Files
SupplierSystem/migrations/20261077_reconcile_guard_indexes.sql
Ubuntu 6ebfa93016
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
perf(对账): 查询超时护栏(SET+RESET) + 每轮90s预算 + 自愈补录增量窗口(最近3天/50单) + 配套索引;附需主系统配合清单(M1-M5)
2026-10-24 13:19:58 +08:00

23 lines
1.5 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 跨系统对账:**查询超时护栏 + 每轮预算所需的索引**(2026-10-24 开发者:
-- 「这个你看看怎么优化 需要主系统配合给我说」;「别急着部署 本地测试好了再来」)
--
-- 目标(纯本地优化,不需要主系统配合):
-- ① 报表/台账类全量查询加 `statement_timeout` 后仍是慢查询的,靠索引把单次耗时压到毫秒级:
-- · 退回台账轮询(每 2 分钟/分公司):`main_system_order_import_items` 上按 `last_return_code` 非空扫;
-- · 退货跟随:按 `last_seen_active_at` 找"曾经 active 过"的行;
-- · 自愈补录:`main_system_order_imports` 按 `imported_at` 取最近 N 天(增量化后只扫窗口)。
--
-- 说明:`after_sale_returns` 已有 `uq_after_sale_returns_main_code_order`(branch_code, main_return_code, …),
-- 退回轮询的 NOT EXISTS 已能走索引,无需再加。
CREATE INDEX IF NOT EXISTS idx_import_items_pending_returns
ON public.main_system_order_import_items (branch_code, prep_id)
WHERE last_return_code IS NOT NULL AND TRIM(last_return_code) <> '';
CREATE INDEX IF NOT EXISTS idx_import_items_last_seen_active
ON public.main_system_order_import_items (branch_code, last_seen_active_at DESC NULLS LAST);
-- 自愈补录增量化:只扫最近窗口内的导入单(按 imported_at,列已存在)
CREATE INDEX IF NOT EXISTS idx_main_system_order_imports_recent
ON public.main_system_order_imports (branch_code, imported_at DESC);