-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Addressing over-eager constraint checking with delete indexes #15092
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
Merged
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
# Conflicts: # src/execution/operator/persistent/physical_update.cpp
taniabogatsch
commented
Dec 3, 2024
Mytherin
reviewed
Dec 4, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Looks great - this will resolve a lot of problems. Some comments from my side:
test/sql/index/art/constraints/test_art_concurrent_deletes.test
Outdated
Show resolved
Hide resolved
test/sql/index/art/constraints/test_art_concurrent_updates.test
Outdated
Show resolved
Hide resolved
test/sql/index/art/constraints/test_art_concurrent_upserts.test
Outdated
Show resolved
Hide resolved
test/sql/index/art/constraints/test_art_concurrent_upserts.test
Outdated
Show resolved
Hide resolved
test/sql/index/art/constraints/test_art_concurrent_upserts.test
Outdated
Show resolved
Hide resolved
# Conflicts: # .github/patches/extensions/vss/hnsw.patch
Extension CI passing 🙌 |
Thanks! |
This was referenced Dec 13, 2024
when will the next release be? |
Release is penciled in for mid-january: https://duckdb.org/docs/dev/release_calendar#upcoming-releases |
krlmlr
added a commit
to duckdb/duckdb-r
that referenced
this pull request
Dec 27, 2024
Addressing over-eager constraint checking with delete indexes (duckdb/duckdb#15092) Fix update_extensions_ci test (duckdb/duckdb#15310) Move away from upload-artifacts@v3 / download-artifacts@v3 (duckdb/duckdb#15309)
github-actions bot
pushed a commit
to duckdb/duckdb-r
that referenced
this pull request
Dec 29, 2024
Addressing over-eager constraint checking with delete indexes (duckdb/duckdb#15092) Fix update_extensions_ci test (duckdb/duckdb#15310) Move away from upload-artifacts@v3 / download-artifacts@v3 (duckdb/duckdb#15309)
github-actions bot
added a commit
to duckdb/duckdb-r
that referenced
this pull request
Dec 29, 2024
Addressing over-eager constraint checking with delete indexes (duckdb/duckdb#15092) Fix update_extensions_ci test (duckdb/duckdb#15310) Move away from upload-artifacts@v3 / download-artifacts@v3 (duckdb/duckdb#15309) Co-authored-by: krlmlr <krlmlr@users.noreply.github.com>
2 tasks
2 tasks
2 tasks
2 tasks
17 tasks
Mytherin
added a commit
that referenced
this pull request
Jul 10, 2025
#18194) ### Overview #15092 made it possible for ART `PRIMARY/UNIQUE` indexes to have at most two row IDs per (unique) leaf. Currently, the conflict manager (and `ART::VerifyLeaf`) still work with the assumption that there can never be more than one row ID per conflict hit. Since this assumption no longer holds, in some cases, we now have to register conflict hits for up to two row IDs. Related issue: duckdblabs/duckdb-internal#4924. Later in the execution, we need to understand which of the two possible row IDs is visible to the transaction (and the conflict manager). As far as I can tell, this mostly kept working because we use a `vector` for row ID scanning, which is order-preserving, and newer row IDs (more likely the ones visible to the current transaction) overwrote older row IDs. ### Changes in this PR - Exposed `CanFetch` to `DataTable`, `LocalStorage`, `RowGroupCollection` to determine whether a row ID is visible to a transaction/in the local storage, or not. - The conflict manager now has the capacity to register a secondary hit for a conflict. Also, I've refactored basically the entire conflict manager. That refactoring includes removing the `ManagedSelection`, and a lot of code paths. I think the number of lines only went up because I've added the `CanFetch` stuff and because I've also added a lot of comments and some formatting). 😅 This PR is a minor follow-up to #18015 and next up is turning the row ids into an unordered set instead of a vector.
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.
This PR introduces a new component to duckdb's transaction-local storage: delete indexes.
Let's look at the following snippet:
INSERT OR REPLACE
fails with a constraint exception. We do not support out-of-place table updates withUNIQUE
constraints, such as a primary key. An out-of-place update turns anUPDATE
intoDELETE + UPDATE
.The longstanding limitation of duckdb's over-eager constraint-checking causing this behavior is documented here: https://duckdb.org/docs/sql/indexes.html#over-eager-unique-constraint-checking.
To solve this issue, this PR introduces transaction-local delete indexes. When attempting to remove any data from the global index, we now store this change in the local index. We can not remove the data yet, as other transactions may still depend on it. Subsequent operations within the same local context are then aware of the deletion of that entry. Thus, before throwing a constraint violation, they double-check if the value is still there by performing a lookup against the local delete index.
There are still some limitations to this approach. I.e., concurrent changes of the same key will likely cause a write-write conflict but will no longer cause a constraint violation.