Repository navigation
fix(postgres): re-parse unnamed statement when statement cache is disabled - #4555
Open
aloneangel45 wants to merge 1 commit into
Open
aloneangel45 wants to merge 1 commit into
aloneangel45 wants to merge 1 commit into
Conversation
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 #4554
Problem
In
sqlx-postgres/src/connection/executor.rs,prepare()assignsStatementId::UNNAMEDwhenever!persistent || !conn.inner.cache_statement.is_enabled()(e.g.,statement_cache_capacity(0)).When preparing a query whose return types trigger a simple catalog query in
resolve_statement_metadata(), PostgreSQL destroys the unnamed prepared statement. #4361 added a re-parse guard, but it checkedif !persistent && ran_catalog_queryrather thanid == StatementId::UNNAMED && ran_catalog_query. Withstatement_cache_capacity(0)and defaultpersistent = trueinside a transaction (where SQLSTATE26000cannot retry outsidecheck_stale_plan), subsequentBindfails withunnamed prepared statement does not exist.Fix
id == StatementId::UNNAMED && ran_catalog_queryinsqlx-postgres/src/connection/executor.rs.sqlx-postgresverifyingStatementId::UNNAMEDis re-parsed for bothstatement_cache_capacity(0)(persistent = true) andpersistent = false, while named statements are not unnecessarily re-parsed.test_issue_4554intests/postgres/postgres.rs.Verification
cargo fmt --all -- --check: passedcargo clippy -p sqlx-postgres --no-deps --lib --tests: clean on modified filescargo test -p sqlx-postgres --lib: 157 passed, 0 failedcargo test --no-run --test postgres --features postgres,runtime-tokio,tls-none,macros: compiled cleanly