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: add NotVisible to index descriptor #84763

Merged
merged 1 commit into from
Jul 22, 2022

Conversation

wenyihu6
Copy link
Contributor

@wenyihu6 wenyihu6 commented Jul 20, 2022

This commit adds a new field NotVisible to the struct IndexDescriptor. Since
primary indexes cannot be not visible, it also includes another check in
pkg/sql/catalog/tabledesc/validate.go. Since the invisible index feature has
not been introduced yet, all indexes created should be visible.

See also: #84776

Assists: #72576

Release note: none

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@wenyihu6 wenyihu6 force-pushed the 1-add-NotVisible-to-descpb branch 6 times, most recently from 1632058 to 4cd6576 Compare July 20, 2022 23:11
@wenyihu6 wenyihu6 force-pushed the 1-add-NotVisible-to-descpb branch 2 times, most recently from 0b910a7 to a4610f6 Compare July 21, 2022 02:03
@wenyihu6 wenyihu6 marked this pull request as ready for review July 21, 2022 03:51
@wenyihu6 wenyihu6 requested a review from a team as a code owner July 21, 2022 03:51
@wenyihu6 wenyihu6 requested a review from a team July 21, 2022 03:51
@wenyihu6 wenyihu6 requested a review from a team as a code owner July 21, 2022 03:51
@wenyihu6 wenyihu6 changed the title sql: added NotVisible to index descriptor sql: add NotVisible to index descriptor Jul 21, 2022
@michae2 michae2 requested review from postamar, mgartner and michae2 July 21, 2022 16:35
Copy link
Collaborator

@michae2 michae2 left a comment

Choose a reason for hiding this comment

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

:lgtm:

message: ThisPR {
  optional bool lgtm = 1 [(gogoproto.nullable) = false];
}

return &ThisPR{lgtm: true}

Reviewed 24 of 24 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @mgartner and @postamar)

Copy link
Collaborator

@mgartner mgartner left a comment

Choose a reason for hiding this comment

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

:lgtm: Very nicely done! Let's get someone on SQL Schema to stamp this before merging.

Reviewed 24 of 24 files at r1, all commit messages.
Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @postamar and @wenyihu6)


-- commits line 2 at r1:
nit: we prefer to use the imperative mood for commit titles, like sql: add NotVisible to index descriptor

I think we typically use the present tense in the commit body (e.g. "This PR adds ..." rather than "This PR added ..."), but I don't see that as an official guideline in the doc linked above, so that's up to you if you want to change it.


-- commits line 4 at r1:
super nit: PR => commit


pkg/sql/catalog/catformat/index.go line 179 at r1 (raw file):

	if index.NotVisible {
		f.WriteString(" NOT VISIBLE")

Reminder to add tests for this with SHOW CREATE TABLE once not visible indexes can be added.


pkg/sql/opt/indexrec/hypothetical_index.go line 52 at r1 (raw file):

	// notVisible indicates if an index is not visible to the optimizer.
	notVisible bool

I don't think we need this field, we can just always return false in IsNotVisible below. I don't see a case where we'd make a recommendation to the user to create an invisible index.

You could add a TODO here to handle cases where an invisible index exists that should be made non-visible to improve the query plan.


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/create_index.go line 46 at r1 (raw file):

		IsInverted:     n.Inverted,
		IsConcurrently: n.Concurrently,
		IsNotVisible:   false, // TODO(wenyihu6): populate hidden property after CREATE

nit: hidden => IsNotVisible

@wenyihu6 wenyihu6 force-pushed the 1-add-NotVisible-to-descpb branch from a4610f6 to 9c18b23 Compare July 21, 2022 20:35
Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

LGTM

This commit adds a new field `NotVisible` to the struct `IndexDescriptor`. Since
primary indexes cannot be not visible, it also includes another check in
`pkg/sql/catalog/tabledesc/validate.go`. Since the invisible index feature has
not been introduced yet, all indexes created should be visible.

See also: cockroachdb#84776

Assists: cockroachdb#72576

Release note: none
@wenyihu6
Copy link
Contributor Author

pkg/sql/opt/indexrec/hypothetical_index.go line 52 at r1 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

I don't think we need this field, we can just always return false in IsNotVisible below. I don't see a case where we'd make a recommendation to the user to create an invisible index.

You could add a TODO here to handle cases where an invisible index exists that should be made non-visible to improve the query plan.

Done.

@wenyihu6
Copy link
Contributor Author

pkg/sql/schemachanger/scbuild/internal/scbuildstmt/create_index.go line 46 at r1 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

nit: hidden => IsNotVisible

Done.

@wenyihu6 wenyihu6 force-pushed the 1-add-NotVisible-to-descpb branch from 9c18b23 to b91b031 Compare July 22, 2022 09:38
@wenyihu6
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Jul 22, 2022

Build succeeded:

@craig craig bot merged commit 65d1263 into cockroachdb:master Jul 22, 2022
@wenyihu6 wenyihu6 deleted the 1-add-NotVisible-to-descpb branch September 1, 2022 20:47
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.

5 participants