Files
material_texture/migrations/003_add_indexes.sql
likegears 85ba15c564 Initial commit: Material Texture API service
- Go + Gin + GORM + PostgreSQL backend
- RESTful API for material management
- Docker deployment support
- Database partitioning for billion-scale data
- API documentation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-11 15:29:49 +08:00

27 lines
1.0 KiB
SQL
Raw 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.
-- ============================================
-- Migration: 003_add_indexes.sql
-- Purpose: 添加性能优化索引
-- ============================================
-- 1. 启用 pg_trgm 扩展 (支持模糊搜索索引)
CREATE EXTENSION IF NOT EXISTS pg_trgm;
-- 2. 材质名称模糊搜索索引 (GIN 索引,支持 ILIKE '%keyword%')
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_materials_name_trgm
ON materials USING gin (name gin_trgm_ops);
-- 3. 材质创建时间索引 (用于排序)
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_materials_created_at
ON materials(created_at DESC);
-- 4. 材质更新时间索引
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_materials_updated_at
ON materials(updated_at DESC);
-- 注意: 如果使用了分区表 (002_partition_bindings.sql)
-- 以下索引已在分区迁移中创建,可跳过
-- 5. binding 表 group_id + material_id 复合索引 (优化批量查询)
-- CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_bindings_group_material
-- ON material_bindings(group_id, material_id);