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: added ALTER INDEX ... NOT VISIBLE #84295

Conversation

wenyihu6
Copy link
Contributor

This PR added ALTER INDEX ... NOT VISIBLE to parser. Users
can now alter a secondary index to become invisible
or become visible. This PR also added panic error for if user tries
to alter a unique index or a primary index to become invisible.
Note that syntax for invisible unique constraint is not supported.
The first three commits of this PR come from #83388, #83471, and #84293.
They should be merged first.

Release note (sql): unique invisible index feature is currently not supported.

wenyihu6 added 4 commits July 11, 2022 16:15
This PR takes the first step for the invisible index feature. The first commit
added a boolean field `Hidden` to the struct `IndexDescriptor`. Since
primary indexes cannot be invisible, this commit also added a check in
`pkg/sql/catalog/tabledesc/validate.go` for that. The second commit added a new
column `is_hidden` to `crdb_internal.table_indexes` and also to the output of
following SQL statements:
```
SHOW INDEX FROM (table_name)
SHOW INDEXES FROM(table_name)
SHOW KEYS FROM (table_name)
SHOW INDEX FROM DATABASE(database_name)
SHOW INDEXES FROM DATABASE (database_name)
SHOW KEYS FROM DATABASE (database_name)
```
Since the invisible index feature has not been introduced yet, all indexes
created should be visible. It is expected for all test cases to output `false`
for all `is_hidden` columns.

See also: There will be more PR coming up to add the SQL statements
`CREATE INDEX … NOT VISIBLE`, `CREATE TABLE … (INDEX NOT VISIBLE)`,
`ALTER INDEX … NOT VISIBLE`.
Next PR for invisible index feature: cockroachdb#83471
TODO (wenyihu6): link more related pr later on

Fixes: cockroachdb#72576
Note that this issue has not been resolved yet, and this pr only takes the first step.

Release note (sql change): A new column `is_hidden` has been added to the
table `crdb_internal.table_indexes` and to the output of SQL statements related
to `SHOW INDEX`, `SHOW INDEXES`, and `SHOW KEYS`. Since the invisible index
feature has not been introduced yet, the output for this column will always be
false for now. This will be changed soon.
This PR added CREATE INDEX … INVISIBLE, CREATE TABLE (INDEX …
INVISIBLE)  to the parser and added invisible index feature to optimizer
Invisible indexes are ignored by the optimizer unless they are specifically
selected with index hinting (force index). This is not supported for unique
Indexes or primary indexes.
This commit added UNIQUE INDEX ... NOT VISIBLE to parser and
added panic error for if user tries to create an invisible unique index.
Note that syntax for invisible unique constraint is not supported.
This commit added ALTER index NOT VISIBLE.  Not done yet

# Conflicts:
#	pkg/sql/walk.go

covered unique and primary check
@wenyihu6 wenyihu6 requested a review from a team July 12, 2022 17:55
@wenyihu6 wenyihu6 requested a review from a team as a code owner July 12, 2022 17:55
@wenyihu6 wenyihu6 requested review from a team July 12, 2022 17:55
@wenyihu6 wenyihu6 requested review from a team as code owners July 12, 2022 17:55
@wenyihu6 wenyihu6 requested a review from msbutler July 12, 2022 17:55
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@wenyihu6 wenyihu6 removed request for a team and msbutler July 12, 2022 17:55
@wenyihu6 wenyihu6 marked this pull request as draft July 12, 2022 17:55
if err := checkSchemaChangeEnabled(
ctx,
p.ExecCfg(),
"ALTER INDEX VISBILITY",
Copy link

Choose a reason for hiding this comment

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

This should probably be ALTER INDEX VISIBILITY

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right! Thank you : )

@wenyihu6 wenyihu6 closed this Aug 12, 2022
@wenyihu6 wenyihu6 deleted the 3-new-add-ALTER-INVISIBLE(wenyihu6) branch September 1, 2022 20:48
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.

2 participants