From 25680994dded04dba21f20f08f36ff3ab4c4b720 Mon Sep 17 00:00:00 2001 From: Pako Date: Mon, 30 Sep 2024 10:24:45 +0200 Subject: [PATCH] feat(previaDelta): refs #8030 new algorithym for coincident records when many records target the same zoneGeoFk, the deepest must be chosen Refs: #8030 --- .../procedures/catalog_componentCalculate.sql | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/db/routines/vn/procedures/catalog_componentCalculate.sql b/db/routines/vn/procedures/catalog_componentCalculate.sql index b49f7ad8a..ee246f9f8 100644 --- a/db/routines/vn/procedures/catalog_componentCalculate.sql +++ b/db/routines/vn/procedures/catalog_componentCalculate.sql @@ -28,24 +28,29 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tPriceDelta (INDEX (itemFk)) ENGINE = MEMORY - SELECT i.id itemFk, - SUM(IFNULL(pd.absIncreasing,0)) absIncreasing, - SUM(IFNULL(pd.ratIncreasing,0)) ratIncreasing, - pd.warehouseFk - FROM item i - JOIN priceDelta pd - ON pd.itemTypeFk = i.typeFk - AND (pd.minSize IS NULL OR pd.minSize <= i.`size`) - AND (pd.maxSize IS NULL OR pd.maxSize >= i.`size`) - AND (pd.inkFk IS NULL OR pd.inkFk = i.inkFk) - AND (pd.originFk IS NULL OR pd.originFk = i.originFk) - AND (pd.producerFk IS NULL OR pd.producerFk = i.producerFk) - AND (pd.warehouseFk IS NULL OR pd.warehouseFk = vWarehouseFk) - LEFT JOIN zoneGeo zg ON zg.id = pd.zoneGeoFk - WHERE (pd.fromDated IS NULL OR pd.fromDated <= vShipped) - AND (pd.toDated IS NULL OR pd.toDated >= vShipped) - AND (pd.zoneGeoFk IS NULL OR address_getGeo(vAddressFk) BETWEEN zg.lft AND zg.rgt) - GROUP BY i.id; + SELECT * FROM + ( + SELECT i.id itemFk, + SUM(IFNULL(pd.absIncreasing,0)) absIncreasing, + SUM(IFNULL(pd.ratIncreasing,0)) ratIncreasing, + pd.warehouseFk + FROM item i + JOIN priceDelta pd + ON pd.itemTypeFk = i.typeFk + AND (pd.minSize IS NULL OR pd.minSize <= i.`size`) + AND (pd.maxSize IS NULL OR pd.maxSize >= i.`size`) + AND (pd.inkFk IS NULL OR pd.inkFk = i.inkFk) + AND (pd.originFk IS NULL OR pd.originFk = i.originFk) + AND (pd.producerFk IS NULL OR pd.producerFk = i.producerFk) + AND (pd.warehouseFk IS NULL OR pd.warehouseFk = vWarehouseFk) + LEFT JOIN zoneGeo zg ON zg.id = pd.zoneGeoFk + LEFT JOIN zoneGeo zg2 ON zg2.id = address_getGeo(vAddressFk) + WHERE (pd.fromDated IS NULL OR pd.fromDated <= vShipped) + AND (pd.toDated IS NULL OR pd.toDated >= vShipped) + AND (pd.zoneGeoFk IS NULL OR zg2.lft BETWEEN zg.lft AND zg.rgt) + ORDER BY zg.`depth` DESC + LIMIT 10000000000000000000 + ) sub GROUP BY itemFk; CREATE OR REPLACE TEMPORARY TABLE tSpecialPrice (INDEX (itemFk))