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

opt: add update checks for unique constraints #57930

Merged
merged 1 commit into from
Dec 17, 2020

Conversation

rytaft
Copy link
Collaborator

@rytaft rytaft commented Dec 15, 2020

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 #41535

Release note: None

@rytaft rytaft requested review from mgartner, RaduBerinde and a team December 15, 2020 03:04
@rytaft rytaft requested a review from a team as a code owner December 15, 2020 03:04
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: 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
Copy link
Collaborator Author

@rytaft rytaft left a comment

Choose a reason for hiding this comment

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

TFTR!

Reviewable status: :shipit: 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.

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: 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

Copy link
Collaborator Author

@rytaft rytaft left a comment

Choose a reason for hiding this comment

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

TFTR!

bors r+

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

@craig
Copy link
Contributor

craig bot commented Dec 17, 2020

Build succeeded:

@craig craig bot merged commit eda9189 into cockroachdb:master Dec 17, 2020
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.

3 participants