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>
This commit is contained in:
Fredrik Adelöw
2026-05-19 23:11:19 +02:00
parent cfb9f07c28
commit 39c5fbb633
2 changed files with 92 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend': patch
---
Added extended multi-column statistics on `(key, value)` in the `search` table (PostgreSQL only). This tells the query planner about the correlation between the `key` and `value` columns, fixing severe row count estimation errors on compound filter queries. Without this, the planner could choose to materialize and sort thousands of rows instead of using the LIMIT short-circuit index scan — causing 10-40x slower catalog list views when multiple filters are active.