Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -258,8 +258,9 @@ norm AS (
|
||||
COALESCE(price, 0) AS price
|
||||
FROM input
|
||||
),
|
||||
-- Prefer PG's authoritative variant dimension table (mmitem_dim). Fall back to cache table if needed.
|
||||
dims_mmitem_dim AS (
|
||||
-- Only PG's authoritative variant dimension table may drive delta writes.
|
||||
-- Do not union sdprc/cache dimensions; stale rows there can re-create wrong variant keys.
|
||||
dims AS (
|
||||
SELECT
|
||||
norm.product_code AS product_code,
|
||||
md.val1::bigint AS dim1,
|
||||
@@ -275,41 +276,7 @@ norm AS (
|
||||
AND COALESCE(md.is_active, TRUE) = TRUE
|
||||
WHERE md.val1 IS NOT NULL
|
||||
AND md.val1 > 0
|
||||
GROUP BY norm.product_code, md.val1, md.val2
|
||||
),
|
||||
dims_cache_table AS (
|
||||
SELECT
|
||||
NULLIF(BTRIM(c.product_code), '') AS product_code,
|
||||
c.dim1::bigint AS dim1,
|
||||
c.dim3::bigint AS dim3
|
||||
FROM mk_mmitem_dim_combo c
|
||||
JOIN norm
|
||||
ON norm.product_code = c.product_code
|
||||
WHERE c.dim1 IS NOT NULL
|
||||
),
|
||||
dims_cache AS (
|
||||
SELECT product_code, dim1, dim3 FROM dims_mmitem_dim
|
||||
UNION
|
||||
SELECT product_code, dim1, dim3 FROM dims_cache_table
|
||||
),
|
||||
dims_sdprc AS (
|
||||
SELECT
|
||||
norm.product_code AS product_code,
|
||||
s.dim1 AS dim1,
|
||||
s.dim3 AS dim3
|
||||
FROM norm
|
||||
JOIN mmitem mm
|
||||
ON mm.code = norm.product_code
|
||||
JOIN sdprc s
|
||||
ON s.mmitem_id = mm.id
|
||||
WHERE s.dim1 IS NOT NULL
|
||||
AND s.dim1 > 0
|
||||
GROUP BY norm.product_code, s.dim1, s.dim3
|
||||
),
|
||||
dims AS (
|
||||
SELECT product_code, dim1, dim3 FROM dims_cache
|
||||
UNION
|
||||
SELECT product_code, dim1, dim3 FROM dims_sdprc
|
||||
GROUP BY norm.product_code, md.val1, md.val3
|
||||
),
|
||||
mapped AS (
|
||||
SELECT
|
||||
|
||||
Reference in New Issue
Block a user