Files
foundry-core/deploy/research/query-indexes.sql
T

26 lines
1.8 KiB
SQL

-- 运维手动索引步骤:对已发布 research schema 执行,不能由只读服务角色调用,也不能包进事务。
-- 不属于 db/ 版本迁移;CREATE INDEX CONCURRENTLY 需要独立顶层语句,避免长时间阻塞语料读取。
-- Manual operator step against the published Paper Atlas schema, outside a
-- transaction. Core's SELECT-only runtime role must never execute this file.
-- These indexes support the actual author search and exact category filter;
-- the migration already owns the title/abstract English GIN index.
-- 调整的是当前运维会话的等待/维护预算,不会修改运行时服务连接池的配置。
-- 数据库迁移器只扫描 db/,不会自动执行这个文件;必须由有权限的运维会话单独运行。
SET lock_timeout = '2s';
SET statement_timeout = '20min';
SET maintenance_work_mem = '32MB';
SET max_parallel_maintenance_workers = 0;
-- (tag_id,paper_id) 支持纯主题页直接走关联索引,在 LIMIT 前避免读所有宽论文行。
-- 先按 tag_id 找命中的 paper_id,适配按主题过滤的访问方向;不是对论文全文字段建立索引。
CREATE INDEX CONCURRENTLY IF NOT EXISTS paper_tags_tag_paper
ON research.paper_tags(tag_id,paper_id);
-- simple 配置匹配作者查询的表达式,不对姓名做 english 词干化;索引表达式须与查询一致。
-- GIN 索引支持作者全文检索,使用 simple 配置保留姓名词项;与查询表达式不同就不能假设会命中本索引。
CREATE INDEX CONCURRENTLY IF NOT EXISTS papers_authors_search_gin
ON research.papers USING gin(to_tsvector('simple'::regconfig,authors_json));
-- After an interrupted concurrent build, inspect pg_index.indisvalid before
-- reuse. IF NOT EXISTS alone does not repair an invalid index.