Skip to content

opt: clean up FK ON UPDATE CASCADE code and opt trees#72466

Merged
craig[bot] merged 2 commits intocockroachdb:masterfrom
mgartner:fk-column-cleanup
Nov 8, 2021
Merged

opt: clean up FK ON UPDATE CASCADE code and opt trees#72466
craig[bot] merged 2 commits intocockroachdb:masterfrom
mgartner:fk-column-cleanup

Conversation

@mgartner
Copy link
Copy Markdown
Contributor

@mgartner mgartner commented Nov 4, 2021

opt: make FK ON UPDATE CASCADE input columns anonymous

This commit anonymizes the columns in the input of a foreign key
ON UPDATE CASCADE expression. This is safe because these columns can
only be referenced by other expressions if they are update columns, and
in that case, mutationBuilder.addUpdateCascade will give them a
distinct name in the scope it produces. This change allows a special
case added in #57153 to be removed, without failing the regression test.

Release note: None

opt: use more accurate FK ON UPDATE column metadata names

Columns produced by the WithScan expression in a foreign key ON UPDATE
CASCADE now have metadata names based on the column names of the child
table, rather than the parent table. This more accurately describes the
columns in the cascade plan because the plan is concerned with the child
table, not the parent. Metadata names are only used in opt expression
trees, so this is purely an aesthetic change, not a semantic one.

Release note: None

@mgartner mgartner requested review from a team, RaduBerinde and nehageorge November 4, 2021 21:56
@mgartner mgartner requested a review from a team as a code owner November 4, 2021 21:56
@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.

Nice cleanup! :lgtm:

Reviewed 1 of 2 files at r1, 4 of 4 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @mgartner and @nehageorge)


pkg/sql/opt/optbuilder/fk_cascade.go, line 875 at r1 (raw file):

	// we make them anonymous here. This prevents column name ambiguity in
	// outScope. There is no need to attach a metadata name here because these
	// columns have already been added to the metadata with a name above in the

supernit: in the calls to md.AddColumn above.

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.

nit: the PR title says "CASECADE"

Reviewed 2 of 2 files at r1, 1 of 4 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @mgartner and @nehageorge)

@mgartner mgartner changed the title opt: clean up FK ON UPDATE CASECADE code and opt trees opt: clean up FK ON UPDATE CASCADE code and opt trees Nov 8, 2021
Copy link
Copy Markdown
Contributor Author

@mgartner mgartner left a comment

Choose a reason for hiding this comment

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

nit: the PR title says "CASECADE"

Fixed.

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


pkg/sql/opt/optbuilder/fk_cascade.go, line 875 at r1 (raw file):

Previously, RaduBerinde wrote…

supernit: in the calls to md.AddColumn above.

Done.

Copy link
Copy Markdown

@nehageorge nehageorge left a comment

Choose a reason for hiding this comment

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

Cool, nice work! :lgtm:

Reviewed 1 of 2 files at r1, 4 of 4 files at r3, 4 of 4 files at r4, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @mgartner)

This commit anonymizes the columns in the input of a foreign key
ON UPDATE CASCADE expression. This is safe because these columns can
only be referenced by other expressions if they are update columns, and
in that case, `mutationBuilder.addUpdateCascade` will give them a
distinct name in the scope it produces. This change allows a special
case added in cockroachdb#57153 to be removed, without failing the regression test.

Release note: None
Columns produced by the WithScan expression in a foreign key ON UPDATE
CASCADE now have metadata names based on the column names of the child
table, rather than the parent table. This more accurately describes the
columns in the cascade plan because the plan is concerned with the child
table, not the parent. Metadata names are only used in opt expression
trees, so this is purely an aesthetic change, not a semantic one.

Release note: None
@mgartner
Copy link
Copy Markdown
Contributor Author

mgartner commented Nov 8, 2021

TFTRs!

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Nov 8, 2021

This PR was included in a batch that was canceled, it will be automatically retried

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Nov 8, 2021

Build succeeded:

@craig craig bot merged commit fdee50b into cockroachdb:master Nov 8, 2021
@mgartner mgartner deleted the fk-column-cleanup branch November 8, 2021 19:26
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.

5 participants