perf(cost-center): 商品页跳过无关 affiliate 聚合并补部分索引

This commit is contained in:
yml2213
2026-10-26 16:04:52 +08:00
parent f0dda3842b
commit 25012c30f4
2 changed files with 29 additions and 3 deletions
@@ -0,0 +1,19 @@
-- 113_cost_center_query_indexes.sql
-- 成本中心商品页性能:总览的「未映射订单项」与商品列表的 affiliate 任务聚合。
--
-- 背景:测试库 40 万 order_items 时,总览对 canonical_product_id IS NULL 做全表扫描约 3.8s;
-- 商品列表在人工 Tab 仍会聚合 30 天 affiliate 任务,测试机 IO 差时超过 10s。
-- 两个索引都是部分索引,体积远小于全表索引。
CREATE INDEX IF NOT EXISTS idx_order_items_unmapped_mode
ON order_items (fulfillment_mode)
WHERE canonical_product_id IS NULL;
CREATE INDEX IF NOT EXISTS idx_fulfillment_tasks_affiliate_recent
ON fulfillment_tasks (created_at)
WHERE executor_key = 'affiliate_dash';
COMMENT ON INDEX idx_order_items_unmapped_mode IS
'成本中心总览:按履约方式统计未归一订单项,避免全表扫 order_items';
COMMENT ON INDEX idx_fulfillment_tasks_affiliate_recent IS
'自动发货任务 30 天聚合:只索引 affiliate_dash,减少商品列表聚合扫描';