Files
ai_academy/migrations/versioned/000100_chunks_index_diet.up.sql
runny 7ec21f35b0 chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、
Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。
今日开发的培训推送管理改动随后单独提交。
2026-11-16 18:12:23 +08:00

23 lines
1.3 KiB
SQL

-- ============================================================================
-- Migration 000100: Drop chunks indexes that only slow down writes
-- ============================================================================
-- Every INSERT/UPDATE on chunks maintains all of its indexes. Three of them
-- never help a query:
-- * idx_chunks_chunk_type — chunk_type has a handful of distinct values
-- and is always combined with knowledge_id /
-- knowledge_base_id, which already have indexes.
-- * idx_chunks_content_hash — no query filters on content_hash; FAQ diffing
-- reads the column but scans by knowledge_base_id.
-- * idx_chunks_tenant_kg — (tenant_id, knowledge_id) is covered by
-- idx_chunks_knowledge_enabled, which leads with
-- the high-cardinality knowledge_id.
-- ============================================================================
DO $$ BEGIN RAISE NOTICE '[Migration 000100] Dropping redundant chunks indexes'; END $$;
DROP INDEX IF EXISTS idx_chunks_chunk_type;
DROP INDEX IF EXISTS idx_chunks_content_hash;
DROP INDEX IF EXISTS idx_chunks_tenant_kg;
DO $$ BEGIN RAISE NOTICE '[Migration 000100] Redundant chunks indexes dropped'; END $$;