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

sql: ban renaming table to a new database unless both schemas are public #55722

Merged
merged 1 commit into from
Oct 20, 2020

Conversation

thoszhang
Copy link
Contributor

@thoszhang thoszhang commented Oct 20, 2020

Previously we would seemingly allow renaming tables to a new database
with arbitrary source and target schemas without ever actually
reassigning the schema ID. This could lead to a corrupted descriptor
with an invalid schema ID for the database. This PR fixes the
implementation to return an error when renaming a table to a different
database unless both the source and target schemas are public.

Fixes #55710.

Release note (bug fix): Previously, changing the parent database and
schema of a table using RENAME was seemingly permitted but would lead
to corruption of the table metadata. Now an error is returned when
attempting to rename a table to a different database except in the case
where both the source and target schemas are the public schema in each
database, which continues to be supported.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@ajwerner ajwerner 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 (waiting on @ajwerner and @lucy-zhang)


pkg/sql/rename_table.go, line 180 at r1 (raw file):

	// Note that we don't have to modify the parent schema ID because the source
	// and target schemas must both be the public schema.

Where is this enforced? The above check doesn't say anything about the parentSchemaID if the catalogs are the same.

Previously we would seemingly allow renaming tables to a new database
with arbitrary source and target schemas without ever actually
reassigning the schema ID. This could lead to a corrupted descriptor
with an invalid schema ID for the database. This PR fixes the
implementation to return an error when renaming a table to a different
database unless both the source and target schemas are `public`.

Release note (bug fix): Previously, changing the parent database and
schema of a table using `RENAME` was seemingly permitted but would lead
to corruption of the table metadata. Now an error is returned when
attempting to rename a table to a different database except in the case
where both the source and target schemas are the `public` schema in each
database, which continues to be supported.
@thoszhang thoszhang force-pushed the disallow-rename-across-database branch from 8bcada7 to a978b55 Compare October 20, 2020 01:12
Copy link
Contributor Author

@thoszhang thoszhang 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 (waiting on @ajwerner)


pkg/sql/rename_table.go, line 180 at r1 (raw file):

Previously, ajwerner wrote…
	// Note that we don't have to modify the parent schema ID because the source
	// and target schemas must both be the public schema.

Where is this enforced? The above check doesn't say anything about the parentSchemaID if the catalogs are the same.

I forgot about the other case while I was writing this comment. But it remains true that we never modify the schema ID because we don't allow changing the table's parent schema within the same database, either (which is checked immediately above the check added in this PR).

Copy link
Contributor

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


pkg/sql/rename_table.go, line 180 at r1 (raw file):

Previously, lucy-zhang (Lucy Zhang) wrote…

I forgot about the other case while I was writing this comment. But it remains true that we never modify the schema ID because we don't allow changing the table's parent schema within the same database, either (which is checked immediately above the check added in this PR).

I see it now, needed to expand up. Thanks!

@thoszhang
Copy link
Contributor Author

TFTR

bors r+

@craig
Copy link
Contributor

craig bot commented Oct 20, 2020

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Oct 20, 2020

Build succeeded:

@craig craig bot merged commit 65bf9e6 into cockroachdb:master Oct 20, 2020
@thoszhang thoszhang deleted the disallow-rename-across-database branch October 20, 2020 16:34
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: the rename of a table to a different database and schema causes unexpected behaviour
3 participants