Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Add indexes for chat_files purge query when chats graduate from experimental

Đang mở
#1,438 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
50/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
sql
Lĩnh vực
databases

Hướng nghiên cứu

Bắt đầu với truy vấn SQL DeleteOldChatFiles trong dbpurge và kiểm tra các CTE kept_file_ids và deletable, bao gồm các bộ lọc, thứ tự sắp xếp và giới hạn của chúng. So sánh kế hoạch truy vấn trước và sau khi thêm các chỉ mục hỗ trợ hoặc tách CTE; hoàn thành khi purge tránh được các lần quét tuần tự và thao tác sắp xếp đã báo cáo trên dữ liệu ở quy mô production.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Không có dữ liệu ngôn ngữ
Star
3
Fork
0
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của coder/internal

Tất cả issue của coder/internal

Issue tương tự

Thêm issue về Databases

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.