From: hlinnaka (@hlinnaka) <noreply+hlinnaka@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: [pgvector/pgvector] issue #434: Limit HNSW build's shared memory size for small tables
Date: Thu, 25 Jan 2024 08:10:22 +0000
Message-ID: <gh-pgvector-pgvector-434@github.com> (raw)
It occurs to me that it's silly that we allocate an area based on `maintenance_work_mem`, even if the table is small. For example, if maintenance_work_mem is set to 10 GB, and the table has 1000 rows, clearly we don't need to allocate 10 GB.
There's some precedence for this in parallel VACUUM. It allocates an array to hold TIDs of dead tuples based on `maintenance_work_mem`, but it uses an upper limit on the worst case assumption that every page is full of tiny tuples, all deleted. See `dead_items_max_items`
It'd be nice t do something similar in HNSW build.