sql: support ALTER INDEX … NOT VISIBLE#86032
Conversation
e39f174 to
42f934f
Compare
michae2
left a comment
There was a problem hiding this comment.
Nice! This Let's see if we can get someone from @cockroachdb/sql-schema to take a look as well.
Reviewed 6 of 6 files at r3, all commit messages.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @michae2)
michae2
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @michae2 and @wenyihu6)
pkg/sql/alter_index_visible.go line 1 at r3 (raw file):
package sql
Above the package declaration, we need a copyright header:
// Copyright 2022 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
Also, it looks like the crlfmt linter wants us to make the following changes:
lint_test.go:1389:
diff -u old/sql/alter_index_visible.go new/sql/alter_index_visible.go
--- old/sql/alter_index_visible.go 2022-08-12 12:26:48.062773361 +0000
+++ new/sql/alter_index_visible.go 2022-08-12 12:26:48.062773361 +0000
@@ -2,6 +2,7 @@
import (
"context"
+
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc"
@@ -19,7 +20,9 @@
index catalog.Index
}
-func (p *planner) AlterIndexVisible(ctx context.Context, n *tree.AlterIndexVisible) (planNode, error) {
+func (p *planner) AlterIndexVisible(
+ ctx context.Context, n *tree.AlterIndexVisible,
+) (planNode, error) {
if err := checkSchemaChangeEnabled(
ctx,
p.ExecCfg(),
42f934f to
45275a1
Compare
| if err := checkSchemaChangeEnabled( | ||
| ctx, | ||
| p.ExecCfg(), | ||
| "ALTER INDEX VISIBILITY", |
There was a problem hiding this comment.
nit: define a constant
Relates to #85473 (comment)
| // returned is nil. 2. No IfExists, error is returned. | ||
| _, tableDesc, err := expandMutableIndexName(ctx, p, &n.Index, !n.IfExists /* requireTable */) | ||
| if err != nil { | ||
| // Error if no table is found and IfExists is false. |
There was a problem hiding this comment.
nit: these kinds of comments add little value but increase clutter, remove them.
Same comment applies below.
| return newZeroNode(nil /* columns */), nil | ||
| } | ||
| // Error if no index exists and IfExists is not specified. | ||
| return nil, pgerror.WithCandidateCode(err, pgcode.UndefinedObject) |
There was a problem hiding this comment.
I suggest wrapping this in an assertion error here, expandMutableIndexName promises that if tableDesc is not nil, then the index exists, so an error here should never happen. Mentioning that in the comments would be useful.
pkg/sql/alter_index_visible.go
Outdated
| if n.n.NotVisible { | ||
| str = " not" | ||
| } | ||
| // TODO (wenyihu6): should we log notices if index is already what they want or is that too noisy? |
There was a problem hiding this comment.
cc @cockroachdb/sql-experience but I don't think so, if you do
CREATE TABLE t (i INT NOT NULL);
ALTER TABLE t ALTER COLUMN i SET NOT NULL;
that ALTER is entirely redundant yet there's no notice.
|
Previously, michae2 (Michael Erickson) wrote…
Done. |
|
Previously, postamar (Marius Posta) wrote…
I was also curious about this. When I tested it out, this errors when you specify the index name with a table that exists but the index does not exists. For example, t@idx returns an error if t exists but idx doesn't exist. |
|
Previously, postamar (Marius Posta) wrote…
That's true. I will remove this notice. |
45275a1 to
045f1fc
Compare
|
Previously, wenyihu6 (Wenyi Hu) wrote…
Done. |
|
Previously, postamar (Marius Posta) wrote…
I'm not sure if I'm understanding correctly. Do you mean something like const feature = "ALTER INDEX VISIBILITY"? Other functions that call |
045f1fc to
17ecc2f
Compare
This commit adds support to execute ALTER INDEX … [VISIBLE | NOT VISIBLE]. Fixes: cockroachdb#72576 See also: cockroachdb#85473 Release note (sql change): Altering an index to visible or not visible using ALTER INDEX … VISIBLE | NOT VISIBLE is now supported.
17ecc2f to
15613bb
Compare
|
TFTRs!! bors r+ |
|
Build failed (retrying...): |
|
Build succeeded: |
This commit adds support to execute ALTER INDEX … [VISIBLE | NOT VISIBLE].
Fixes: #72576
See also: #85473
Release note (sql change): Altering an index to visible or not visible using
ALTER INDEX … VISIBLE | NOT VISIBLE is now supported.