Commit ea857067 by luoqi

perf(plan): patient_facts(patient_id,type,status) 索引 — 召回 selectHits ~3.6×

EXPLAIN 定位:selectHits 的 sig 信号扫描 + gap resolvedTeeth 各子查询都按 (patient_id,type,status) 过滤,原仅 (patient_id,status) 索引 → type 走内存 Filter,facts/患者多时 heap fetch 超线性膨胀(本地单条 K08 查询读 1.3GB 页面产 81 行)。加复合索引后所有子查询命中 Bitmap Index Scan。本地 selectHits warm 7.3s→2.0s(~3.6×),prod 13万患者收益更大。

迁移用 CREATE INDEX IF NOT EXISTS:prod 大表可先手动 CREATE INDEX CONCURRENTLY 预建免锁表,再 deploy 时本句 no-op。规则零改动、纯加速。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
parent e1ffafbc
-- 召回 selectHits 主路径索引:sig 信号 + gap resolvedTeeth 子查询均按 (patient_id, type, status) 过滤。
-- 原仅 (patient_id, status) → type 内存过滤,facts/患者多时 heap fetch 超线性膨胀(全量重算 50min 主因)。
-- IF NOT EXISTS:prod 可先手动 CREATE INDEX CONCURRENTLY 预建(免锁表),再 deploy 时本句即 no-op。
CREATE INDEX IF NOT EXISTS "patient_facts_patient_id_type_status_idx"
ON "patient_facts"("patient_id", "type", "status");
...@@ -606,6 +606,10 @@ model PatientFact { ...@@ -606,6 +606,10 @@ model PatientFact {
@@index([hostId, tenantId]) @@index([hostId, tenantId])
/// 拉某患者当前 active 视图(persona / plan 重算主路径) /// 拉某患者当前 active 视图(persona / plan 重算主路径)
@@index([patientId, status]) @@index([patientId, status])
/// 召回 selectHits 主路径:sig 信号扫描 + gap resolvedTeeth 各子查询都按 (patient_id, type, status) 过滤。
/// 原仅 (patient_id, status) type 走内存 Filter,facts/患者 多时 heap fetch 超线性膨胀(13万患者全量重算瓶颈)
/// 实测本地 selectHits 7.3s2.0s(~3.6×),prod 收益更大。
@@index([patientId, type, status])
/// 按患者拉 actual 时间轴 /// 按患者拉 actual 时间轴
@@index([patientId, occurredAt]) @@index([patientId, occurredAt])
/// 按患者查 planned 列表(待办 / 即将复查) /// 按患者查 planned 列表(待办 / 即将复查)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment