Add indexes for chat_files purge query when chats graduate from experimental
还没有人认领这个 Issue。
评估
调研方向
从 dbpurge 中的 DeleteOldChatFiles SQL 查询开始,检查 kept_file_ids 和 deletable CTE,包括它们的过滤条件、排序和 limit。比较添加支持索引或拆分 CTE 前后的查询计划;当 purge 在生产规模的数据上避免报告中的顺序扫描和排序时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Context
PR https://github.com/coder/coder/pull/23833 adds periodic cleanup of chat_files to dbpurge. The DeleteOldChatFiles SQL query does a sequential scan of both chats and chat_files because there are no supporting indexes. This is acceptable while chats are experimental with low row counts, but needs to be addressed before chats see production-scale traffic.
Flagged by Database Reviewer (P2), Edge Case Analyst (P2), and Go Architect during deep-review.
What needs indexing
1. chats table — kept_file_ids CTE
The CTE SELECT DISTINCT unnest(file_ids) FROM chats WHERE archived = false OR updated_at >= @before_time does a full seq scan with no index on archived or (archived, updated_at). The OR condition prevents the planner from using existing indexes. Cost scales with total_chats × avg(file_ids length).
Options:
CREATE INDEX ON chats (updated_at) WHERE archived = true+ split CTE into two UNIONed queries- Composite index on
(archived, updated_at)
2. chat_files table — deletable CTE
The CTE filters WHERE cf.created_at < @before_time and orders by created_at ASC with a LIMIT. No index on created_at means full scan + sort. Since chat_files rows carry bytea blob data, rows are wide — making the scan expensive per row.
Fix: CREATE INDEX idx_chat_files_created_at ON chat_files (created_at)
When
Before chats graduate from experimental status / see production-scale traffic.
- 主要语言
- 没有语言数据
- 星标
- 3
- 派生
- 0
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
coder/internal 的其他 Issue
-
flake
难度 2/5 1-3 小时 新手友好度 72/100
-
chore: cleanup http transport debt可能已有人在做 @sreya 于 19 天前认领。 未关闭
-
难度 4/5 3-5 天 新手友好度 45/100
-
flake: TestPubsubCluster/ClusterAuthRequired可能重新可做 @sreya 于 69 天前认领,目前没有进行中的 PR。 未关闭flake
-
flake: TestSnapshotChanged_MultipleConfigFiles (multiple variants)可能重新可做 @Shelnutt2 于 89 天前认领,目前没有进行中的 PR。 未关闭
相似的 Issue
-
documentation good first issue hacktoberfest
难度 1/5 1 小时以内 新手友好度 85/100
libredb/libredb-studio#1755 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
bug good first issue
难度 2/5 1-3 小时 新手友好度 82/100
Bible-Research/bible_research#51 ·
维护者通常 6 天内回复
-
area: bulk-copy
难度 2/5 1-3 小时 新手友好度 70/100
microsoft/mssql-python#843 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 半天 新手友好度 62/100
gnocchixyz/gnocchi#1527 ·
维护者通常 1 天内回复