From 8aeecc845bd9cf0fed316c6bb146ecbfed6c01ee Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 13 Feb 2020 23:54:11 -0500 Subject: [PATCH] use materialized view of itemm and use date range object to facilitate join --- route_sql/new_basket.sql | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/route_sql/new_basket.sql b/route_sql/new_basket.sql index ddc41e7..9a29b4f 100644 --- a/route_sql/new_basket.sql +++ b/route_sql/new_basket.sql @@ -13,6 +13,7 @@ target AS (select $$replace_request$$::json def) ,to_char(N1FSYP,'FM0000') FSPR ,N1SD01 SDAT ,N1ED01 EDAT + ,daterange(n1sd01, n1ed01) drange ,to_char(N1ED01,'yymm') CAPR ,N1ED01 - N1SD01 +1 NDAYS ,CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(YEAR FROM N1ED01) + 1 ELSE EXTRACT(YEAR FROM N1ED01) END SSYR @@ -251,11 +252,11 @@ SELECT JOIN LATERAL json_to_record(ae.e) as jr(part_descr text, bill_cust_descr text, ship_cust_descr text, mix numeric) ON true CROSS JOIN mxm LEFT OUTER JOIN gld od ON - make_date(mxm.yr + 2021,mxm.cal,mxm.odom) BETWEEN od.sdat AND od.edat + od.drange @> make_date(mxm.yr + 2021,mxm.cal,mxm.odom) LEFT OUTER JOIN gld rd ON - make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag BETWEEN rd.sdat AND rd.edat + od.drange @> (make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag) LEFT OUTER JOIN gld sd ON - make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat + od.drange @> (make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag + slag) ) --SELECT * FROM basemix ,log AS ( @@ -336,7 +337,7 @@ SELECT FROM basemix b CROSS JOIN log - LEFT OUTER JOIN rlarp.itemm i ON + LEFT OUTER JOIN rlarp.itemmv i ON i.item = b.part LEFT OUTER JOIN SEG ON SEG.GLEC = i.glec