Files
huike-back/htykc_models/migrations/2026-05-03-013827_add_clazz_indexes/up.sql
T
weli fa14a5ca8c perf: add GIN indexes on clazz JSONB columns and date-range indexes
- GIN indexes on students/teachers (jsonb_path_ops) for fast user lookups
- Composite index on clazz (is_repeat, start_from, end_by) for date range queries
- Indexes on clazz_repeat (clazz_id, repeat_start, repeat_end) for joins

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-03 09:39:36 +08:00

11 lines
621 B
SQL

-- GIN indexes for JSONB path queries on students/teachers
CREATE INDEX IF NOT EXISTS idx_clazz_students_gin ON clazz USING gin (students jsonb_path_ops);
CREATE INDEX IF NOT EXISTS idx_clazz_teachers_gin ON clazz USING gin (teachers jsonb_path_ops);
-- Composite index for date range + is_repeat filter
CREATE INDEX IF NOT EXISTS idx_clazz_date_active ON clazz (is_repeat, start_from, end_by);
-- Indexes on clazz_repeat for join queries
CREATE INDEX IF NOT EXISTS idx_clazz_repeat_clazz_id ON clazz_repeat (clazz_id);
CREATE INDEX IF NOT EXISTS idx_clazz_repeat_date_range ON clazz_repeat (repeat_start, repeat_end);