Skip to content

sql: fix bug with multi-statement implicit txn schema changes and Bind#92300

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
ajwerner:ajwerner/fix-implicit-txn-schema-changes
Nov 22, 2022
Merged

sql: fix bug with multi-statement implicit txn schema changes and Bind#92300
craig[bot] merged 1 commit intocockroachdb:masterfrom
ajwerner:ajwerner/fix-implicit-txn-schema-changes

Conversation

@ajwerner
Copy link
Copy Markdown
Contributor

For legacy reasons, we were resetting the descriptor collection state in Bind if we thought we were not in a transaction. Since #76792, we're always in a transaction. You might think that'd mean that the logic would not run. Sadly, for other still unclear reasons, when in an implicit transaction (*connExecutor).getTransactionState() returns NoTxnStateStr. The end result was that we'd erroneously reset our descriptor state in the middle of a multi- statement implicit transaction if bind was invoked.

Fixes #82921

Release note (bug fix): Fixed a bug which could lead to errors when running multiple schema change statements in a single command using a driver that uses the extended pgwire protocol internally (Npgsql in .Net as an example). These errors would have the form "attempted to update job for mutation 2, but job already exists with mutation 1".

For legacy reasons, we were resetting the descriptor collection state in Bind
if we thought we were not in a transaction. Since cockroachdb#76792, we're always in a
transaction. You might think that'd mean that the logic would not run. Sadly,
for other still unclear reasons, when in an implicit transaction
`(*connExecutor).getTransactionState()` returns `NoTxnStateStr`. The end result
was that we'd erroneously reset our descriptor state in the middle of a multi-
statement implicit transaction if bind was invoked.

Fixes cockroachdb#82921

Release note (bug fix): Fixed a bug which could lead to errors when running
multiple schema change statements in a single command using a driver that
uses the extended pgwire protocol internally (Npgsql in .Net as an example).
These errors would have the form "attempted to update job for mutation 2, but
job already exists with mutation 1".
@ajwerner ajwerner requested a review from a team November 22, 2022 00:32
@ajwerner ajwerner requested a review from a team as a code owner November 22, 2022 00:32
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@ajwerner ajwerner requested a review from rafiss November 22, 2022 00:33
Copy link
Copy Markdown
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow nice find

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner)


-- commits line 7 at r1:
my educated guess for the weird getTransactionState() behavior is that it's purely to implement show transaction_status. but it was a mistake to implement show transaction_status that way; maybe it should use an observer statement instead

@ajwerner
Copy link
Copy Markdown
Contributor Author

TFTR!

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Nov 22, 2022

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v22.1.1: sql: alter table attempted to update job for mutation 2, but job already exists with mutation 1

3 participants