yggdrasil/migrations/013_comment_content_hash_index.sql
xfy 82ab190e0d fix(comments): make duplicate-check atomic with transaction; index content_hash
查重 SELECT 与 INSERT 包进同一事务,串行化并发请求缩小重复窗口(M4);
重复时 rollback 空事务。content_hash 加索引(非唯一,避免误杀不同作者
发相同短内容的合法场景)加速 5 分钟窗口查重,原先全表扫。
2026-06-18 13:31:37 +08:00

6 lines
334 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.

-- 评论内容哈希索引,加速 5 分钟窗口内的重复检测查询。
-- 注意不加 UNIQUE 约束content_hash 基于 parent_id+author+content
-- 不同作者发相同内容(如"顶"、"+1")是合法的,唯一约束会误杀。
CREATE INDEX IF NOT EXISTS idx_comments_content_hash
ON comments(content_hash);