Compare commits

..

No commits in common. "37fead59ffa9818f9c41cc179d2036ec6aa559a5" and "6bb0172c2debb025660bed10fa5a8b0ee9a41c84" have entirely different histories.

5 changed files with 40 additions and 60 deletions

View File

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

View File

@ -466,8 +466,8 @@ BEGIN
CASE ISNULL(q.last_source, '') CASE ISNULL(q.last_source, '')
WHEN 'mrq' THEN 'Similar Quote' WHEN 'mrq' THEN 'Similar Quote'
WHEN 'mrs' THEN 'Similar Sale' WHEN 'mrs' THEN 'Similar Sale'
WHEN 'dsq' THEN 'Last Quote' WHEN 'dsq' THEN 'Last Sale'
WHEN 'dss' THEN 'Last Sale' WHEN 'dss' THEN 'Last Quote'
ELSE '' ELSE ''
END END
ELSE 'No Recent' ELSE 'No Recent'
@ -601,5 +601,5 @@ BEGIN
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- Final: Return all calculated fields and JSON payloads. -- Final: Return all calculated fields and JSON payloads.
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
SELECT guidance_price, ui_json FROM @queue; SELECT guidance_price, ui_json FROM @queue;
END; END;

View File

@ -14,3 +14,28 @@ GRANT SELECT, INSERT, UPDATE, DELETE ON pricequote.target_prices TO PUBLIC;
DROP TABLE IF EXISTS import.core_target; DROP TABLE IF EXISTS import.core_target;
CREATE TABLE import.core_target AS (SELECT * FROM pricequote.core_target); CREATE TABLE import.core_target AS (SELECT * FROM pricequote.core_target);
WITH
expand AS (
SELECT
c.compset,
c.stlc,
c.floor,
b.ds,
b.chan,
b.tier,
b.vol,
b.val,
b.price,
json_pretty(to_json(b.math)) math
FROM
pricequote.core_target c
LEFT JOIN LATERAL pricequote.build_pricing_path_base (options||jsonb_build_object('entity','Anchor','attr',c.stlc,'val',c.floor,'func','Price')) b ON b.lastflag
)
-- select count(*) from expand
INSERT INTO
pricequote.target_prices_base
SELECT
*
FROM
expand

View File

@ -1,27 +0,0 @@
DELETE FROM pricequote.target_prices_base;
WITH
expand AS (
SELECT
c.compset,
c.stlc,
c.floor,
b.ds,
b.chan,
b.tier,
b.vol,
b.val,
b.price,
b.math math
FROM
pricequote.core_target c
LEFT JOIN LATERAL pricequote.build_pricing_path_base (options||jsonb_build_object('entity','Anchor','attr',c.stlc,'val',c.floor,'func','Price')) b ON b.lastflag
)
-- select count(*) from expand
INSERT INTO
pricequote.target_prices_base
SELECT
*
FROM
expand;

View File

@ -1,17 +0,0 @@
DROP TABLE pricequote.target_prices_base CASCADE;
CREATE TABLE pricequote.target_prices_base (
compset TEXT NOT NULL,
stlc TEXT NOT NULL,
floor NUMERIC NOT NULL,
ds TEXT NOT NULL,
chan TEXT NOT NULL,
tier TEXT NOT NULL,
vol INT4RANGE NOT NULL,
val NUMERIC NOT NULL,
price NUMERIC,
math TEXT[],
PRIMARY KEY (stlc, ds, chan, tier, vol)
);
GRANT SELECT, INSERT, UPDATE, DELETE ON pricequote.target_prices_base TO PUBLIC;