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: permit user-defined hidden columns #53428

Closed
4 of 6 tasks
jordanlewis opened this issue Aug 25, 2020 · 15 comments
Closed
4 of 6 tasks

sql: permit user-defined hidden columns #53428

jordanlewis opened this issue Aug 25, 2020 · 15 comments
Labels
C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) good first issue

Comments

@jordanlewis
Copy link
Member

jordanlewis commented Aug 25, 2020

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.

@jordanlewis jordanlewis added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) good first issue labels Aug 25, 2020
@jasobrown
Copy link
Contributor

I'd like to take a stab at implementing this, if that's cool.

@jordanlewis
Copy link
Member Author

You're more than welcome to, Jason! Thanks.

@rohany
Copy link
Contributor

rohany commented Aug 25, 2020

There might be some gotchas that we'll find out along the way. I think there might be some assertions lurking around that rowid is the only hidden column.

@jordanlewis
Copy link
Member Author

I don't think that's true - didn't you just add the crdb_internal_mvcc_timestamp column to every table that's marked hidden too? :)

@rohany
Copy link
Contributor

rohany commented Aug 25, 2020

No, that was only within the optimizer's representation of tables.

@jordanlewis
Copy link
Member Author

Hmm, ok. I think the hash sharded index columns are also marked hidden though, unless I'm missing something there too (makeShardColumnDesc)

@knz
Copy link
Contributor

knz commented Aug 26, 2020

There was a draft implementation here: #26644

@knz
Copy link
Contributor

knz commented Aug 26, 2020

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:

Note: the choice for the syntax "NOT VISIBLE" as opposed to "HIDDEN"
is mandated by the fact that the first word of an attribute must be a
reserved keyword, and adding reserved keywords is disruptive. This
way, the patch is properly backward-compatible.

@Heoric
Copy link

Heoric commented Jan 7, 2021

Which method should be used ?

ALTER TABLE a ALTER COLUMN a [SET|DROP] NOT VISIBLE
or
ALTER TABLE a ALTER COLUMN a SET [NOT] VISIBLE

@knz
Copy link
Contributor

knz commented Jan 7, 2021

I changed the description of the issue to explain that the syntax must use "NOT VISIBLE".
We cannot use a keyword "HIDDEN" in the proposed way, because of grammar restrictions (see #26644 for details).

@knz
Copy link
Contributor

knz commented Jan 7, 2021

ALTER TABLE a ALTER COLUMN a SET [NOT] VISIBLE

This is the correct one.

@knz
Copy link
Contributor

knz commented Jan 7, 2021

Note: this feature is now discussed as well in this RFC: #58440

craig bot pushed a commit that referenced this issue Feb 3, 2021
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]>
@knz
Copy link
Contributor

knz commented Feb 3, 2021

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.

@thoszhang
Copy link
Contributor

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.

@rafiss
Copy link
Collaborator

rafiss commented Apr 22, 2021

PR #63052 implements ALTER SET [NOT] VISIBLE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) good first issue
Projects
None yet
Development

No branches or pull requests

7 participants