yggdrasil/migrations/011_perf_indexes.sql
xfy c6161764a9 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
2026-06-18 11:02:13 +08:00

14 lines
752 B
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 性能审计补充索引。
-- 所有索引均为 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;