macro sql Optimization

Database
Enthusiast

macro sql Optimization

REPLACE MACRO MSTMACRO.MAC_TSF_PRE_PAYMENT_0002

(
Start_Dt VARCHAR(20)
,End_Dt VARCHAR(20)
,Account_Org_Cd VARCHAR(10) DEFAULT '0'
,Org_Cd VARCHAR(10) DEFAULT '0'
,Pre_Fee_Cd VARCHAR(10) DEFAULT '0'
,Scr_Id VARCHAR(30) DEFAULT '0'
,Start_Num VARCHAR(10) DEFAULT '1'
,End_Num VARCHAR(10) DEFAULT '50'
)
AS
(

SELECT ROW_NUMBER() OVER ( ORDER BY A.preAccountDt,A.accountSetl11Dt,A.preSetlType ,A.shipmentNo ASC) T
,preAccountDt
,accountSetl1Dt
,accountSetl11Dt
,accountAdjDt
,shipmentNo
,bagId
,resendFlag
,serverOrgCd
,serverOrgName
,startCity
,startCityName
,ownerOrg
,ownerOrgName
,endOrg
,endOrgName
,endCity
,endCityName
,setlWeight
,recvPostmanName
,sendPostmanName
,flagAutoTrans
,fee
,preSetlType
FROM (SELECT Pre_Account_Dt AS preAccountDt
,Account_Setl1_Dt AS accountSetl1Dt
,Account_Setl11_Dt AS accountSetl11Dt
,Account_Adj_Dt AS accountAdjDt
,Shipment_No AS shipmentNo
,Bag_Id AS bagId
,Resend_Flag AS resendFlag
,Server_Org_Cd AS serverOrgCd
,Server_Org_Name AS serverOrgName
,Start_City AS startCity
,Start_City_Name AS startCityName
,Owner_Org AS ownerOrg
,Owner_Org_Name AS ownerOrgName
,End_Org AS endOrg
,End_Org_Name AS endOrgName
,End_City AS endCity
,End_City_Name AS endCityName
,Setl_Weight AS setlWeight
,Recv_Postman_Name AS recvPostmanName
,Send_Postman_Name AS sendPostmanName
,CASE WHEN Flag_Auto_Trans = -1 THEN ''
WHEN Flag_Auto_Trans = 1 THEN 'y'
WHEN Flag_Auto_Trans = 0 THEN 'n'
END AS flagAutoTrans
,Fee AS fee
,CASE WHEN Pre_Setl_Type = 1 THEN 'f'
WHEN Pre_Setl_Type = 2 THEN 'a'
WHEN Pre_Setl_Type = 3 THEN 's'
WHEN Pre_Setl_Type = 4 THEN 'r'
WHEN Pre_Setl_Type = 5 THEN 'e'
WHEN Pre_Setl_Type = 6 THEN 'ff'
WHEN Pre_Setl_Type = 7 THEN '3'
END AS preSetlType
FROM MSTVIEW.PRE_PAYMENT_DETAIL
WHERE Pre_Account_Dt >= CASE WHEN :Start_Dt = '' OR :Start_Dt IS NULL THEN CURRENT_DATE
ELSE CAST(SUBSTR(:Start_Dt,1,4)||SUBSTR(:Start_Dt,6,2)||SUBSTR(:Start_Dt,9,2) AS DATE FORMAT 'YYYYMMDD')
END
AND Pre_Account_Dt <= CASE WHEN :End_Dt = '' OR :End_Dt IS NULL THEN CURRENT_DATE
ELSE CAST(SUBSTR(:End_Dt,1,4)||SUBSTR(:End_Dt,6,2)||SUBSTR(:End_Dt,9,2) AS DATE FORMAT 'YYYYMMDD')
END
AND Pay_Dep = :Org_Cd
AND Re_Dep = :Account_Org_Cd
AND Pre_Fee_Cd = :Pre_Fee_Cd
AND Scr_Id = :Scr_Id
AND Re_Value = 'Y'
UNION ALL
SELECT Pre_Account_Dt AS preAccountDt
,Account_Setl1_Dt AS accountSetl1Dt
,Account_Setl11_Dt AS accountSetl11Dt
,Account_Adj_Dt AS accountAdjDt
,Shipment_No AS shipmentNo
,Bag_Id AS bagId
,Resend_Flag AS resendFlag
,Server_Org_Cd AS serverOrgCd
,Server_Org_Name AS serverOrgName
,Start_City AS startCity
,Start_City_Name AS startCityName
,Owner_Org AS ownerOrg
,Owner_Org_Name AS ownerOrgName
,End_Org AS endOrg
,End_Org_Name AS endOrgName
,End_City AS endCity
,End_City_Name AS endCityName
,Setl_Weight AS setlWeight
,Recv_Postman_Name AS recvPostmanName
,Send_Postman_Name AS sendPostmanName
,CASE WHEN Flag_Auto_Trans = -1 THEN ''
WHEN Flag_Auto_Trans = 1 THEN 'y'
WHEN Flag_Auto_Trans = 0 THEN 'n'
END AS flagAutoTrans
,Fee AS fee
,CASE WHEN Pre_Setl_Type = 1 THEN 'cur'
WHEN Pre_Setl_Type = 2 THEN '11'
WHEN Pre_Setl_Type = 3 THEN '11_post'
WHEN Pre_Setl_Type = 4 THEN 'manual'
WHEN Pre_Setl_Type = 5 THEN 'up'
WHEN Pre_Setl_Type = 6 THEN 'up11'
WHEN Pre_Setl_Type = 7 THEN 'up111'
END AS preSetlType
FROM MSTVIEW.PRE_PAYMENT_RESETL_DETAIL
WHERE Pre_Account_Dt >= CASE WHEN :Start_Dt = '' OR :Start_Dt IS NULL THEN CURRENT_DATE
ELSE CAST(SUBSTR(:Start_Dt,1,4)||SUBSTR(:Start_Dt,6,2)||SUBSTR(:Start_Dt,9,2) AS DATE FORMAT 'YYYYMMDD')
END
AND Pre_Account_Dt <= CASE WHEN :End_Dt = '' OR :End_Dt IS NULL THEN CURRENT_DATE
ELSE CAST(SUBSTR(:End_Dt,1,4)||SUBSTR(:End_Dt,6,2)||SUBSTR(:End_Dt,9,2) AS DATE FORMAT 'YYYYMMDD')
END
AND Pay_Dep = :Org_Cd
AND Re_Dep = :Account_Org_Cd
AND Pre_Fee_Cd = :Pre_Fee_Cd
AND Scr_Id = :Scr_Id
AND Re_Value = 'Y') A
QUALIFY T BETWEEN CAST(:Start_Num AS INTEGER) AND CAST(:End_Num AS INTEGER)

;

INSERT INTO PWORK.LWL_TEST_MACRO VALUES(:Start_Dt,:End_Dt,:Account_Org_Cd,:Org_Cd,:Pre_Fee_Cd,:Scr_Id,:Start_Num,:End_Num,);
;

);

table:

CREATE MULTISET TABLE PMART_ST.PRE_PAYMENT_DETAIL ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT,
DEFAULT MERGEBLOCKRATIO
(
Pre_Account_Dt DATE FORMAT 'YYYYMMDD' TITLE '预付款发送日期',
Scr_Id VARCHAR(30) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '序列号',
Resend_Flag CHAR(2) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '是否服务部转上级网点',
Server_Org_Cd INTEGER TITLE '服务部编码',
Server_Org_Name VARCHAR(80) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '服务部名称',
Re_Dep INTEGER TITLE '收款部门',
Pay_Dep INTEGER TITLE '付款公司',
Pre_Fee_Cd INTEGER TITLE '预付款费用类型',
Re_Value VARCHAR(10) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '预付款返回值',
Pre_Setl_Type INTEGER TITLE '预付款结算类型',
Shipment_No VARCHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '运单编号',
Bag_Id VARCHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '大包号',
Account_Setl1_Dt DATE FORMAT 'YYYYMMDD' TITLE '第一天结算日期',
Account_Setl11_Dt DATE FORMAT 'YYYYMMDD' TITLE '第十一天结算日期',
Account_Adj_Dt DATE FORMAT 'YYYYMMDD' TITLE '调整日期',
Shipping_Method_Setl1 INTEGER TITLE '第一天运输方式',
Shipping_Method_Setl2 INTEGER TITLE '第十一天运输方式',
Start_City INTEGER TITLE '始发城市',
Start_City_Name VARCHAR(100) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '始发城市名',
Owner_Org INTEGER TITLE '揽件公司',
Owner_Org_Name VARCHAR(100) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '揽件公司名',
End_Org INTEGER TITLE '派送公司',
End_Org_Name VARCHAR(100) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '派送公司名',
End_City INTEGER TITLE '目的城市',
End_City_Name VARCHAR(100) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '目的城市名',
Setl_Weight DECIMAL(8,2) TITLE '重量',
Fee DECIMAL(8,2) TITLE '金额',
Recv_Postman_Name VARCHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '揽件业务员',
Send_Postman_Name VARCHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '派送业务员',
Flag_Auto_Trans SMALLINT TITLE '是否直跑车件',
Shipment_Re_Value CHAR(2) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '运单费用是否发送成功',
Shipment_Re_Dt DATE FORMAT 'YYYYMMDD' TITLE '运单费用发送成功日期')
PRIMARY INDEX ( Shipment_No )
PARTITION BY RANGE_N(CAST((Pre_Account_Dt ) AS DATE FORMAT 'YYYYMMDD') BETWEEN DATE '2011-01-01' AND DATE '2050-12-31' EACH INTERVAL '1' DAY );

CREATE MULTISET TABLE PMART_ST.PRE_PAYMENT_RESETL_DETAIL ,NO FALLBACK ,
NO BEFORE JOURNAL,
NO AFTER JOURNAL,
CHECKSUM = DEFAULT,
DEFAULT MERGEBLOCKRATIO
(
Pre_Account_Dt DATE FORMAT 'YYYYMMDD' TITLE '预付款发送日期',
Scr_Id VARCHAR(30) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '序列号',
Resend_Flag CHAR(2) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '是否服务部转上级网点',
Server_Org_Cd INTEGER TITLE '服务部编码',
Server_Org_Name VARCHAR(80) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '服务部名称',
Re_Dep INTEGER TITLE '收款部门',
Pay_Dep INTEGER TITLE '付款公司',
Pre_Fee_Cd INTEGER TITLE '预付款费用类型',
Re_Value VARCHAR(10) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '预付款返回值',
Pre_Setl_Type INTEGER TITLE '预付款结算类型',
Shipment_No VARCHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '运单编号',
Bag_Id VARCHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '大包号',
Account_Setl1_Dt DATE FORMAT 'YYYYMMDD' TITLE '第一天结算日期',
Account_Setl11_Dt DATE FORMAT 'YYYYMMDD' TITLE '第十一天结算日期',
Account_Adj_Dt DATE FORMAT 'YYYYMMDD' TITLE '调整日期',
Shipping_Method_Setl1 INTEGER TITLE '第一天运输方式',
Shipping_Method_Setl2 INTEGER TITLE '第十一天运输方式',
Start_City INTEGER TITLE '始发城市',
Start_City_Name VARCHAR(100) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '始发城市名',
Owner_Org INTEGER TITLE '揽件公司',
Owner_Org_Name VARCHAR(100) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '揽件公司名',
End_Org INTEGER TITLE '派送公司',
End_Org_Name VARCHAR(100) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '派送公司名',
End_City INTEGER TITLE '目的城市',
End_City_Name VARCHAR(100) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '目的城市名',
Setl_Weight DECIMAL(8,2) TITLE '重量',
Fee DECIMAL(8,2) TITLE '金额',
Recv_Postman_Name VARCHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '揽件业务员',
Send_Postman_Name VARCHAR(20) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '派送业务员',
Flag_Auto_Trans SMALLINT TITLE '是否直跑车件',
Shipment_Re_Value CHAR(2) CHARACTER SET LATIN NOT CASESPECIFIC TITLE '运单费用是否发送成功',
Shipment_Re_Dt DATE FORMAT 'YYYYMMDD' TITLE '运单费用发送成功日期')
PRIMARY INDEX ( Shipment_No )
PARTITION BY RANGE_N(CAST((Pre_Account_Dt ) AS DATE FORMAT 'YYYYMMDD') BETWEEN DATE '2011-01-01' AND DATE '2050-12-31' EACH INTERVAL '1' DAY );

excution plan

 1) First, we lock PMART_ST.PRE_PAYMENT_DETAIL for access, and we lock
PMART_ST.PRE_PAYMENT_RESETL_DETAIL for access.
2) Next, we do an all-AMPs RETRIEVE step from
PMART_ST.PRE_PAYMENT_DETAIL by way of an all-rows scan with a
condition of ("(PMART_ST.PRE_PAYMENT_DETAIL.Re_Value = 'Y') AND
((PMART_ST.PRE_PAYMENT_DETAIL.Scr_Id = (:? (VARCHAR(30), CHARACTER
SET LATIN, NOT CASESPECIFIC, NAMED Scr_Id, FORMAT 'X(30)', DEFAULT
'0'))) AND (((PMART_ST.PRE_PAYMENT_DETAIL.Pay_Dep )= (:?
(VARCHAR(10), CHARACTER SET LATIN, NOT CASESPECIFIC, NAMED Org_Cd,
FORMAT 'X(10)', DEFAULT '0')(FLOAT, FORMAT
'1600000000000000020020000000150100FF00000000'XB))) AND
(((PMART_ST.PRE_PAYMENT_DETAIL.Re_Dep )= (:? (VARCHAR(10),
CHARACTER SET LATIN, NOT CASESPECIFIC, NAMED Account_Org_Cd,
FORMAT 'X(10)', DEFAULT '0')(FLOAT, FORMAT
'1600000000000000020020000000150100FF00000000'XB))) AND
(((PMART_ST.PRE_PAYMENT_DETAIL.Pre_Fee_Cd )= (:? (VARCHAR(10),
CHARACTER SET LATIN, NOT CASESPECIFIC, NAMED Pre_Fee_Cd, FORMAT
'X(10)', DEFAULT '0')(FLOAT, FORMAT
'1600000000000000020020000000150100FF00000000'XB))) AND
((PMART_ST.PRE_PAYMENT_DETAIL.Pre_Account_Dt >= (( CASE WHEN (((:?
(VARCHAR(20), CHARACTER SET LATIN, NOT CASESPECIFIC, NAMED
Start_Dt, FORMAT 'X(20)'))= '') OR (:? (VARCHAR(20), CHARACTER SET
LATIN, NOT CASESPECIFIC, NAMED Start_Dt, FORMAT 'X(20)')IS NULL ))
THEN (DATE '2013-11-13') ELSE (((SUBSTR(:? (VARCHAR(20), CHARACTER
SET LATIN, NOT CASESPECIFIC, NAMED Start_Dt, FORMAT 'X(20)'),1 ,4
))||(SUBSTR(:? (VARCHAR(20), CHARACTER SET LATIN, NOT
CASESPECIFIC, NAMED Start_Dt, FORMAT 'X(20)'),6 ,2 )))||(SUBSTR(:?
(VARCHAR(20), CHARACTER SET LATIN, NOT CASESPECIFIC, NAMED
Start_Dt, FORMAT 'X(20)'),9 ,2 ))(DATE, FORMAT
'1800010000000000FF06FF0400FFFF000004000200020008'XB)) END ))) AND
(PMART_ST.PRE_PAYMENT_DETAIL.Pre_Account_Dt <= (( CASE WHEN (((:?
(VARCHAR(20), CHARACTER SET LATIN, NOT CASESPECIFIC, NAMED End_Dt,
FORMAT 'X(20)'))= '') OR (:? (VARCHAR(20), CHARACTER SET LATIN,
NOT CASESPECIFIC, NAMED End_Dt, FORMAT 'X(20)')IS NULL )) THEN
(DATE '2013-11-13') ELSE (((SUBSTR(:? (VARCHAR(20), CHARACTER SET
LATIN, NOT CASESPECIFIC, NAMED End_Dt, FORMAT 'X(20)'),1 ,4
))||(SUBSTR(:? (VARCHAR(20), CHARACTER SET LATIN, NOT
CASESPECIFIC, NAMED End_Dt, FORMAT 'X(20)'),6 ,2 )))||(SUBSTR(:?
(VARCHAR(20), CHARACTER SET LATIN, NOT CASESPECIFIC, NAMED End_Dt,
FORMAT 'X(20)'),9 ,2 ))(DATE, FORMAT
'1800010000000000FF06FF0400FFFF000004000200020008'XB)) END
))))))))") into Spool 1 (all_amps), which is built locally on the
AMPs. The input table will not be cached in memory, but it is
eligible for synchronized scanning. The size of Spool 1 is
estimated with no confidence to be 52,861,128 rows (
14,801,115,840 bytes). The estimated time for this step is 9
minutes and 56 seconds.
3) We do an all-AMPs RETRIEVE step from
PMART_ST.PRE_PAYMENT_RESETL_DETAIL by way of an all-rows scan with
a condition of ("(PMART_ST.PRE_PAYMENT_RESETL_DETAIL.Re_Value =
'Y') AND ((PMART_ST.PRE_PAYMENT_RESETL_DETAIL.Scr_Id = (:?
(VARCHAR(30), CHARACTER SET LATIN, NOT CASESPECIFIC, NAMED Scr_Id,
FORMAT 'X(30)', DEFAULT '0'))) AND
(((PMART_ST.PRE_PAYMENT_RESETL_DETAIL.Pay_Dep )= (:? (VARCHAR(10),
CHARACTER SET LATIN, NOT CASESPECIFIC, NAMED Org_Cd, FORMAT
'X(10)', DEFAULT '0')(FLOAT, FORMAT
'1600000000000000020020000000150100FF00000000'XB))) AND
(((PMART_ST.PRE_PAYMENT_RESETL_DETAIL.Re_Dep )= (:? (VARCHAR(10),
CHARACTER SET LATIN, NOT CASESPECIFIC, NAMED Account_Org_Cd,
FORMAT 'X(10)', DEFAULT '0')(FLOAT, FORMAT
'1600000000000000020020000000150100FF00000000'XB))) AND
(((PMART_ST.PRE_PAYMENT_RESETL_DETAIL.Pre_Fee_Cd )= (:?
(VARCHAR(10), CHARACTER SET LATIN, NOT CASESPECIFIC, NAMED
Pre_Fee_Cd, FORMAT 'X(10)', DEFAULT '0')(FLOAT, FORMAT
'1600000000000000020020000000150100FF00000000'XB))) AND
((PMART_ST.PRE_PAYMENT_RESETL_DETAIL.Pre_Account_Dt >= (( CASE
WHEN (((:? (VARCHAR(20), CHARACTER SET LATIN, NOT CASESPECIFIC,
NAMED Start_Dt, FORMAT 'X(20)'))= '') OR (:? (VARCHAR(20),
CHARACTER SET LATIN, NOT CASESPECIFIC, NAMED Start_Dt,
FORMAT'X(20)')IS NULL )) THEN (DATE '2013-11-13') ELSE
(((SUBSTR(:? (VARCHAR(20), CHARACTER SET LATIN, NOT CASESPECIFIC,
NAMED Start_Dt, FORMAT 'X(20)'),1 ,4 ))||(SUBSTR(:? (VARCHAR(20),
CHARACTER SET LATIN, NOT CASESPECIFIC, NAMED Start_Dt, FORMAT
'X(20)'),6 ,2 )))||(SUBSTR(:? (VARCHAR(20), CHARACTER SET LATIN,
NOT CASESPECIFIC, NAMED Start_Dt, FORMAT 'X(20)'),9 ,2 ))(DATE,
FORMAT '1800010000000000FF06FF0400FFFF000004000200020008'XB)) END
))) AND (PMART_ST.PRE_PAYMENT_RESETL_DETAIL.Pre_Account_Dt <= ((
CASE WHEN (((:? (VARCHAR(20), CHARACTER SET LATIN, NOT
CASESPECIFIC, NAMED End_Dt, FORMAT 'X(20)'))= '') OR (:?
(VARCHAR(20), CHARACTER SET LATIN, NOT CASESPECIFIC, NAMED End_Dt,
FORMAT 'X(20)')IS NULL )) THEN (DATE '2013-11-13') ELSE
(((SUBSTR(:? (VARCHAR(20), CHARACTER SET LATIN, NOT CASESPECIFIC,
NAMED End_Dt, FORMAT 'X(20)'),1 ,4 ))||(SUBSTR(:? (VARCHAR(20),
CHARACTER SET LATIN, NOT CASESPECIFIC, NAMED End_Dt, FORMAT
'X(20)'),6 ,2 )))||(SUBSTR(:? (VARCHAR(20), CHARACTER SET LATIN,
NOT CASESPECIFIC, NAMED End_Dt, FORMAT 'X(20)'),9 ,2 ))(DATE,
FORMAT '1800010000000000FF06FF0400FFFF000004000200020008'XB)) END
))))))))") into Spool 1 (all_amps), which is built locally on the
AMPs. The size of Spool 1 is estimated with no confidence to be
53,095,544 rows (14,866,752,320 bytes). The estimated time for
this step is 2.66 seconds.
4) We do an all-AMPs STAT FUNCTION step from Spool 1 (Last Use) by
way of an all-rows scan into Spool 6 (Last Use), which is assumed
to be redistributed by value to all AMPs. The result rows are put
into Spool 2 (group_amps), which is built locally on the AMPs.
The size is estimated with no confidence to be 53,095,544 rows (
19,273,682,472 bytes).
5) We do an INSERT into PWORK.LWL_TEST_MACRO. The estimated time for
this step is 0.14 seconds.
6) Finally, we send out an END TRANSACTION step to all AMPs involved
in processing the request.
-> The contents of Spool 2 are sent back 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.

以下是正常的执行计划,取自第24行对应计划:
1) First, we lock PMART_ST.PRE_PAYMENT_DETAIL for access, and we lock
PMART_ST.PRE_PAYMENT_RESETL_DETAIL for access.
2) Next, we do an all-AMPs RETRIEVE step from a single partition of
PMART_ST.PRE_PAYMENT_DETAIL with a condition of (
"PMART_ST.PRE_PAYMENT_DETAIL.Pre_Account_Dt = DATE '2013-11-12'")
with a residual condition of (
"(PMART_ST.PRE_PAYMENT_DETAIL.Pay_Dep = 300182) AND
((PMART_ST.PRE_PAYMENT_DETAIL.Re_Dep = 300008) AND
((PMART_ST.PRE_PAYMENT_DETAIL.Pre_Fee_Cd = 111) AND
((PMART_ST.PRE_PAYMENT_DETAIL.Re_Value = 'Y') AND
((PMART_ST.PRE_PAYMENT_DETAIL.Scr_Id = 'TDZZF131112104349') AND
(PMART_ST.PRE_PAYMENT_DETAIL.Pre_Account_Dt = DATE
'2013-11-12')))))") into Spool 1 (all_amps), which is built
locally on the AMPs. The size of Spool 1 is estimated with no
confidence to be 1,409,631 rows (394,696,680 bytes). The
estimated time for this step is 2.01 seconds.
3) We do an all-AMPs RETRIEVE step from a single partition of
PMART_ST.PRE_PAYMENT_RESETL_DETAIL with a condition of (
"PMART_ST.PRE_PAYMENT_RESETL_DETAIL.Pre_Account_Dt = DATE
'2013-11-12'") with a residual condition of (
"(PMART_ST.PRE_PAYMENT_RESETL_DETAIL.Pay_Dep = 300182) AND
((PMART_ST.PRE_PAYMENT_RESETL_DETAIL.Re_Dep = 300008) AND
((PMART_ST.PRE_PAYMENT_RESETL_DETAIL.Pre_Fee_Cd = 111) AND
((PMART_ST.PRE_PAYMENT_RESETL_DETAIL.Re_Value = 'Y') AND
((PMART_ST.PRE_PAYMENT_RESETL_DETAIL.Scr_Id = 'TDZZF131112104349')
AND (PMART_ST.PRE_PAYMENT_RESETL_DETAIL.Pre_Account_Dt = DATE
'2013-11-12')))))") into Spool 1 (all_amps), which is built
locally on the AMPs. The size of Spool 1 is estimated with no
confidence to be 1,589,951 rows (445,186,280 bytes). The
estimated time for this step is 0.27 seconds.
4) We do an all-AMPs STAT FUNCTION step from Spool 1 (Last Use) by
way of an all-rows scan into Spool 6 (Last Use), which is assumed
to be redistributed by value to all AMPs. The result rows are put
into Spool 2 (group_amps), which is built locally on the AMPs.
The size is estimated with no confidence to be 50 rows (18,150
bytes).
5) We do an INSERT into PWORK.LWL_TEST_MACRO. The estimated time for
this step is 0.14 seconds.
6) Finally, we send out an END TRANSACTION step to all AMPs involved
in processing the request.
-> The contents of Spool 2 are sent back 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.

it seems the macro doesn’t  evoke partition elimination because of input parameters . The wired thing is the macro not always perform FTS , sometimes it works properly.  Anyone can help?   

Thanks

QI

Tags (1)
3 REPLIES
Teradata Employee

Re: macro sql Optimization

Hello,

 

your Explain shows that partition elimination does happen, both for PMART_ST.PRE_PAYMENT_DETAIL and PMART_ST.PRE_PAYMENT_RESETL_DETAIL tables (the phrase "single partition"):

 

 

we do an all-AMPs RETRIEVE step from a single partition of

     PMART_ST.PRE_PAYMENT_DETAIL with a condition of (

     "PMART_ST.PRE_PAYMENT_DETAIL.Pre_Account_Dt = DATE '2013-11-12'")

 

 

We do an all-AMPs RETRIEVE step from a single partition of

     PMART_ST.PRE_PAYMENT_RESETL_DETAIL with a condition of (

     "PMART_ST.PRE_PAYMENT_RESETL_DETAIL.Pre_Account_Dt = DATE

     '2013-11-12'")

 

 

Please provide the Explain where the partition elimination does not happen.

 

Regards,

Vlad.

Senior Apprentice

Re: macro sql Optimization

There's no partition elimination in the 2nd explain because this has been submitted using Prepared SQL (':?') while the 1st explain was done with hard-coded literals.

There should be a simple solution to that problem, simply change the datatype of Start_dt and End_dt to a DATE add a default:

Start_date DATE DEFAULT CURRENT_DATE

Teradata Employee

Re: macro sql Optimization

sorry for my previous post, I've not seen the 2nd explain.