-
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: permit user-defined hidden columns #53428
Comments
I'd like to take a stab at implementing this, if that's cool. |
You're more than welcome to, Jason! Thanks. |
There might be some gotchas that we'll find out along the way. I think there might be some assertions lurking around that |
I don't think that's true - didn't you just add the |
No, that was only within the optimizer's representation of tables. |
Hmm, ok. I think the hash sharded index columns are also marked hidden though, unless I'm missing something there too ( |
There was a draft implementation here: #26644 |
That PR incidentally makes the case that it's needed to implement certain pg_catalog tables that also have hidden columns. Also the approach at the top of this issue has a flaw. Look at the linked PR:
|
Which method should be used ? ALTER TABLE a ALTER COLUMN a [SET|DROP] NOT VISIBLE |
I changed the description of the issue to explain that the syntax must use "NOT VISIBLE". |
This is the correct one. |
Note: this feature is now discussed as well in this RFC: #58440 |
58923: sql: support NOT VISIBLE in CREATE TABLE for user-defined hidden columns r=lucy-zhang,knz a=Heoric 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 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. Co-authored-by: leoric <[email protected]>
PR #58923 is implementing the CREATE part of this, but does not implement ALTER SET [NOT] VISIBLE. @lucy-zhang requested that we delay the ALTER changes until after the schema change work has moved forward. |
I don't think we should necessarily wait for the schema change work to proceed. I just thought it would be easier to review in a separate commit. Do we need ALTER SET VISIBLE for the multiregion work? I have no objections to implementing it. |
PR #63052 implements |
SQL supports hidden columns: columns that are only included in a projection if explicitly requested. An example of this is the
rowid
column that is created on tables without explicitly primary keys.Currently, there is no way to get a hidden column on a user-defined table: it's only possible if you manually set the hidden boolean in the table descriptor, by editing the CockroachDB source code.
It could conceivably be useful for users to define hidden columns on their own tables. This issue tracks adding that functionality. It should be pretty straightforward, and reasonably suitable for a new contributor.
pkg/sql/parser/sql.y
as an optional modifier to columns for creation and modification. e.g.CREATE TABLE a (a INT NOT VISIBLE)
,ALTER TABLE a ALTER COLUMN a SET [NOT] VISIBLE
sql: support NOT VISIBLE in CREATE TABLE for user-defined hidden columns #58923ColumnTableDef
inpkg/sql/sem/tree/create.go
sql: support NOT VISIBLE in CREATE TABLE for user-defined hidden columns #58923MakeColumnDefDescs
inpkg/sql/catalog/tabledesc/table.go
to setHidden
on the column descriptor if the attribute above is set sql: support NOT VISIBLE in CREATE TABLE for user-defined hidden columns #58923AlterTableSetHidden
AST nodes topkg/sql/sem/tree/alter_table.go
pkg/sql/alter_table.go
pkg/sql/logictest/testdata/logic_test/hidden
. sql: support NOT VISIBLE in CREATE TABLE for user-defined hidden columns #58923The text was updated successfully, but these errors were encountered: