-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: UPSERT execution incorrectly assumes partial index PUT and DEL columns will be last columns in mutation input #61414
Comments
This appears related to #57097. execbuilder might add addition columns to mutation inputs: cockroach/pkg/sql/opt/exec/execbuilder/mutation.go Lines 47 to 57 in c9fb63a
|
This commit adds tests for implicitly partitioned partial unique indexes. It also fixes a bug that caused `UPSERT`s to fail on a regional-by-row table with a partial unique index. The upsert execution code previously assumed that partial index PUT and DEL columns are the last columns in the mutation's input. This may not be the case when FK or unique checks require additional columns. The execution code no longer makes this assumption. There is no regression test added for this case because it was caught by existing tests in `pkg/ccl/logictestccl` once partial unique indexes were added to tables. Fixes cockroachdb#61414 Release justification: This is a low-risk bug fix for multi-region features. Release note: None
This commit fixes a bug in UPSERT execution that was caused by the incorrect assumption that there are never columns following the partial index PUT and DEL columns in the mutation's input. I was unable to reproduce this bug for INSERTs or DELETEs. However, I updated the execution code for both out of caution. The logic for both no longer makes the same assumption that partial index PUT and DEL columns will be the last columns in the input. This commit also adds tests for implicitly partitioned partial unique indexes. Fixes cockroachdb#61414 Release justification: This is a low-risk bug fix necessary for new multi-region features. Release note: None
I think we just ran into this on a production cluster. v20.2.5 on ubuntu 20.04 The partial index was newly added. The column indexed was newly added, a timestamptz with default now(). The condition was on an existing enum. Not sure if any of that matters. Any chance if you can tell me if you think this is the same issue, else I'll open a new one. Logs:
In the application, this is what we saw:
|
It looks like it could be the same issue. Are you able to share the schema and statement that produce the error so that I can confirm? If not, is there a simplified reproduction you can share? |
Hope it's ok anonymized (and hope i mapped this properly)
With the statement that caused it:
|
This commit fixes a bug in UPSERT execution that was caused by the incorrect assumption that there are never columns following the partial index PUT and DEL columns in the mutation's input. I was unable to reproduce this bug for INSERTs or DELETEs. However, I updated the execution code for both out of caution. The logic for both no longer makes the same assumption that partial index PUT and DEL columns will be the last columns in the input. Fixes cockroachdb#61414 Release justification: This is a low-risk fix for a bug causing UPSERT statements to err when executed on tables with partial indexes. Release note (bug fix): A bug which caused UPSERT and INSERT..ON CONFLICT..DO UPDATE statements to fail on tables with both partial indexes and foreign key references has been fixed. This bug has been present since version 20.2.0.
@karlseguin Thanks for catching this and sharing! I've confirmed that you're running into the same bug. #61416 will fix this issue and I'll backport the fix so that it will be included in an upcoming 20.2.x release, hopefully the next one, 20.2.6. |
This commit fixes a bug in UPSERT execution that was caused by the incorrect assumption that there are never columns following the partial index PUT and DEL columns in the mutation's input. I was unable to reproduce this bug for INSERTs or DELETEs. However, I updated the execution code for both out of caution. The logic for both no longer makes the same assumption that partial index PUT and DEL columns will be the last columns in the input. Fixes cockroachdb#61414 Release justification: This is a low-risk fix for a bug causing UPSERT statements to err when executed on tables with partial indexes. Release note (bug fix): A bug which caused UPSERT and INSERT..ON CONFLICT..DO UPDATE statements to fail on tables with both partial indexes and foreign key references has been fixed. This bug has been present since version 20.2.0.
61416: sql: fix UPSERT with columns after partial index PUT and DEL columns r=mgartner a=mgartner #### sql: fix UPSERT with columns after partial index PUT and DEL columns This commit fixes a bug in UPSERT execution that was caused by the incorrect assumption that there are never columns following the partial index PUT and DEL columns in the mutation's input. I was unable to reproduce this bug for INSERTs or DELETEs. However, I updated the execution code for both out of caution. The logic for both no longer makes the same assumption that partial index PUT and DEL columns will be the last columns in the input. Fixes #61414 Release justification: This is a low-risk fix for a bug causing UPSERT statements to err when executed on tables with partial indexes. Release note (bug fix): A bug which caused UPSERT and INSERT..ON CONFLICT..DO UPDATE statements to fail on tables with both partial indexes and foreign key references has been fixed. This bug has been present since version 20.2.0. #### ccl: add tests for implicitly partitioned partial unqiue indexes Release justification: This is a test-only change. Release note: None Co-authored-by: Marcus Gartner <[email protected]>
To Reproduce
Stacktrace
The text was updated successfully, but these errors were encountered: