Skip to content
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: fix bug with multi-statement implicit txn schema changes and Bind #92300

Merged

Conversation

ajwerner
Copy link
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
Member

This change is Reviewable

@ajwerner ajwerner requested a review from rafiss November 22, 2022 00:33
Copy link
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
Contributor Author

TFTR!

bors r+

@craig
Copy link
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