Skip to content

Commit 3686517

Browse files
committed
Fix O(n²) scaling in planner for nullable natural keys
Two optimizations that together provide 4x speedup for realistic workloads: 1. Canonical NK resolution (Step 21): When all new entities have uniform NK specificity (same non-null keys pattern), skip the O(n²) LATERAL join and use direct assignment. Reduces step from 60ms to 12ms. 2. Target rows filter (Step 9): Replace NULL-safe OR join pattern with partitioned equality joins. The old pattern caused O(n²) bitmap scans because PostgreSQL couldn't optimize the OR condition. New approach partitions by NULL pattern and uses simple IN clauses per partition. Performance impact on test 112 (realistic SEED benchmark): - SEED stat_for_unit (ES): 582 → 4,577 rows/sec (7.8x faster) - Total SEED time: 60s → 15s (4x faster) Root cause: Natural keys with nullable columns (e.g., stat_for_unit with legal_unit_id XOR establishment_id) triggered worst-case query plans.
1 parent f286ca4 commit 3686517

4 files changed

Lines changed: 297 additions & 132 deletions

File tree

0 commit comments

Comments
 (0)