Skip to content

opt: fix buggy EliminateUpsertDistinctOnNoColumns rule#46408

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
andy-kimball:donothing
Mar 24, 2020
Merged

opt: fix buggy EliminateUpsertDistinctOnNoColumns rule#46408
craig[bot] merged 1 commit intocockroachdb:masterfrom
andy-kimball:donothing

Conversation

@andy-kimball
Copy link
Copy Markdown
Contributor

The fix for #37880 added a new ErrorOnDup field to the UpsertDistinctOn
operator. However, the EliminateErrorDistinctNoColumns rule wasn't changed
to respect this flag, and so there's still a case where ON CONFLICT DO
NOTHING returns an error.

This commit eliminates the error by separating out the ErrorOnDup=True case
from the EliminateErrorDistinctNoColumns rule (which raises an error) and
adding it instead to the EliminateDistinctNoColumns rule (which does not
raise an error).

Fixes #46395

Release justification: Bug fixes and low-risk updates to new functionality.
This was always an error, so it's low-risk to make it a non-error.

Release note: None

@andy-kimball andy-kimball requested a review from a team as a code owner March 22, 2020 04:54
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
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 @andy-kimball and @RaduBerinde)


pkg/sql/opt/norm/rules/groupby.opt, line 165 at r1 (raw file):


# EliminateErrorDistinctNoColumns is similar to EliminateDistinctNoColumns,
# except that it will raise an error if there are no grouping columns and the

[nit] phrasing here is a bit confusing (the rule itself doesn't raise errors). Maybe "except Max1Row is used to raise an error if"

Copy link
Copy Markdown
Contributor Author

@andy-kimball andy-kimball left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale)


pkg/sql/opt/norm/rules/groupby.opt, line 165 at r1 (raw file):

Previously, RaduBerinde wrote…

[nit] phrasing here is a bit confusing (the rule itself doesn't raise errors). Maybe "except Max1Row is used to raise an error if"

Done.

Copy link
Copy Markdown
Collaborator

@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.

:lgtm:

Reviewed 4 of 5 files at r1, 1 of 1 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @andy-kimball)


pkg/sql/opt/norm/groupby.go, line 33 at r2 (raw file):

// RaiseErrorOnDup returns true if an UpsertDistinct operator raises an error
// when duplicate values are detected.
func (c *CustomFuncs) RaiseErrorOnDup(private *memo.GroupingPrivate) bool {

[nit] maybe change this to "RaisesErrorOnDup"? Currently sounds like this function will raise an error.

The fix for cockroachdb#37880 added a new ErrorOnDup field to the UpsertDistinctOn
operator. However, the EliminateErrorDistinctNoColumns rule wasn't changed
to respect this flag, and so there's still a case where ON CONFLICT DO
NOTHING returns an error.

This commit eliminates the error by separating out the ErrorOnDup=True case
from the EliminateErrorDistinctNoColumns rule (which raises an error) and
adding it instead to the EliminateDistinctNoColumns rule (which does not
raise an error).

Fixes cockroachdb#46395

Release justification: Bug fixes and low-risk updates to new functionality.
This was always an error, so it's low-risk to make it a non-error.

Release note: None
Copy link
Copy Markdown
Contributor Author

@andy-kimball andy-kimball left a comment

Choose a reason for hiding this comment

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

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


pkg/sql/opt/norm/groupby.go, line 33 at r2 (raw file):

Previously, rytaft (Rebecca Taft) wrote…

[nit] maybe change this to "RaisesErrorOnDup"? Currently sounds like this function will raise an error.

Done.

Copy link
Copy Markdown
Collaborator

@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.

Reviewed 2 of 2 files at r3.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 2 stale)

@andy-kimball
Copy link
Copy Markdown
Contributor Author

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 24, 2020

Build succeeded

@craig craig bot merged commit 21e6fa6 into cockroachdb:master Mar 24, 2020
@andy-kimball andy-kimball deleted the donothing branch March 24, 2020 02:05
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.

sql: INSERT ... DO NOTHING results in an error "UPSERT or INSERT...ON CONFLICT command cannot affect row a second time"

4 participants