-
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
sql: ban renaming table to a new database unless both schemas are public #55722
sql: ban renaming table to a new database unless both schemas are public #55722
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! 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.
8bcada7
to
a978b55
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.
Reviewable status: 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).
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
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!
TFTR bors r+ |
Build failed (retrying...): |
Build succeeded: |
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 leadto 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 eachdatabase, which continues to be supported.