cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
30.19k stars 3.82k forks source link

sql: deprecate cross-database references between catalog elements #55791

Open thoszhang opened 4 years ago

thoszhang commented 4 years ago

As part of moving toward a more Postgres-compatible world where databases are isolated from each other, we're going to stop supporting references between catalog elements (i.e., tables, types, and schemas) in different databases. The following kinds of references will only be permitted for tables/types in the same database:

In 20.2 we introduced cluster settings to disallow creating new cross-database references for foreign keys, sequence owners, and views by default (#54126).

The proposal is that in 21.1 we'll always disallow the creation of new cross-database references, and have a mechanism to prevent upgrading to 21.2 until users have removed all their existing cross-database references by either moving tables or removing the cross-database schema elements. Specifically, we'd use the long-running migration framework, and have a potentially very long running migration that continually checks whether users have finished removing their cross-database references, and only completes successfully upon confirming that they have.

Other concerns:

Epic: CRDB-1519

Jira issue: CRDB-3631

thoszhang commented 4 years ago

The current thinking is that we'll start the migration for #55793 automatically after the user has set some flag (via cluster setting) and implement all this as one long-running migration.

ajwerner commented 4 years ago

One important consideration for this task is the interaction with RESTORE of a backup which includes such references. What is the user story? Do we reject them?

cc @mwang1026

mwang1026 commented 4 years ago

Thanks for the ping. Let me bring this to the team to discuss. My initial thought is to invalidate them with some sort of warning after the fact, but want to talk through other options too (e.g. invalidation is an option, otherwise error if we find them).

postamar commented 2 years ago

@ajwerner should we add a cluster upgrade precondition for 23.1 which checks that the cross-database cluster setting is disabled, to consider this done?

ajwerner commented 2 years ago

Steps:

1) Add a migration and pre-condition to make sure these things don't exist