From ddac22a12f88b3549618e2a999ee8bbe4b8e469f Mon Sep 17 00:00:00 2001 From: yiling Date: Fri, 29 May 2026 15:29:29 +0800 Subject: [PATCH] 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). --- .../migration.sql | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/prisma/migrations/20260529071403_add_hnsw_index_to_asset_embeddings/migration.sql b/prisma/migrations/20260529071403_add_hnsw_index_to_asset_embeddings/migration.sql index 5091cdd6..37fb8b1b 100644 --- a/prisma/migrations/20260529071403_add_hnsw_index_to_asset_embeddings/migration.sql +++ b/prisma/migrations/20260529071403_add_hnsw_index_to_asset_embeddings/migration.sql @@ -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)