If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > TEMP Tables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-20-04, 15:03
ansonee ansonee is offline
Registered User
 
Join Date: Feb 2002
Location: Minneapolis, MN
Posts: 253
TEMP Tables

I'm just actually soliciting general comments.

I need to use a temp table in a stored proc in orser to do some manipulation of data (sorting, updating, etc.) The database guys here (who are 99% mainframe) are having a fit because "no application here has EVER used a temp table" blah blah blah....

Please comment on any problems - small or large - you may have encountered. What are the risks/rewards. Are they just overreacting?

We're on AIX DB2 v8 FixPak 4a.

Thanks in advance...
__________________
Anthony Robinson

"If I'm curt with you, it's because time is a factor here. I think fast, I talk fast, and I need you guys to act fast if you want to get out of this. So, pretty please - with sugar on top..."
Reply With Quote
  #2 (permalink)  
Old 04-20-04, 16:22
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
There are three types of temp tables.
1) "permanent" temp tables. These are basically real tables that are used for temporary storage. They can be used to pass data between applications, etc.
2) declared temporary tables (DECLARE GLOBAL TEMPORARY TABLE ...) . These hang around only as long as the session is active (hence the special schema od SESSION.<table>).
3) implicit temporary tables (WITH TEMP1 AS (Select * from department) ...)

All three have their advantages. We are using all three in our SPs. We use (1) for passing large amounts of data to the SP. We us (2) for storing a smaller subset of data than the base tables and then perform operations on the temp table. Very handy. We use (3) whenever this type of query is needed and (2) is overkill for the operation.

An example for (1) is they want to get data for an unspecified number of employees that is picked by an external (to the SP) process. The temp table holds the list of employees where the SP can use an IN predicate.

An example of (2) would be gathering some data and doing some data transposing on a subset of it. I just did this one about a hour ago. It worked fast and great.

We have not had any problems with temp tables. We like them. The only risk I can see is that all the 3 types are written to disk (however short the life of the temp table).

I believe they are overreacting. The main reason is that with a temp table you can work on smaller subsets of data writing the SQL to utilize indexes etc to perform faster. Writing it without temp tables could result in a table scan. I have seen performance improvements changing some queries to use temp tables.

HTH

Andy
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On