fix(migration): handle pipeline-incompatible statements in ExecBatch#5156
Open
wucm667 wants to merge 1 commit intosupabase:developfrom
Open
fix(migration): handle pipeline-incompatible statements in ExecBatch#5156wucm667 wants to merge 1 commit intosupabase:developfrom
wucm667 wants to merge 1 commit intosupabase:developfrom
Conversation
CREATE INDEX CONCURRENTLY, REINDEX CONCURRENTLY, and VACUUM cannot run inside a pgx pipeline (extended query protocol). When db reset encounters these statements, the batch fails with SQLSTATE 25001. Fix: detect pipeline-incompatible statements and execute them individually via conn.Exec (simple query protocol) while batching the rest normally. Fixes supabase#5139 Signed-off-by: wucm667 <stevenwucongmin@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5139
What type of PR is this?
What this PR does / why it is needed:
When running
supabase db reset, migrations containingCREATE INDEX CONCURRENTLYfail with SQLSTATE 25001 ("cannot be executed within a pipeline"). This is becauseExecBatchinpkg/migration/file.gosends all statements throughconn.PgConn().ExecBatch(), which uses PostgreSQL's extended query protocol pipeline — incompatible with CONCURRENTLY, VACUUM, REINDEX CONCURRENTLY, ALTER SYSTEM, and CLUSTER statements.The fix:
isPipelineIncompatible()to detect statements that cannot run in a pipelineExecBatchto flush the batch before these statements and execute them individually viaconn.Exec(simple query protocol), then resume batching for subsequent statementsTesting
Manual testing with a migration file containing
CREATE INDEX CONCURRENTLYconfirms the fix — the statement now executes successfully via simple protocol while other statements continue to benefit from pipelining.