Skip to content

fix(vchordrq): estimate filtered candidate selectivity#461

Open
spenc-r wants to merge 1 commit into
supervc-stack:mainfrom
spenc-r:cost-estimator-candidate-selectivity
Open

fix(vchordrq): estimate filtered candidate selectivity#461
spenc-r wants to merge 1 commit into
supervc-stack:mainfrom
spenc-r:cost-estimator-candidate-selectivity

Conversation

@spenc-r
Copy link
Copy Markdown

@spenc-r spenc-r commented May 21, 2026

What changed

Fixes vchordrq cost estimation for filtered ORDER BY distance LIMIT ... queries.

The estimator now separates:

  • filter selectivity: derived from the planner filtered row estimate (baserel->rows or parameterized ppi_rows)
  • index selectivity: derived from the expected candidate count retrieved by the scan

This avoids reporting indexSelectivity = 1.0 for heap-side filters that are not index quals, while also avoiding the opposite under-estimate of reporting only the final survivor fraction.

The candidate-processing term is also clamped by the IVF candidate budget (node_count).

Why

For vchordrq indexes, filters on non-vector columns live in baserestrictinfo, not indexclauses. The previous estimator therefore often reported selectivity as 1.0, causing PostgreSQL to price expensive filter evaluation against the whole table and reject the vector index path even when it was the better plan.

Tests

  • Added tests/vchordrq/cost_estimator.slt
  • Local sqllogictest run completed; adjusted case 11 for PG18 disabled-path behavior
  • git diff --check origin/main...HEAD
  • CI

Use the planner's filtered row estimate as filter selectivity for deciding how many IVFFlat candidates are needed to satisfy LIMIT after heap-side quals.

Report indexSelectivity from the expected retrieved candidate count instead of the final survivor fraction, so cost_index() prices heap fetch and qpqual evaluation against candidate rows rather than every table row or only the rows that pass filters.

Clamp the candidate-processing term by node_count, and tighten the cost estimator sqllogictest coverage around btree alternatives, candidate-cost floors, and extreme selectivity.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 21, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@spenc-r
Copy link
Copy Markdown
Author

spenc-r commented May 21, 2026

I have read the CLA Document and I hereby sign the CLA

gaocegege added a commit to tensorchord/CLA that referenced this pull request May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant