From: KilianU (@KilianU) <noreply+KilianU@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #702: Index not used when using a WITH expression
Date: Mon, 28 Oct 2024 14:53:16 +0000
Message-ID: <gh-pgvector-pgvector-702-c2441817795@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-702@github.com>
References: <gh-pgvector-pgvector-702@github.com>
Thank you @hlinnaka.
I tested it and found this variant to use the index:
```SQL
EXPLAIN WITH v AS (SELECT embedding as vec FROM incident_embedding WHERE incident_id = 2491825880941960244)
SELECT *, embedding <=> (SELECT v.vec from v) as distance FROM incident_embedding ORDER BY embedding <=> (SELECT v.vec from v) LIMIT 5;
```
`ORDER BY 2` caused a sequential scan...