Per code review audit (May 14): BRIN index на partitioned parent table dead weight. PG16 НЕ propagates такие индексы на child partitions; pg_stat показывает idx_scan=0 → никогда не использовался. ## Why dead rosreestr_deals — yearly partitioned по period_start_date. Queries делают partition pruning через partition key. BRIN index на parent существует, но: 1. На child partitions его нет (PG16 не reflects) 2. Parent сам не имеет данных (partitioned out) 3. Queries никогда не trigger BRIN scan Maintenance overhead (storage, autoanalyze) без value. ## Migration `data/sql/89_drop_dead_brin_rosreestr_deals.sql` — атомарный DROP с idempotent `IF EXISTS`. Apply order: после 88_*. ## Cleanup `data/sql/01_schema_rosreestr_deals.sql:65-67` — закомментировал оригинальное CREATE с note: fresh DB bootstrap НЕ создаст index заново. ## Rollback path Если в будущем нужен range scan optimization — re-create per-partition: ```sql CREATE INDEX rosreestr_deals_2024q1_period_brin ON rosreestr_deals_2024q1 USING BRIN (period_start_date); -- per-partition × N partitions ``` Но обычно partition pruning достаточно. Измерь EXPLAIN перед re-creation. ## Vault `fixes/Migration_Drop_Dead_Brin_May14.md` создан (status: ready_to_apply). Apply на prod: `psql ... -f data/sql/89_drop_dead_brin_rosreestr_deals.sql` после merge. Co-authored-by: lekss361 <claudestars@proton.me>
40 lines
1.7 KiB
PL/PgSQL
40 lines
1.7 KiB
PL/PgSQL
-- 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;
|