-
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: support NOT VISIBLE in CREATE TABLE for user-defined hidden columns #58923
Conversation
Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. Before a member of our team reviews your PR, I have some potential action items for you:
I was unable to automatically find a reviewer. You can try CCing one of the following members:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
This happens to be a concept we're explicitly exploring right now in this RFC: #58440 |
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.
Thank you, this actually looks pretty good.
You will need a proper commit message however, that explains the work (motivation and approach).
Also the PR description needs to indicate the link to the motivating issue, e.g. "fixes #53428"
As well as a release note that outlines the user-facing changes.
For more information about how to write a proper commit message, head here: https://wiki.crdb.io/wiki/spaces/CRDB/pages/73072807/Git+Commit+Messages
Also this PR is missing unit tests. There needs to be some tests in sql/parser/parse_test.go
, and also some tests in pkg/sql/logictests
I invite you to take inspiration from my previous PR #26644 which also contains unit tests (you can take most of them over). I'd, of course, also appreciate a reference to that previous work in your commit message.
Reviewed 13 of 13 files at r1.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @Heoric)
pkg/sql/show_create.go, line 87 at r1 (raw file):
f.WriteString(" (") primaryKeyIsOnVisibleColumn := false // visibleCols := desc.VisibleColumns()
I don't understand this - why did you need to change it?
pkg/sql/parser/sql.y, line 1365 at r1 (raw file):
// // Column qualifiers: // [CONSTRAINT <constraintname>] {NULL | NOT NULL | VISIBLE | UNIQUE [WITHOUT INDEX] | PRIMARY KEY | CHECK (<expr>) | DEFAULT <expr>}
probably | [NOT] VISIBLE ...
here
pkg/sql/parser/sql.y, line 1901 at r1 (raw file):
} // ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT VISIBLE | ALTER opt_column column_name SET NOT VISIBLE
please add the corresponding tests in parse_test.go
thanks
pkg/sql/parser/sql.y, line 5655 at r1 (raw file):
// // Column qualifiers: // [CONSTRAINT <constraintname>] {NULL | NOT NULL | VISIBLE | NOT VISIBLE |UNIQUE [WITHOUT INDEX] | PRIMARY KEY | CHECK (<expr>) | DEFAULT <expr>}
make this | [NOT] VISIBLE | UNIQUE ...
pkg/sql/sem/tree/create.go, line 600 at r1 (raw file):
ctx.FormatNode(&node.Nullable.ConstraintName) } if node.Hidden {
Can you also update (node *ColumnTableDef) docRow()
accordingly in pretty.go, thanks.
pkg/sql/vtable/pg_catalog.go, line 21 at r1 (raw file):
const PGCatalogAm = ` CREATE TABLE pg_catalog.pg_am ( oid OID NOT VISIBLE,
This change, while welcome, belongs to a different commit/PR. Please split it away from the first commit, thanks.
I'd like to request that you split the |
Thank you for updating your pull request. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
1 similar comment
Thank you for updating your pull request. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
Thank you for updating your pull request. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
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.
Thanks for updating the PR.
@lucy-zhang what should we do regarding ALTER? Do we ask to remove the SQL parser support entirely, or should we keep the syntax but then report an unimplemented error during planning?
Reviewed 11 of 11 files at r2.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @Heoric)
pkg/sql/parser/parse_test.go, line 1452 at r2 (raw file):
{`ALTER TABLE a ALTER COLUMN b DROP NOT NULL`}, {`ALTER TABLE a ALTER COLUMN b DROP STORED`}, {`ALTER TABLE a ALTER COLUMN b SET VISIBLE`},
I think you can remove the ALTER tests here now.
pkg/sql/parser/sql.y, line 1346 at r2 (raw file):
// ALTER TABLE ... ALTER [COLUMN] <colname> DROP NOT NULL // ALTER TABLE ... ALTER [COLUMN] <colname> DROP STORED // ALTER TABLE ... ALTER [COLUMN] <colname> SET [NOT] VISIBLE
Since you are extracting the ALTER functionality into a different PR, you can remove this from this PR too.
pkg/sql/parser/sql.y, line 1901 at r2 (raw file):
} // ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT VISIBLE | ALTER opt_column column_name SET NOT VISIBLE
same here.
pkg/sql/sem/tree/alter_table.go, line 76 at r2 (raw file):
func (*AlterTableSetAudit) alterTableCmd() {} func (*AlterTableSetDefault) alterTableCmd() {} func (*AlterTableSetHidden) alterTableCmd() {}
same here
Should I just commit the |
Thank you for updating your pull request. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
Thank you for updating your pull request. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
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 think this looks good now.
Lucy do you want to take a look and merge this if you're satisfied?
Reviewed 3 of 5 files at r3, 2 of 2 files at r4.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @Heoric)
@Heoric sorry I forgot - you need to populate a commit message that explains the change, according to the instructions in the wiki (see my link above). Also you can squash the 3 commits together. |
Thank you for your advice and look forward to your review. @lucy-zhang |
Thank you very much for the review!
…------------------ 原始邮件 ------------------
发件人: "kena"<[email protected]>;
发送时间: 2021年1月21日(星期四) 晚上9:30
收件人: "cockroachdb/cockroach"<[email protected]>;
抄送: "奔跑"<[email protected]>; "Mention"<[email protected]>;
主题: Re: [cockroachdb/cockroach] [WIP] user-defined hidden columns (#58923)
@knz approved this pull request.
I think this looks good now.
Lucy do you want to take a look and merge this if you're satisfied?
Reviewed 3 of 5 files at r3, 2 of 2 files at r4.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @Heoric)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
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.
Reviewed 4 of 13 files at r1, 1 of 11 files at r2, 2 of 5 files at r3, 2 of 2 files at r4.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @Heoric)
pkg/sql/logictest/testdata/logic_test/hidden_columns, line 1 at r4 (raw file):
statement ok
Can you add logic tests for these interactions with DDL statements:
- dropping a hidden column
- renaming a hidden column
- adding an index on a hidden column
- adding a foreign key constraint on a hidden column
- adding a foreign key constraint that references a hidden column
ALTER PRIMARY KEY
on a primary key with hidden columns
I expect these to all work, but it'll be good to make sure.
Thank you for updating your pull request. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
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.
Reviewed 1 of 5 files at r3, 1 of 1 files at r5.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @Heoric)
pkg/sql/logictest/testdata/logic_test/hidden_columns, line 70 at r5 (raw file):
statement ok ALTER TABLE kv Drop COLUMN x;
nit: capitalize DROP
pkg/sql/logictest/testdata/logic_test/hidden_columns, line 75 at r5 (raw file):
SELECT x FROM kv;
nit: Only 1 newline between these cases
pkg/sql/logictest/testdata/logic_test/hidden_columns, line 82 at r5 (raw file):
statement ok CREATE TABLE t2(b INT NOT VISIBLE, c INT, d INT, PRIMARY KEY (d), FOREIGN KEY(b) REFERENCES t1(b));
Can you add some queries after all these schema changes to help make sure that the new descriptor states are usable?
pkg/sql/logictest/testdata/logic_test/hidden_columns, line 103 at r5 (raw file):
nit: Extra newlines at the end (the linter doesn't pick this up)
This has a error when I add a foreign key constraint that references a hidden column(including rowid)。
CREATE TABLE t3(a INT PRIMARY KEY);
CREATE TABLE t4(c INT);
CREATE TABLE t5(a INT);
ALTER TABLE t4 ADD FOREIGN KEY (rowid) REFERENCES t3 (a); -- success
ALTER TABLE t4 ADD FOREIGN KEY (c) REFERENCES t5 (rowid); -- error
CREATE TABLE t6(c INT, FOREIGN KEY(c) REFERENCES t5(rowid)); -- success |
@lucy-zhang this error surprises me too. What do you think? |
That error is coming from executing the internal query generated here: Line 152 in 3e2a4e7
I reproduced this on master and got the query from the logs:
Here it is cleaned up a bit:
This query produces the same error when issued from the sql console, so it's not a problem with the internal executor or anything. I'll ask around and probably file a separate issue, but I don't think that should block this PR. |
Thank you for updating your pull request. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
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.
Thanks, changes LGTM. Could you please squash your commits?
Reviewed 1 of 1 files at r6.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @Heoric)
Thank you for updating your pull request. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
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.
Ok this is looking good now, but the commit message is imperfect.
@Heoric I will take care of editing the commit message for you. Thank you for your change!
Reviewed 1 of 1 files at r6.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @Heoric)
Release note (sql change): It is now possible to use the `NOT VISIBLE` qualifier for new column definitions in CREATE TABLE. This causes the column to become 'hidden'. Hiddens columns are not considered when using `*` in SELECT clauses. (Note that CockroachDB already supported hidden columns previously, such as `rowid` which is added automatically when a table definition has no PRIMARY KEY constraint. This change merely adds the opportunity for end-users to define their own hidden columns.) This feature is intended for use in combination with other features related to geo-partitioning introduced in v21.1, to offer more control about how geo-partitioning keys get exposed to client ORMs and other automated tools that inspect the SQL schema.
bors r=lucy-zhang,knz |
Build succeeded: |
@otan thanks for covering me! sorry, this week is quite a hectic week for me as I become the on-call for my team, hopefully, in my next contribution I'll work from the start till the end. |
Informs #53428
Informs #58440
Release note (sql change): It is now possible to use the
NOT VISIBLE
qualifier for new column definitions in CREATE TABLE. This causes the
column to become 'hidden'. Hiddens columns are not considered when
using
*
in SELECT clauses.(Note that CockroachDB already supported hidden columns previously,
such as
rowid
which is added automatically when a table definitionhas no PRIMARY KEY constraint. This change merely adds the opportunity
for end-users to define their own hidden columns.)
This feature is intended for use in combination with other features
related to geo-partitioning introduced in v21.1, to offer more control
about how geo-partitioning keys get exposed to client ORMs and other
automated tools that inspect the SQL schema.