From: ankane (@ankane) <noreply+ankane@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #878: partial index "USING hnsw (embedding vector_cosine_ops) WHERE (some_bool = true)" gives partial results as if filtering
Date: Fri, 25 Jul 2025 16:35:35 +0000
Message-ID: <gh-pgvector-pgvector-878-c3119291373@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-878@github.com>
References: <gh-pgvector-pgvector-878@github.com>
Thanks.
From what I can tell, Postgres underestimates the cost of the `my_table_handy_bool_idx` index scan since it doesn't take [TOAST](https://www.postgresql.org/docs/current/storage-toast.html) into account.
With the specific setup above and `random_page_cost = 1.1` (the recommended value when using an SSD), this causes the planner to choose a suboptimal plan with ~50k rows (but not 100k+).
Two ways to address this are:
1. Use `PLAIN` storage for the `embedding` column, which avoids TOAST
2. Use [pg_hint_plan](https://github.com/ossc-db/pg_hint_plan) to help the planner