From 42c5900efec60ae280240ca0560a6b4cc7da208a Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 27 Aug 2025 20:06:02 -0400 Subject: [PATCH] huge increase in run times --- procs/matrix_guidance.pg.sql | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/procs/matrix_guidance.pg.sql b/procs/matrix_guidance.pg.sql index 9c8f3e9..9feb715 100644 --- a/procs/matrix_guidance.pg.sql +++ b/procs/matrix_guidance.pg.sql @@ -66,6 +66,7 @@ BEGIN -- 1) Seed queue from matrix -------------------------------------------------------------------- DELETE FROM pricequote.queue; + -- 1:30 INSERT INTO pricequote.queue (bill, ship, part, stlc, v1ds, vol, expl, ui_json) SELECT DISTINCT @@ -84,7 +85,7 @@ BEGIN AND o.version IN ('Actual', 'Forecast', 'Quotes') AND o.part IS NOT NULL AND SUBSTRING(o.glec, 1, 1) <= '2'; - -- 46 seconds + -- 2:12 -------------------------------------------------------------------- -- 2) Enrich: chan, tier, cust, pltq, plevel, partgroup (+stlc fix) @@ -126,7 +127,7 @@ BEGIN plevel = s.plevel, partgroup = s.partgroup, stlc = COALESCE(q.stlc, s.stlc_fix); - -- 16 seconds + -- 4:51 -------------------------------------------------------------------- -- 3) Scenario fields from item master: part_v1ds, v0ds, orig costs @@ -146,7 +147,7 @@ BEGIN END FROM "CMS.CUSLG".itemm i0 WHERE i0.item = q.part; - -- 16 seconds + -- 3:21 -------------------------------------------------------------------- -- 4) History: store hist, extract last_* with precedence helper @@ -184,7 +185,7 @@ BEGIN AND lp2.partgroup = q2.partgroup ) AS x WHERE q.ctid = x.ctid; - -- 2 min 3 sec + -- 7:32 -------------------------------------------------------------------- -- 5) Target (requested v1ds): tprice, tmath, volume_range @@ -201,7 +202,7 @@ BEGIN AND tp.chan = q.chan AND tp.tier = q.tier AND FLOOR(q.vol / NULLIF(q.pltq, 0))::INT <@ tp.vol; - -- 22 seconds + -- 2:51 -------------------------------------------------------------------- -- 6) Target for last_dataseg (tprice_last) @@ -217,7 +218,7 @@ BEGIN AND tp2.chan = q.chan AND tp2.tier = q.tier AND FLOOR(q.last_qty / NULLIF(q.pltq, 0))::INT <@ tp2.vol; - -- 17 sec + -- 1:26 -------------------------------------------------------------------- -- 7) Cost data for requested v1ds and last_dataseg @@ -250,7 +251,7 @@ BEGIN ON v0l.stlc = q2.stlc AND v0l.v0ds = q2.last_v0ds ) AS s WHERE q.ctid = s.ctid; - -- 28 seconds + -- 4:15 -------------------------------------------------------------------- -- 8) List price (lowest valid); allow open-ended ranges (vb_to IS NULL) @@ -280,7 +281,7 @@ BEGIN listcode = p.jcplcd FROM best_price p WHERE q.ctid = p.ctid; - -- 18 seconds + -- 2:48 -------------------------------------------------------------------- -- 9) Normalize last (when last_dataseg != v1ds) + effective list flags @@ -328,7 +329,7 @@ BEGIN END, listprice_eff = CASE WHEN q.customized <> '' THEN NULL ELSE q.listprice END, list_relevance = CASE WHEN q.customized <> '' THEN 'Ignore - Customized' ELSE '' END; - -- 21 seconds + -- 2:22 -------------------------------------------------------------------- -- 10) Guidance using normalized last + effective list @@ -352,7 +353,7 @@ BEGIN ) g ON TRUE ) s WHERE q.ctid = s.ctid; - -- 31 seconds + -- 4:33 -------------------------------------------------------------------- -- 11) Build expl and ui_json identical to single_price_call @@ -498,7 +499,7 @@ BEGIN ), 'data', q.expl ); - -- 2 minutes 33 seconds + -- 7:59 -------------------------------------------------------------------- -- 12) Merge back into matrix (store both expl and ui) @@ -522,7 +523,7 @@ BEGIN AND o.version IN ('Actual', 'Forecast', 'Quotes') AND o.part IS NOT NULL AND SUBSTRING(o.glec, 1, 1) <= '2'; - -- 9 minutes 35 seconds + -- 14:13 RAISE NOTICE 'Queue processing complete.'; END;