1 Commits

Author SHA1 Message Date
Fredrik Adelöw 39c5fbb633 Add extended statistics on search(key, value) for planner accuracy
The search table is an EAV schema where key and value are highly
correlated, but standard single-column statistics can't model this.
This caused the planner to underestimate compound filter queries by
up to 1300x, choosing materialize-then-sort plans instead of LIMIT
short-circuit index scans.

CREATE STATISTICS captures the (key, value) correlation via
dependencies, ndistinct, and most-common-values metadata. The planner
then correctly estimates row counts and chooses the index-driven plan.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
2026-05-19 23:11:19 +02:00