fix(db): persist hnsw.iterative_scan via ALTER DATABASE instead of SET

SET only applies to the current migration session and is lost when the
connection closes. Use a DO block with current_database() to execute
ALTER DATABASE ... SET, which persists the GUC for all future connections.

The DO block with format('%I', current_database()) avoids hardcoding
the database name and works on PostgreSQL < 16 (which lacks ALTER DATABASE
CURRENT syntax).
This commit is contained in:
yiling
2026-05-29 15:29:29 +08:00
parent 048028007e
commit ddac22a12f
@@ -1,5 +1,11 @@
-- Enable iterative index scans for HNSW so filtered queries don't fall back to seq scan
SET hnsw.iterative_scan = relaxed_order;
-- Enable iterative index scans for HNSW so filtered queries don't fall back to seq scan.
-- Uses current_database() so this works across all environments without hardcoding the DB name.
-- ALTER DATABASE ... SET persists the GUC for all future connections to this database.
DO $$
BEGIN
EXECUTE format('ALTER DATABASE %I SET hnsw.iterative_scan = ''relaxed_order''', current_database());
END;
$$;
-- CreateIndex: HNSW index on asset_embeddings.embedding
-- Uses cosine distance ops (suited for normalized OpenAI-style embeddings)