insert into Supermag.TTArticleData (SpecItem,AvlQuantity,ItemPrice,DocType,CreatedAt,OpCode,LocFrom,LocTo,ClientIndex, NCauseDoc,CauseSpecItem,TotalSum,TotalSumNoVAT,DocID,UserOp,PayCash,GoodsOwner,TotalSumNoTax,CurrencyType,VATRate,TotalSumCur,CauseType,CauseID,Location,NativeDocType) select S.SpecItem,S.AvailQuantity*1000,nvl(S.ItemPrice,0),S.DocType,S.CreatedAt,S.OpCode,nvl(S.LocationFrom,-1),nvl(S.LocationTo,-1),nvl(S.ClientIndex,-1),-1 NCauseDoc, nvl(S.CauseSpecItem,-1),S.TotalPrice TotalSum,S.TotalPrice-nvl(ST.TaxSum,0) TotalSumNoVAT,S.ID DocID,nvl(S.UserOp,-1),nvl(nvl(XIn.PayCash,XOut.PayCash), decode(S.DocType,'CS','1','CR','1','0')) PayCash,nvl(XIn.GoodsOwner,0) GoodsOwner,nvl(S.TotalPriceNoTax,nvl(S.ItemPriceNoTax,0)*S.Quantity) TotalSumNoTax,S.CurrencyType, nvl(ST.TaxRate,0) VATRate,TotalPriceCur TotalSumCur,S.CauseType,S.CauseID,-1,1 from (select nvl(T.Quantity,nvl(FS.AvailQuantity,S.Quantity)) AvailQuantity, D.DocType,D.ID,D.CreatedAt,D.OpCode,D.UserOp,D.LocationFrom,D.LocationTo,D.Location,D.ClientIndex,D.CurrencyType,S.CauseSpecItem,S.CauseType, S.CauseID,S.SpecItem,S.Quantity,S.ItemPrice,S.TotalPrice,S.ItemPriceNoTax,S.TotalPriceNoTax,S.TotalPriceCur from Supermag.SMSpec S,Supermag.SMDocuments D,Supermag.TTFIFOAltSpec T,Supermag.FFSpec_ FS where S.DocType=D.DocType and S.DocID=D.ID and T.DocID(+)=S.DocID and T.DocType(+)=S.DocType and T.SpecItem(+)=S.SpecItem and FS.EndDate(+)=to_date('01.01.2013','DD.MM.YYYY') and FS.DocType(+)=S.DocType and FS.DocID(+)=S.DocID and FS.SpecItem(+)=S.SpecItem and S.Article=:Article and S.DocType in ('CS','CR','IW','WI','WO','PE','PO','PN') and ( (D.DocState=3 and (D.Createdat>=to_date('01.01.2013','DD.MM.YYYY') or FS.DocType is not null)) or exists (select * from Supermag.TTDocList T where T.DocType=D.DocType and T.ID=D.ID)) ) S,Supermag.SMWayBillsIn XIn,Supermag.SMWayBillsOut XOut,Supermag.SMSpecTax ST WHERE S.DocType=XIn.DocType(+) and S.ID=XIn.ID(+) and S.DocType=XOut.DocType(+) and S.ID=XOut.ID(+) and S.DocType=ST.DocType(+) and S.ID=ST.DocID(+) and S.SpecItem=ST.SpecItem(+) and ST.TaxID(+)=1 union all select S.SpecItem,S.AvailQuantity*1000,nvl(S.ItemPrice,0),S.DocType,S.CreatedAt,S.OpCode,nvl(S.LocationFrom,-1),nvl(S.LocationTo,-1),nvl(S.ClientIndex,-1), -1 NCauseDoc,nvl(S.CauseSpecItem,-1),S.TotalPrice TotalSum,S.TotalPrice-nvl(ST.TaxSum,0) TotalSumNoVAT,S.ID DocID, nvl(S.UserOp,-1),nvl(nvl(XIn.PayCash,XOut.PayCash),decode(S.DocType,'CS','1','CR','1','0')) PayCash,nvl(XIn.GoodsOwner,0) GoodsOwner, nvl(S.TotalPriceNoTax,nvl(S.ItemPriceNoTax,0)*S.Quantity) TotalSumNoTax,S.CurrencyType,nvl(ST.TaxRate,0) VATRate,TotalPriceCur TotalSumCur,null,null,nvl(S.Location,-1),0 from (select nvl(T.Quantity,S.Quantity) AvailQuantity,D.DocType,D.ID,D.CreatedAt,D.OpCode,D.UserOp,D.LocationFrom,D.LocationTo,D.Location, D.ClientIndex,D.CurrencyType,S.CauseSpecItem,S.CauseType,S.CauseID,S.SpecItem,S.Quantity,S.ItemPrice,S.TotalPrice,S.ItemPriceNoTax,S.TotalPriceNoTax,S.TotalPriceCur from Supermag.SMSpec S,Supermag.SMDocuments D,Supermag.TTFIFOAltSpec T where S.DocType=D.DocType and S.DocID=D.ID and T.DocID(+)=S.DocID and T.DocType(+)=S.DocType and T.SpecItem(+)=S.SpecItem and S.Article=:Article1 and S.DocType in ('RL') and exists (select * from Supermag.TTDocList T where T.DocType=D.DocType and T.ID=D.ID) ) S,Supermag.SMWayBillsIn XIn, Supermag.SMWayBillsOut XOut,Supermag.SMSpecTax ST WHERE S.DocType=XIn.DocType(+) and S.ID=XIn.ID(+) and S.DocType=XOut.DocType(+) and S.ID=XOut.ID(+) and S.DocType=ST.DocType(+) and S.ID=ST.DocID(+) and S.SpecItem=ST.SpecItem(+) and ST.TaxID(+)=1
Execution Plan ---------------------------------------------------------- Plan hash value: 4140408912 ------------------------------------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | 2 | 604 | 3973 (2)| 00:00:03 | | 1 | UNION-ALL | | | | | | | 2 | NESTED LOOPS OUTER | | 1 | 311 | 3957 (1)| 00:00:03 | | 3 | NESTED LOOPS OUTER | | 1 | 290 | 3955 (1)| 00:00:03 | | 4 | NESTED LOOPS OUTER | | 1 | 271 | 3954 (1)| 00:00:03 | | 5 | VIEW | | 1 | 242 | 3952 (1)| 00:00:03 | |* 6 | FILTER | | | | | | | 7 | NESTED LOOPS OUTER | | 886 | 165K| 3507 (1)| 00:00:03 | |* 8 | HASH JOIN RIGHT OUTER | | 886 | 136K| 1711 (1)| 00:00:02 | | 9 | INLIST ITERATOR | | | | | | | 10 | TABLE ACCESS BY INDEX ROWID | TTFIFOALTSPEC | 1 | 57 | 1 (0)| 00:00:01 | |* 11 | INDEX RANGE SCAN | TTCFIFOALTSPEC_PK | 1 | | 6 (0)| 00:00:01 | | 12 | NESTED LOOPS | | | | | | | 13 | NESTED LOOPS | | 886 | 89486 | 1710 (1)| 00:00:02 | | 14 | INLIST ITERATOR | | | | | | | 15 | TABLE ACCESS BY INDEX ROWID| SMSPEC | 842 | 47152 | 858 (1)| 00:00:01 | |* 16 | INDEX RANGE SCAN | SMSPEC_ART | 842 | | 11 (0)| 00:00:01 | |* 17 | INDEX RANGE SCAN | SMCDOCUMENTS_PK | 1 | | 1 (0)| 00:00:01 | | 18 | TABLE ACCESS BY INDEX ROWID | SMDOCUMENTS | 1 | 45 | 2 (0)| 00:00:01 | | 19 | TABLE ACCESS BY INDEX ROWID | FFSPEC_ | 1 | 33 | 3 (0)| 00:00:01 | |* 20 | INDEX UNIQUE SCAN | FFCSPEC_PK_ | 1 | | 2 (0)| 00:00:01 | |* 21 | INDEX UNIQUE SCAN | TTCDOCLIST_PK | 1 | 31 | 1 (0)| 00:00:01 | | 22 | TABLE ACCESS BY INDEX ROWID | SMSPECTAX | 1 | 29 | 3 (0)| 00:00:01 | |* 23 | INDEX UNIQUE SCAN | SMCSPECTAX_PK | 1 | | 2 (0)| 00:00:01 | | 24 | TABLE ACCESS BY INDEX ROWID | SMWAYBILLSOUT | 1 | 19 | 1 (0)| 00:00:01 | |* 25 | INDEX UNIQUE SCAN | SMCWAYBILLSOUT_PK | 1 | | 0 (0)| 00:00:01 | | 26 | TABLE ACCESS BY INDEX ROWID | SMWAYBILLSIN | 1 | 21 | 2 (0)| 00:00:01 | |* 27 | INDEX UNIQUE SCAN | SMCWAYBILLSIN_PK | 1 | | 1 (0)| 00:00:01 | | 28 | NESTED LOOPS OUTER | | 1 | 293 | 16 (7)| 00:00:01 | | 29 | NESTED LOOPS OUTER | | 1 | 264 | 13 (8)| 00:00:01 | | 30 | NESTED LOOPS OUTER | | 1 | 243 | 11 (10)| 00:00:01 | | 31 | VIEW | | 1 | 224 | 10 (10)| 00:00:01 | | 32 | NESTED LOOPS OUTER | | 1 | 185 | 10 (10)| 00:00:01 | | 33 | NESTED LOOPS | | 1 | 128 | 9 (12)| 00:00:01 | | 34 | NESTED LOOPS | | 1 | 76 | 5 (20)| 00:00:01 | | 35 | SORT UNIQUE | | 1 | 31 | 2 (0)| 00:00:01 | |* 36 | TABLE ACCESS FULL | TTDOCLIST | 1 | 31 | 2 (0)| 00:00:01 | | 37 | TABLE ACCESS BY INDEX ROWID | SMDOCUMENTS | 1 | 45 | 2 (0)| 00:00:01 | |* 38 | INDEX UNIQUE SCAN | SMCDOCUMENTS_PK | 1 | | 1 (0)| 00:00:01 | | 39 | TABLE ACCESS BY INDEX ROWID | SMSPEC | 1 | 52 | 4 (0)| 00:00:01 | |* 40 | INDEX RANGE SCAN | SMSPEC_ART | 1 | | 3 (0)| 00:00:01 | | 41 | TABLE ACCESS BY INDEX ROWID | TTFIFOALTSPEC | 1 | 57 | 1 (0)| 00:00:01 | |* 42 | INDEX UNIQUE SCAN | TTCFIFOALTSPEC_PK | 1 | | 0 (0)| 00:00:01 | | 43 | TABLE ACCESS BY INDEX ROWID | SMWAYBILLSOUT | 1 | 19 | 1 (0)| 00:00:01 | |* 44 | INDEX UNIQUE SCAN | SMCWAYBILLSOUT_PK | 1 | | 0 (0)| 00:00:01 | | 45 | TABLE ACCESS BY INDEX ROWID | SMWAYBILLSIN | 1 | 21 | 2 (0)| 00:00:01 | |* 46 | INDEX UNIQUE SCAN | SMCWAYBILLSIN_PK | 1 | | 1 (0)| 00:00:01 | | 47 | TABLE ACCESS BY INDEX ROWID | SMSPECTAX | 1 | 29 | 3 (0)| 00:00:01 | |* 48 | INDEX UNIQUE SCAN | SMCSPECTAX_PK | 1 | | 2 (0)| 00:00:01 | ------------------------------------------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 6 - filter("D"."DOCSTATE"=3 AND ("D"."CREATEDAT">=TO_DATE(' 2013-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') OR "FS"."DOCTYPE" IS NOT NULL) OR EXISTS (SELECT 0 FROM "SUPERMAG"."TTDOCLIST" "T" WHERE "T"."ID"=:B1 AND "T"."DOCTYPE"=:B2)) 8 - access("T"."DOCID"(+)="S"."DOCID" AND "T"."DOCTYPE"(+)="S"."DOCTYPE" AND "T"."SPECITEM"(+)="S"."SPECITEM") 11 - access(("T"."DOCTYPE"(+)='CR' OR "T"."DOCTYPE"(+)='CS' OR "T"."DOCTYPE"(+)='IW' OR "T"."DOCTYPE"(+)='PE' OR "T"."DOCTYPE"(+)='PN' OR "T"."DOCTYPE"(+)='PO' OR "T"."DOCTYPE"(+)='WI' OR "T"."DOCTYPE"(+)='WO') AND "T"."SPECITEM"(+)>0) filter("T"."SPECITEM"(+)>0) 16 - access("S"."ARTICLE"='00021' AND ("S"."DOCTYPE"='CR' OR "S"."DOCTYPE"='CS' OR "S"."DOCTYPE"='IW' OR "S"."DOCTYPE"='PE' OR "S"."DOCTYPE"='PN' OR "S"."DOCTYPE"='PO' OR "S"."DOCTYPE"='WI' OR "S"."DOCTYPE"='WO')) 17 - access("S"."DOCTYPE"="D"."DOCTYPE" AND "S"."DOCID"="D"."ID") filter("D"."DOCTYPE"='CR' OR "D"."DOCTYPE"='CS' OR "D"."DOCTYPE"='IW' OR "D"."DOCTYPE"='PE' OR "D"."DOCTYPE"='PN' OR "D"."DOCTYPE"='PO' OR "D"."DOCTYPE"='WI' OR "D"."DOCTYPE"='WO') 20 - access("FS"."ENDDATE"(+)=TO_DATE(' 2013-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "FS"."DOCTYPE"(+)="S"."DOCTYPE" AND "FS"."DOCID"(+)="S"."DOCID" AND "FS"."SPECITEM"(+)="S"."SPECITEM") filter("FS"."SPECITEM"(+)>0 AND ("FS"."DOCTYPE"(+)='CR' OR "FS"."DOCTYPE"(+)='CS' OR "FS"."DOCTYPE"(+)='IW' OR "FS"."DOCTYPE"(+)='PE' OR "FS"."DOCTYPE"(+)='PN' OR "FS"."DOCTYPE"(+)='PO' OR "FS"."DOCTYPE"(+)='WI' OR "FS"."DOCTYPE"(+)='WO')) 21 - access("T"."DOCTYPE"=:B1 AND "T"."ID"=:B2) 23 - access("S"."DOCTYPE"="ST"."DOCTYPE"(+) AND "S"."ID"="ST"."DOCID"(+) AND "S"."SPECITEM"="ST"."SPECITEM"(+) AND "ST"."TAXID"(+)=1) 25 - access("S"."DOCTYPE"="XOUT"."DOCTYPE"(+) AND "S"."ID"="XOUT"."ID"(+)) 27 - access("S"."DOCTYPE"="XIN"."DOCTYPE"(+) AND "S"."ID"="XIN"."ID"(+)) 36 - filter("T"."DOCTYPE"='RL') 38 - access("D"."DOCTYPE"='RL' AND "T"."ID"="D"."ID") filter("T"."DOCTYPE"="D"."DOCTYPE") 40 - access("S"."ARTICLE"='00021' AND "S"."DOCTYPE"='RL' AND "S"."DOCID"="D"."ID") 42 - access("T"."DOCTYPE"(+)='RL' AND "T"."DOCID"(+)="S"."DOCID" AND "T"."SPECITEM"(+)="S"."SPECITEM") filter("T"."SPECITEM"(+)>0) 44 - access("S"."DOCTYPE"="XOUT"."DOCTYPE"(+) AND "S"."ID"="XOUT"."ID"(+)) 46 - access("S"."DOCTYPE"="XIN"."DOCTYPE"(+) AND "S"."ID"="XIN"."ID"(+)) 48 - access("S"."DOCTYPE"="ST"."DOCTYPE"(+) AND "S"."ID"="ST"."DOCID"(+) AND "S"."SPECITEM"="ST"."SPECITEM"(+) AND "ST"."TAXID"(+)=1)