-
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
opt: add update checks for unique constraints #57930
Conversation
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.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @mgartner, @RaduBerinde, and @rytaft)
pkg/sql/opt/optbuilder/mutation_builder_unique.go, line 42 at r1 (raw file):
// a check. if mb.tab.Unique(i).WithoutIndex() && h.init(mb, i) { mb.uniqueChecks = append(mb.uniqueChecks, h.buildInsertionCheck())
[nit] maybe a comment why the insertion check just works
pkg/sql/opt/optbuilder/mutation_builder_unique.go, line 48 at r1 (raw file):
} func (mb *mutationBuilder) buildUniqueChecksForUpdate() {
[nit] worth adding a comment, and mention that this builds checks for "unique without index" constraints
pkg/sql/opt/optbuilder/mutation_builder_unique.go, line 75 at r1 (raw file):
// UNIQUE WITHOUT INDEX constraints on the table. Also returns the ordinal of // the first matching constraint if one exists. func (mb *mutationBuilder) hasUniqueWithoutIndexConstraints() (ord int, ok bool) {
I don't think returning the ordinal is worthwhile here. It's a minuscule optimization, this stuff pales in comparison with the total cost of the actual uniqueness check.
pkg/sql/opt/optbuilder/mutation_builder_unique.go, line 77 at r1 (raw file):
func (mb *mutationBuilder) hasUniqueWithoutIndexConstraints() (ord int, ok bool) { uniqueCount := mb.tab.UniqueCount() if uniqueCount == 0 {
[nit] We shouldn't need this special code path
This commit adds checks for unique constraints when planning updates in the optimizer. This does not yet impact anything outside of the optimizer tests, since UNIQUE WITHOUT INDEX is still not fully supported outside of the optimizer test catalog. Informs cockroachdb#41535 Release note: None
2eddd70
to
20b524a
Compare
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.
TFTR!
Reviewable status: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @mgartner and @RaduBerinde)
pkg/sql/opt/optbuilder/mutation_builder_unique.go, line 42 at r1 (raw file):
Previously, RaduBerinde wrote…
[nit] maybe a comment why the insertion check just works
Did you mean to add this to the update code below? I added a comment there (let me know if that's not what you had in mind).
pkg/sql/opt/optbuilder/mutation_builder_unique.go, line 48 at r1 (raw file):
Previously, RaduBerinde wrote…
[nit] worth adding a comment, and mention that this builds checks for "unique without index" constraints
Done.
pkg/sql/opt/optbuilder/mutation_builder_unique.go, line 75 at r1 (raw file):
Previously, RaduBerinde wrote…
I don't think returning the ordinal is worthwhile here. It's a minuscule optimization, this stuff pales in comparison with the total cost of the actual uniqueness check.
Done.
pkg/sql/opt/optbuilder/mutation_builder_unique.go, line 77 at r1 (raw file):
Previously, RaduBerinde wrote…
[nit] We shouldn't need this special code path
Done.
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.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @mgartner)
pkg/sql/opt/optbuilder/mutation_builder_unique.go, line 42 at r1 (raw file):
Previously, rytaft (Rebecca Taft) wrote…
Did you mean to add this to the update code below? I added a comment there (let me know if that's not what you had in mind).
Yeah, looks good, I pointed to the wrong section
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.
Build succeeded: |
This commit adds checks for unique constraints when planning updates
in the optimizer. This does not yet impact anything outside of the optimizer
tests, since
UNIQUE WITHOUT INDEX
is still not fully supported outside of theoptimizer test catalog.
Informs #41535
Release note: None