From: natehaze (@natehaze) <noreply+natehaze@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #776: Iterative Scan doesn't support filtering by subquery
Date: Fri, 14 Feb 2025 20:51:22 +0000
Message-ID: <gh-pgvector-pgvector-776-c2660238337@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-776@github.com>
References: <gh-pgvector-pgvector-776@github.com>
OK. (actually as ugly as it is `(select i % 10000 = 0 where i %10000 = 0)` is a valid filter. `SET enable_seqscan = off;` does NOT trigger the index to be used for the equivalent subquery (to `i % 10000 = 0`). I was able to finally (with the help of `pg_hint_plan`) see this work.
To answer my questions.
1. I don't think a subquery can be applied to a `filter` in postgres.
- Actually I now see in real data that it can be applied directly to the filter as a hashed subplan
3. A `filter` is NOT necessary for `pgvector` to perform an iterative scan.
see
https://gist.github.com/natehaze/ca6c48ab861f8252d7253c5283ea7ccf
The final two queries show that the nested loop does indeed use an iterative scan. It is incredibly hard to discern that though. The trick is just seeing that one query (not iterative) returns 1 row and the other (iterative) returns 10 rows. Without digging to the depths of the query plan it's impossible to know if those 10 rows are coming from an iterative scan, OR another query plan altogether.
**@ankane Would it be possible to have a debug output from pgvector that says when it DOES perform an iterative scan?**
I understand that an iterative scan is not always going to be the best plan. However, I DO want to get a feeling for what sort of conditions trigger one and what the performance is on our real data without necessarily getting a query plan every time.