2.2: propagate range conditions across join equalities in the planner hook
PostgreSQL derives equalities through equivalence classes but never
inequalities. For the indexer's transaction pages
FROM txn t JOIN block_header h ON t.round = h.round
WHERE t.round >= $1 ORDER BY t.round, t.intra LIMIT n
nothing tells the planner that h.round >= $1, so a plan that drives the
join from block_header scans that index from its first key and probes txn
for every round below $1. With an accurate n_distinct on round that plan
is the cheapest LIMIT plan on paper and the slowest one in practice
(6-12 s instead of 1-3 ms on a 3.7B-row table).
ineq_propagation.c adds, before planning, every column OP value condition
(OP one of <, <=, >=, >) to all columns joined to it with = of the same
type and operator family in the WHERE clause or an inner join. Only
conditions that hold for every output row are used and produced (nothing
at or below the nullable side of an outer join), so results never change.
The value side must be safe to evaluate twice; uncorrelated sub-selects
become a second init plan. GUC pg_algorand.propagate_inequalities.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BAkGJyPG5VRajhBwFRPiQ2
b386e114
main
10/909 ++ 4 --