perf(db): add indexes for trash and admin post list queries

- idx_posts_deleted_at: 回收站查询 WHERE deleted_at IS NOT NULL ORDER BY deleted_at DESC
- idx_posts_created_at_admin: 管理后台全量列表 WHERE deleted_at IS NULL ORDER BY created_at DESC
This commit is contained in:
xfy 2026-06-18 11:02:13 +08:00
parent 306da3cf83
commit c6161764a9

View File

@ -0,0 +1,13 @@
-- 性能审计补充索引。
-- 所有索引均为 CREATE INDEX IF NOT EXISTS对已有数据库安全幂等。
-- 回收站查询trash.rs 中大量 WHERE deleted_at IS NOT NULL ... ORDER BY deleted_at DESC。
-- 配合 list_deleted_posts 的 ORDER BY deleted_at DESC 分页。
CREATE INDEX IF NOT EXISTS idx_posts_deleted_at
ON posts(deleted_at DESC) WHERE deleted_at IS NOT NULL;
-- 管理后台列表 list_postsWHERE deleted_at IS NULL ORDER BY created_at DESC。
-- 注意 002_posts.sql 已有 idx_posts_status_published仅 published 分页),
-- 这里补充未按 status 过滤的管理后台全量列表路径。
CREATE INDEX IF NOT EXISTS idx_posts_created_at_admin
ON posts(created_at DESC) WHERE deleted_at IS NULL;