gendesign/tradein-mvp/backend/data/sql/086_deals_address_trgm_index.sql
bot-backend a9e4aecb54
All checks were successful
Deploy Trade-In / changes (push) Successful in 5s
Deploy Trade-In / build-frontend (push) Has been skipped
Deploy Trade-In / test (push) Successful in 26s
Deploy Trade-In / build-backend (push) Successful in 40s
Deploy Trade-In / deploy (push) Successful in 36s
fix(tradein): data-layer tail A2+B+C — trgm index, FDW options, matview refresh (Refs #769) (#804)
Co-authored-by: bot-backend <bot-backend@gendsgn.local>
Co-committed-by: bot-backend <bot-backend@gendsgn.local>
2026-05-30 17:40:54 +00:00

34 lines
1.4 KiB
PL/PgSQL

-- 086_deals_address_trgm_index.sql
-- Issue #769 Part A2 (finding #10) — GIN trigram index on deals.address.
--
-- Context:
-- The deals table (002_core_tables.sql line 84) has an `address text` column used
-- in street-match queries (import_rosreestr_dkp in scheduler.py builds ILIKE / text
-- predicates). Without a trigram index the planner falls back to seq-scan on the
-- full deals table. pg_trgm is already enabled in 050_search_optimization.sql but
-- only for the listings table — not for deals.
--
-- Idempotency:
-- CREATE EXTENSION IF NOT EXISTS — safe on re-run (ext already active = no-op).
-- CREATE INDEX IF NOT EXISTS — safe on re-run.
-- Both inside a single BEGIN/COMMIT — plain CREATE INDEX (not CONCURRENTLY) is
-- required to stay transaction-safe (CONCURRENTLY cannot run inside a txn block).
-- Acceptable here because deals is populated incrementally via FDW import batches
-- and the table starts small.
--
-- Dependencies:
-- 002_core_tables.sql (deals table with address column).
--
-- Deploy order:
-- Apply after 002_core_tables.sql. No application code changes required.
-- Post-deploy QA: EXPLAIN (ANALYZE, BUFFERS) SELECT ... FROM deals WHERE address
-- ILIKE '%улица%'; should show Bitmap Index Scan on deals_address_trgm_idx.
BEGIN;
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE INDEX IF NOT EXISTS deals_address_trgm_idx
ON deals USING gin (address gin_trgm_ops);
COMMIT;