Files
thrilltrack-explorer/supabase/migrations/20251105182707_4c1e40b3-b4ef-4bd1-8a9c-2ece1429d4a6.sql
2025-11-05 18:27:27 +00:00

19 lines
1.0 KiB
SQL

-- Phase 1: Optimize temp ref lookups with covering index
-- This enables index-only scans, reducing query time by 2-3x
-- Drop redundant indexes that require table lookups
DROP INDEX IF EXISTS public.idx_submission_item_temp_refs_type;
DROP INDEX IF EXISTS public.idx_submission_item_temp_refs_item_type;
-- Create covering index that includes all frequently accessed columns
-- This allows PostgreSQL to satisfy queries entirely from the index without table access
CREATE INDEX idx_submission_item_temp_refs_covering
ON public.submission_item_temp_refs(submission_item_id)
INCLUDE (ref_type, ref_order_index);
COMMENT ON INDEX public.idx_submission_item_temp_refs_covering IS
'Covering index for temp ref lookups during approval processing. Enables index-only scans by including ref_type and ref_order_index columns.';
-- Verification: This query should now use index-only scan
-- EXPLAIN (ANALYZE, BUFFERS) SELECT ref_type, ref_order_index
-- FROM submission_item_temp_refs WHERE submission_item_id = 'some-uuid';