-
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: name PRIMARY KEY constraints (table_name)_pkey by default #70604
Conversation
fe43fff
to
a99e52c
Compare
Nice! Just wanted to check when you were thinking of merging this? Would it be onerous to wait until we tag a 21.2 RC? We (bulk at least) are trying to avoid unnecessary refactor churn in our packages until the RC is ready, just in case we discover a last-minute severe and release-blocking issue that requires an urgent fix, so that that fix doesn't risk being delayed by unclean backports. |
this can wait (but oh god the pain of rebasing) |
a99e52c
to
4d11190
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.
This all seems fine to me, the only comment I have pertains to maintaining the legacy naming of the primary index of the system tables.
Caveat: I haven't looked at the slew of changes in the expected test output definitions but then I doubt anyone ever will.
As far as I'm concerned this is a welcome change, I'm just curious as to what motivates it, as I see no linked issue anywhere. Do I guess correctly that naming them all "primary" was causing problems when importing mysql dumps?
// PrimaryKeyIndexName is the name of the index for the primary key. | ||
PrimaryKeyIndexName = "primary" | ||
// LegacyPrimaryKeyIndexName is the pre 22.1 default PRIMARY KEY index name. | ||
LegacyPrimaryKeyIndexName = "primary" |
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.
Why is it necessary to keep the old LegacyPrimaryKeyIndexName
name in the system schema? I'd be surprised if the primary index of any system table is ever referred to by name anywhere. In any case, it seems like you could quite easily add a tenant migration which runs a bunch of ALTER INDEX IF EXISTS system.???@primary RENAME TO ???_pkey
statements. Perhaps I'm missing something.
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.
I'd hate to run that migration! Two issues top of my head:
- Easy to miss a table
- In particular, the hardcoded descriptors in code and sql schema have to be kept in sync as well (from what I can tell). That will be challenging in your example.
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.
It's not that bad, I don't think. There's no need to version-gate the system table schemas in systemschema
as these are used for bootstrapping new clusters, changes in there are supposed to be backward compatible. In this case changing the name isn't backward compatible but if we never refer to the primary index of a system table by name anywhere then that doesn't matter and it's essentially a no-op. I suspect that we don't, ever. The migration would be in case if ever we chose to in the future.
Just to be clear I'm OK with just leaving their names be. I wanted to understand if there was a deeper motivation that I'd missed.
As for making sure not to miss tables, querying SHOW TABLES FROM system
and iterating over the results should take care of that.
This was motivated by trying to get the https://www.prisma.io/ test suite passing against CRDB |
Soon, we will no longer have `@primary` as the PRIMARY KEY lookup path. To prepare for the eventuality TPC-C may be used on an older or newer version of cockroach, remove the `@primary` index hint. Release note: None
Note that legacy system tables retain their legacy PRIMARY name. Release note (sql change): Newly created tables now have `<table_name>_pkey` by default as their index/constraint name.
Broken up for ease of reviewing; this does a little bit more than the mechanical work. Release note: None
To match PostgreSQL, we should rename the PRIMARY KEY index name when importing MySQL dumps. Release note: None
4d11190
to
7bd3f75
Compare
… name Separated out from logic changes (previous commit), can squash before merging. Release note: None
7bd3f75
to
514dfd6
Compare
bors r=postamar |
Build failed: |
opt flake bors r=postamar |
Build failed: |
inf flake :\ bors r=postamar |
Build succeeded: |
We should update the optimizer test catalog to match. I'll put up a PR. |
This commit updates the test catalog to name primary keys in the form `<table_name>_pkey`. This makes primary index names consistent with the real catalog and Postgres. See cockroachdb#70604. Release note: None
This commit updates the test catalog to name primary keys in the form `<table_name>_pkey`. This makes primary index names consistent with the real catalog and Postgres. See cockroachdb#70604. Release note: None
71818: opt: make index names in test catalog consistent with real catalog r=mgartner a=mgartner #### opt: name primary indexes <table_name>_pkey in test catalog This commit updates the test catalog to name primary keys in the form `<table_name>_pkey`. This makes primary index names consistent with the real catalog and Postgres. See #70604. Release note: None #### opt: make secondary index names in test catalog consistent with real catalog This commit updates the test catalog to name secondary keys consistently with the real catalog and Postgres. Release note: None Co-authored-by: Marcus Gartner <[email protected]>
The rename can have important consequences: a user who is using a I propose that we add some code to continue to support |
if they re-use the schema that was dumped, it will have |
We have seen customers recreate their schema anew using their own tools/scripts. Deploying a fresh instance of their app on a test cluster is their first step to validate that their app still works with a new version.
My proposal is to match |
that will probs work for PKs, do we care about what happens to FKs? |
FKs don't matter as much, they can't be part of queries as hints. |
I'd be fine to add that fallback name resolution logic. So we aren't going to be changing anything about how it shows up in pg_catalog introspection tables, right? Let's get it tracked in a new github issue |
This change also adjusts how we respond to the case in which a table has no primary key. The previous SQL query was looking for a hardcoded "primary" index, but that behavior has changed in v22.1 (cockroachdb/cockroach#70604).
This change also adjusts how we respond to the case in which a table has no primary key. The previous SQL query was looking for a hardcoded "primary" index, but that behavior has changed in v22.1 (cockroachdb/cockroach#70604).
This change also adjusts how we respond to the case in which a table has no primary key. The previous SQL query was looking for a hardcoded "primary" index, but that behavior has changed in v22.1 (cockroachdb/cockroach#70604).
resolves #71087
See individual commits for details.
Split up to make reviewing "easier"; more complex changes are separate commits.