-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: pg mandates multi-stmt batches to execute as single txn #44803
Comments
I think we simply didn't know about this, since it appears to only be documented starting in pg 11. But I've verified down to pg 9.4, and their behavior seems to have stayed consistent. |
I agree with "we didn't know" but it seems egregious given the amount of time we routinely spend comparing behaviors. I am very surprised we didn't notice earlier. The reason, I think, is that when an error happens the messages sent back and forth are the same in both cases. So there's no visual hint. We probably never checked the side effects in the database. My argument at the top remains though. If client apps rely on transactionality, we're failing them big time now, and in no way for them to notice until their data is in a bad state. |
Leaving some notes in here about how Postgres implements this. In the
We should be able to do something similar in our own state machine. NB: I skipped over some edge cases above (which are also described in the Postgres docs). For example, if a |
76834: sql: execute batch statements in an implicit transaction r=otan a=rafiss fixes #44803 relates to #76490 Release justification: high value bug fix to existing functionality ### *: prepare tests for batch stmt txn change This commit will make the next one easier to review. ### sql: execute batch statements in an implicit transaction Release note (bug fix): Previously statements that arrived in a batch during the simple query protocol would all execute in their own implicit transactions. Now, we match the Postgres wire protocol, so all these statements share the same implicit transaction. If a BEGIN is included in a statement batch, then the existing implicit transaction is upgraded to an explicit transaction. ### sql: add session var for old implicit txn behavior Release note (sql change): The enable_implicit_transaction_for_batch_statements session variable was added. It defaults to true. When it is true, multiple statements in a single query (a.k.a. a "batch statement") will all be run in the same implicit transaction, which matches the Postgres wire protocol. This setting is provided for users who want to preserve the behavior of CockroachDB versions v21.2 and earlier. 77780: roachtest: update 22.1 version map to v21.2.7 r=celiala a=Azhng Release note: None Release justification: non-production code change. 77781: cloud: bump orchestrator to v21.2.7 r=celiala a=Azhng Release note: None Release justification: non-production code change. 77803: kvserverbase: move MaxCommandSizeDefault out of kvserver r=ajwerner a=ajwerner ``` $ bazel query "somepath(//pkg/sql, //pkg/kv/kvserver)" INFO: Empty results Loading: 0 packages loaded ``` Release justification: non-production code changes Release note: None Co-authored-by: Rafi Shamim <[email protected]> Co-authored-by: Azhng <[email protected]> Co-authored-by: Andrew Werner <[email protected]>
As per pg's docs: https://www.postgresql.org/docs/12/protocol-flow.html#PROTOCOL-FLOW-MULTI-STATEMENT
If a pg client that expects this behavior is ran against crdb, this will yield inconsistent data without any clear signal to the client.
(The current crdb behavior is a plain ACID violation when viewed through the lens of pg semantics.)
Epic CRDB-8948
Jira issue: CRDB-5201
The text was updated successfully, but these errors were encountered: