Skip to Content
3
Oct 30, 2013 at 06:00 PM

Join optimization

1022 Views

This is a new thread opened for a continuing discussion

currently join is needed between two huge fact tables . If the join is performed on the fly on HANA , the performance is degraded and HANA sometimes crashes .

Thus a stored procedure chunks the data and then performs the join on the smaller chunk and then dumps the results in a physical table . The chunking is inefficient and but the data inserts is even more . The majority of time is taken in the delta merges ( data inserts) .

Here is the code

essentially , there are two tables Table_A , and Table_B and an analytical view is created from them .

we pick data between 2 timestamps from analytical view made from Table_A

and within a loop we join data from Table_A and Table_B

and dump the results to a physical table .

What can be done to optimize .

unfortunately I cant seem to hold in Memory the results of the while loop like

A= A union ( results of while loop)

CREATE PROCEDURE CPM_SAP.SP_ZZFSL_CE11_REV_JOIN_V4 
(IN MIN_TIMESTAMP NVARCHAR(14), IN MAX_TIMESTAMP NVARCHAR(14),IN MIN_PERIOD NVARCHAR(6), IN MAX_PERIOD NVARCHAR(6))
LANGUAGE SQLSCRIPT ASXPERIOD INT := :MIN_PERIOD;
XYEAR INT := 0;
XMONTH INT := 0;BEGINVAR_Z_NAME_OBSCURED = SELECT "RYEAR", "RTCUR", "RUNIT", "POPER", "RBUKRS", "RACCT", "RCNTR", "RPRCTR", "RZZSITE",
"RZZPOSID", "RZZFKBER", "DOCTY", "REFDOCNR", "AUFNR", "ZZLDGRP", "VBUND", "ZZBUZEI", "AWORG", "CPUDT", "CPUTM",
"ZZBUZEI_RPOSN", "PERIOD_ID", "TIMESTAMP",
"TSL" AS "TSL", "HSL" AS "HSL", "KSL" AS "KSL", "MSL" AS "MSL"
FROM "_SYS_BIC"."wlclose/AN_Z_NAME_OBSCURED_REV_KSLNN"
where "TIMESTAMP" > :MIN_TIMESTAMP AND "TIMESTAMP" <= :MAX_TIMESTAMP ;WHILE :XPERIOD <= :MAX_PERIOD DO VAR1_Z_NAME_OBSCURED = SELECT "RYEAR", "RTCUR", "RUNIT", "POPER", "RBUKRS", "RACCT", "RCNTR", "RPRCTR", "RZZSITE",
"RZZPOSID", "RZZFKBER", "DOCTY", "REFDOCNR", "AUFNR", "ZZLDGRP", "VBUND", "ZZBUZEI", "AWORG", "CPUDT", "CPUTM",
"ZZBUZEI_RPOSN", "PERIOD_ID", "TIMESTAMP",
"TSL" AS "TSL", "HSL" AS "HSL", "KSL" AS "KSL", "MSL" AS "MSL"
FROM :VAR_Z_NAME_OBSCURED
where "PERIOD_ID" = CAST(:XPERIOD AS VARCHAR(6)); VAR_CE11000 = SELECT "PALEDGER","KSTAR", "PERIOD_ID","BUKRS", "COPA_AWORG", "ZZBUZEI_RPOSN", "RBELN", "PERIO",
"GJAHR", "PERDE", "RPOSN", "PRCTR", "PPRCTR", "SKOST", "RKAUFNR", "KURSF", "VV005_ME", "VV006_ME", "WW004","WW011" , "WW012", "WW013",
"WW008", "WW023", "WW010", "WW020", "WW015", "WW006", "WW024", "WW026",
"VV005" AS "VV005", "VV006" AS "VV006" FROM "_SYS_BIC"."wlclose/AN_CE11000_REV_LDG01"
where "PERIOD_ID" = CAST(:XPERIOD AS VARCHAR(6));VAR_JOIN = SELECT Z.RACCT AS RACCT, Z.RBUKRS AS RBUKRS, Z."PERIOD_ID" AS ZPERIOD, Z."AWORG" AS AWORG, Z."ZZBUZEI",
Z."REFDOCNR" as REFDOCNR, Z."RCNTR" as RCNTR, Z."RPRCTR" as RPRCTR, Z."RZZSITE" AS RZZSITE, Z."RZZPOSID" AS RZZPOSID,
Z."RZZFKBER" AS RZZFKBER, Z."DOCTY" AS DOCTY, Z."AUFNR" AS AUFNR, Z."ZZLDGRP" AS ZZLDGRP, Z."VBUND"AS VBUND,
Z."TIMESTAMP" AS TIMESTAMP,Z."RYEAR" AS RYEAR, Z."POPER" AS POPER ,Z."TSL" AS TSL, Z."HSL" AS HSL, Z."RTCUR" AS RTCUR,
Z."KSL" AS KSL, Z."MSL" AS MSL, Z."RUNIT" AS RUNIT, C."PALEDGER" AS PALEDGER ,C."KSTAR" AS KSTAR, C."BUKRS" AS BUKRS,
C."PERIOD_ID" AS CPERIOD,C."COPA_AWORG" AS COPA_AWORG,C."RBELN" AS RBELN,C."ZZBUZEI_RPOSN" AS RPOSN,
C."WW004" AS WW004, C."WW011" as WW011, C."WW012" AS WW012 , "WW013" AS WW013 , C."WW008" AS WW008, C."WW023" AS WW023, C."WW010" AS WW010,
C."WW020" AS WW020, C."WW015" AS WW015, C."WW006" AS WW006, C."VV005" AS VV005,C."VV005_ME" AS VV005_ME,
C."VV006" AS VV006, C."VV006_ME" AS VV006_ME
FROM :VAR1_Z_NAME_OBSCURED Z
LEFT OUTER JOIN :VAR_CE11000 C ON
Z."ZZBUZEI_RPOSN"=C."ZZBUZEI_RPOSN" AND
Z."REFDOCNR"=C."RBELN" AND
Z."AWORG"=C."COPA_AWORG" AND
Z."RBUKRS"=C."BUKRS" AND
Z."PERIOD_ID"=C."PERIOD_ID" AND
Z.RACCT = C.KSTAR;
INSERT INTO CPM_SAP.ZZFSL_CE11_REV_JOIN (SELECT * FROM :VAR_JOIN );XYEAR := (:XPERIOD/100);
XMONTH := :XPERIOD - (:XYEAR*100) ;IF :XMONTH =12
THEN
XPERIOD := ((:XYEAR+ 1) * 100) +1;
ELSE
XPERIOD := :XPERIOD +1;
END IF;END WHILE;
END;