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: fix CREATE TABLE LIKE with implicit pk #82555

Merged
merged 1 commit into from
Jun 9, 2022

Conversation

jasonmchan
Copy link
Contributor

@jasonmchan jasonmchan commented Jun 7, 2022

Previously, CREATE TABLE LIKE copied implicitly created columns (e.g.
for the rowid default primary key and hash sharded index). Defaults for
some of these columns were not properly copied over in some cases,
causing unexpected constraint violations to surface.

This commit fixes this by skipping copying such columns; instead, they
will be freshly created. Followup work is needed for REGIONAL BY ROW.

Fixes #82401

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@jasonmchan jasonmchan marked this pull request as ready for review June 7, 2022 21:52
@jasonmchan jasonmchan requested review from a team and ajwerner June 7, 2022 21:52
Copy link
Contributor

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

@knz
Copy link
Contributor

knz commented Jun 8, 2022

That solution is not sufficient. See my additional comment in #82401.

@jasonmchan jasonmchan force-pushed the create-table-like branch from 4067171 to 2cd587f Compare June 8, 2022 23:32
Copy link
Contributor

@chengxiong-ruan chengxiong-ruan 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 (and 1 stale) (waiting on @ajwerner and @jasonmchan)


pkg/sql/create_table.go line 2894 at r2 (raw file):

		return false, err
	}
	if td.IsShardColumn(col) {

Could you also add logic tests where the source table has hash sharded index and expression index?

@chengxiong-ruan
Copy link
Contributor

pkg/sql/create_table.go line 2894 at r2 (raw file):

Previously, chengxiong-ruan (Chengxiong Ruan) wrote…

Could you also add logic tests where the source table has hash sharded index and expression index?

oops, there is already test coverage for hash sharded index.

@jasonmchan
Copy link
Contributor Author

I'm going to omit a fix for REGIONAL BY ROW because #82672 causes problems with this solution. Will put up a new revision for the broken CI tests.

Previously, `CREATE TABLE LIKE` copied implicitly created columns (e.g.
for the rowid default primary key and hash sharded index). Defaults for
some of these columns were not properly copied over in some cases,
causing unexpected constraint violations to surface.

This commit fixes this by skipping copying such columns; instead, they
will be freshly created. Followup work is needed for REGIONAL BY ROW.

Fixes cockroachdb#82401

Release note: None
@jasonmchan jasonmchan force-pushed the create-table-like branch from 2cd587f to 19ce4ec Compare June 9, 2022 16:19
Copy link
Contributor

@chengxiong-ruan chengxiong-ruan left a comment

Choose a reason for hiding this comment

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

:lgtm:

I'd suggest adding a test case for expression index like `INDEX idx_expr (a + 2)` which would create a hidden virtual column which can be seen by selecting from the `crdb_internal.table_columns` table. I think this is working with PR but up to you to add it or not :)

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @ajwerner and @jasonmchan)

@jasonmchan
Copy link
Contributor Author

TFTR! I'm leaving out the expression index test for now because this PR doesn't change how they are handled.

bors r+

@craig
Copy link
Contributor

craig bot commented Jun 9, 2022

Build succeeded:

@craig craig bot merged commit 7b88642 into cockroachdb:master Jun 9, 2022
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: UX problem (maybe bug) in CREATE TABLE LIKE when the source table has an implicit PK
4 participants