From: oliness (@oliness) <noreply+oliness@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] PR #1031: Remove approximate indexes for ORDER BY queries without a LIMIT
Date: Wed, 23 Sep 2026 19:42:21 +0000
Message-ID: <gh-pgvector-pgvector-1031-c5801690496@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-1031@github.com>
References: <gh-pgvector-pgvector-1031@github.com>
I've added TAP tests for the `tuple_fraction = 0` case: `test/t/049_hnsw_no_limit.pl` and `test/t/050_ivfflat_no_limit.pl`, one per index type. They run with `enable_sort = off`, so the index is chosen whenever it's allowed.
For queries planned with `tuple_fraction = 0`, they check that the index isn't used and that the results match a scan with `enable_indexscan = off`:
- no `LIMIT`
- a subquery without its own `LIMIT`, under an outer aggregate, `GROUP BY`, `ROLLUP`, `HAVING`, `DISTINCT`, `ORDER BY` on another column, or join
- the same kind of subquery when the outer query only reads the first rows: an outer `ORDER BY` on the same distance with a `LIMIT`, or a join ordered by distance with a `LIMIT`
They also check that these queries still use the index:
- a `LIMIT`
- an outer `LIMIT` with nothing else in the outer query
- a subquery with its own `LIMIT`, under an aggregate, `ORDER BY`, or join
- no `LIMIT` with `enable_seqscan = off`, at the top level and in a subquery
On master, 17 of the 27 checks in each file fail, including every "no index scan" check. The checks for queries that should still use the index pass on master too.