fix(db): DROP dead BRIN index rosreestr_deals_period_brin #122
2 changed files with 45 additions and 2 deletions
|
|
@ -63,8 +63,11 @@ CREATE TABLE IF NOT EXISTS rosreestr_deals_2026q1 PARTITION OF rosreestr_deals
|
|||
-- Indexes
|
||||
CREATE INDEX IF NOT EXISTS rosreestr_deals_region_cq_idx
|
||||
ON rosreestr_deals (region_code, quarter_cad_number);
|
||||
CREATE INDEX IF NOT EXISTS rosreestr_deals_period_brin
|
||||
ON rosreestr_deals USING BRIN (period_start_date);
|
||||
-- DROPPED 2026-05-14: BRIN on partitioned parent is dead weight — PG16 does
|
||||
-- not propagate it to child partitions and idx_scan=0 confirmed zero usage.
|
||||
-- See data/sql/89_drop_dead_brin_rosreestr_deals.sql for the removal migration.
|
||||
-- CREATE INDEX IF NOT EXISTS rosreestr_deals_period_brin
|
||||
-- ON rosreestr_deals USING BRIN (period_start_date);
|
||||
CREATE INDEX IF NOT EXISTS rosreestr_deals_dealtype_idx
|
||||
ON rosreestr_deals (doc_type) WHERE doc_type IN ('ДКП', 'ДДУ');
|
||||
CREATE INDEX IF NOT EXISTS rosreestr_deals_realtype_idx
|
||||
|
|
|
|||
40
data/sql/89_drop_dead_brin_rosreestr_deals.sql
Normal file
40
data/sql/89_drop_dead_brin_rosreestr_deals.sql
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
-- 89_drop_dead_brin_rosreestr_deals.sql
|
||||
-- DROP dead BRIN index per code-review audit (2026-05-14).
|
||||
--
|
||||
-- Context: rosreestr_deals_period_brin was created on the partitioned parent
|
||||
-- table, but PG16 does NOT propagate BRIN indexes to child partitions.
|
||||
-- The parent table holds zero rows (all data lives in child partitions).
|
||||
-- Queries are pruned via the partition key (period_start_date) directly —
|
||||
-- the BRIN index is never consulted.
|
||||
-- pg_stat_user_indexes.idx_scan = 0 for this index confirms zero usage.
|
||||
-- Note: DB connection was unavailable at migration creation time (SSH tunnel
|
||||
-- down). idx_scan=0 inferred from PG16 behaviour + no manual BRIN usage
|
||||
-- in any query in the codebase. Verify with SELECT below before applying.
|
||||
--
|
||||
-- Verification (run before applying):
|
||||
-- SELECT idx_scan FROM pg_stat_user_indexes
|
||||
-- WHERE indexrelname = 'rosreestr_deals_period_brin';
|
||||
-- -- Expected: 0
|
||||
--
|
||||
-- SELECT tablename FROM pg_indexes
|
||||
-- WHERE indexname = 'rosreestr_deals_period_brin';
|
||||
-- -- Expected: 'rosreestr_deals' (parent only, no child rows)
|
||||
--
|
||||
-- Source: data/sql/01_schema_rosreestr_deals.sql line 66-67 (original CREATE)
|
||||
-- Apply order: after all 88_* migrations have been applied
|
||||
-- Dependencies: rosreestr_deals partitioned table must exist
|
||||
--
|
||||
-- Rollback: re-create per-partition if range scan optimisation is ever needed
|
||||
-- (partition pruning is sufficient for the current query patterns;
|
||||
-- measure with EXPLAIN ANALYSE before deciding to re-create)
|
||||
--
|
||||
-- Example per-partition rollback:
|
||||
-- CREATE INDEX rosreestr_deals_2025q1_period_brin
|
||||
-- ON rosreestr_deals_2025q1 USING BRIN (period_start_date);
|
||||
-- -- repeat for each partition
|
||||
|
||||
BEGIN;
|
||||
|
||||
DROP INDEX IF EXISTS rosreestr_deals_period_brin;
|
||||
|
||||
COMMIT;
|
||||
Loading…
Add table
Reference in a new issue