Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Add indexes for chat_files purge query when chats graduate from experimental

已关闭
#1,438 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
50/100
Issue 类型
重构
描述清晰度
基本清楚
活跃度
冷清
技术栈
sql
领域
databases

调研方向

从 dbpurge 中的 DeleteOldChatFiles SQL 查询开始,检查 kept_file_ids 和 deletable CTE,包括它们的过滤条件、排序和 limit。比较添加支持索引或拆分 CTE 前后的查询计划;当 purge 在生产规模的数据上避免报告中的顺序扫描和排序时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

tech-debt

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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

coder/internal 的其他 Issue

查看 coder/internal 的全部 Issue

相似的 Issue

更多 Databases Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。