Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Wed, 24 Sep 2003 @ 12:34:26 GMT


     
  <Prev Next>   <<First <Prev Next> Last>>  


Subj:   Re: Multi-Statement Requests
 
From:   Narayan Murthy K S

I think it is an optimization done w.r.t the INSERT/SELECT statement. If the target table in the MSR involving the INSERT/SELECT is the same table - then there is an optimization done in bringing the data generated by the different INSERT/SELECTS into a single spool and then doing an ALL-AMP merge from that single spool into the target table. But if the target tables in the MSR's were to be different then I guess this optimization will not be seen. This is what accounts for the result shown at the end of the MSR.

Here is an example which shows this optimization. An explain of the MSR also follows, which talks about the single spool that I have mentioned.

ins t2 sel a from t1 where a=1
;ins t2 sel a from t1 where a=2
;ins t2 sel a from t1 where a=3;

ins t2 sel a from t1 where a=1
;ins t2 sel a from t1 where a=2
;ins t2 sel a from t1 where a=3;

 *** Insert completed. No rows added.
 *** Total elapsed time was 1 second.

 *** Insert completed. No rows added.

 *** Insert completed. 3 rows added. <-finally affected rows

explain
ins t2 sel a from t1 where a=1
;ins t2 sel a from t1 where a=2
;ins t2 sel a from t1 where a=3;

 *** Help information returned. 25 rows.
 *** Total elapsed time was 1 second.
Explanation
--------------------------------------------------
 
  1)First, we lock a distinct CHK."pseudo table" for write on a RowHash to prevent global deadlock for CHK.t2.  
  2)Next, we lock CHK.t2 for write.  
  3)We do a single-AMP RETRIEVE step from CHK.t1 by way of the primary index "CHK.t1.a = 1" with no residual conditions into Spool 1 (one-amp), which is built locally on that AMP. The size of Spool 1 is estimated with low confidence to be 40 rows. The estimated time for this step is 0.03 seconds.  
  4)We do a single-AMP RETRIEVE step from CHK.t1 by way of the primary index "CHK.t1.a = 2" with no residual conditions into Spool 1 (one-amp), which is built locally on that AMP. The size of Spool 1 is estimated with low confidence to be 40 rows. The estimated time for this step is 0.03 seconds.  
  5)We do a single-AMP RETRIEVE step from CHK.t1 by way of the primary index "CHK.t1.a = 3" with no residual conditions into Spool 1 (one-amp), which is built locally on that AMP. The size of Spool 1 is estimated with low confidence to be 40 rows. The estimated time for this step is 0.03 seconds.  
  6)We do a SORT to order Spool 1 by row hash.  
  7)We do an all-AMPs MERGE into CHK.t2 from Spool 1 (Last Use).  
  8)Finally, we send out an END TRANSACTION step to all AMPs involved in processing the request.  
  ->No rows are returned to the user as the result of statement 1. No rows are returned to the user as the result of statement 2. No rows are returned to the user as the result of statement 3.  


Hope this helps.

Narayan



     
  <Prev Next>   <<First <Prev Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023