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: store partial index predicate in index descriptor #49453

Merged
merged 1 commit into from
Jun 2, 2020

Conversation

mgartner
Copy link
Collaborator

With this commit, serialized partial index predicates are now stored on
index descriptors. Predicates are dequalified so that database and table
names are not included in column references.

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@jordanlewis jordanlewis left a comment

Choose a reason for hiding this comment

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

Nice, this looks good. I hope you don't mind the drop in reviews, but I'm just quite familiar with what's going on so it's pretty low cost for me.

I think that this patch will be broken in the presence of column renames. You need to change the code in pkg/sql/rename_column.go to iterate over the Predicates and not just the check constraints and computed column expressions. You should also add test cases for this, and also maybe some test cases for rename table as you allude to in one of your comments.

pkg/sql/partial_index.go Outdated Show resolved Hide resolved
pkg/sql/partial_index.go Outdated Show resolved Hide resolved
pkg/sql/create_table.go Outdated Show resolved Hide resolved
@mgartner mgartner force-pushed the descriptor-partial-index branch 4 times, most recently from 9b9c793 to 47a6ce7 Compare May 27, 2020 23:33
@mgartner mgartner requested a review from a team as a code owner May 27, 2020 23:33
@mgartner mgartner force-pushed the descriptor-partial-index branch 2 times, most recently from 9b9c793 to 90b4439 Compare May 27, 2020 23:42
@mgartner
Copy link
Collaborator Author

Hold off on reviewing this until #49657 is sorted out. A rebase will be required if that gets merged.

@mgartner mgartner force-pushed the descriptor-partial-index branch 2 times, most recently from a663876 to c973e12 Compare June 1, 2020 21:54
@mgartner mgartner requested a review from RaduBerinde June 1, 2020 21:54
@@ -1,3 +1,4 @@
# LogicTest: !3node-tenant
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is required for the SHOW CREATE TABLE... statements I added. Without it the build fails with relation "system.zones" does not exist. Why?

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @asubiotto, @jordanlewis, @mgartner, and @RaduBerinde)


pkg/sql/logictest/testdata/logic_test/partial_index, line 1 at r3 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

This is required for the SHOW CREATE TABLE... statements I added. Without it the build fails with relation "system.zones" does not exist. Why?

Maybe @asubiotto knows. It looks like it's blacklisted in a lot of other tests so this is probably fine


pkg/sql/sqlbase/structured.proto, line 470 at r3 (raw file):

  optional geo.geoindex.Config geo_config = 22 [(gogoproto.nullable) = false];

  // If Predicate is not the empty string, describes a predicate expression for

[nit] It would be nice if it would be more clear that this is only set for partial indexes, and is actually the only way to tell if an index is partial. Maybe "Predicate, when it is not empty, indicates that this is a partial index and contains the expression for the partial index condition."


pkg/sql/sqlbase/structured.proto, line 471 at r3 (raw file):

  // If Predicate is not the empty string, describes a predicate expression for
  // a partial index.

[nit] maybe add a TODO referencing #49766. (once that is addressed, we'd want to update this comment to say how the predicate expression refers to table columns)


pkg/sql/sqlbase/structured.proto, line 472 at r3 (raw file):

  // If Predicate is not the empty string, describes a predicate expression for
  // a partial index.
  optional string predicate = 23 [(gogoproto.nullable) = false];

[nit] consider partial_index_predicate (your call, I realize it's a mouthful)

With this commit, serialized partial index predicates are now stored on
index descriptors. Predicates are dequalified so that database and table
names are not included in column references.

Release note: None
Copy link
Collaborator Author

@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.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @asubiotto, @jordanlewis, and @RaduBerinde)


pkg/sql/sqlbase/structured.proto, line 470 at r3 (raw file):

Previously, RaduBerinde wrote…

[nit] It would be nice if it would be more clear that this is only set for partial indexes, and is actually the only way to tell if an index is partial. Maybe "Predicate, when it is not empty, indicates that this is a partial index and contains the expression for the partial index condition."

Done.


pkg/sql/sqlbase/structured.proto, line 471 at r3 (raw file):

Previously, RaduBerinde wrote…

[nit] maybe add a TODO referencing #49766. (once that is addressed, we'd want to update this comment to say how the predicate expression refers to table columns)

Done.


pkg/sql/sqlbase/structured.proto, line 472 at r3 (raw file):

Previously, RaduBerinde wrote…

[nit] consider partial_index_predicate (your call, I realize it's a mouthful)

I felt that "index" was redundant given that this is within IndexDescriptor. Would partial_predicate be better than predicate?

@RaduBerinde
Copy link
Member


pkg/sql/sqlbase/structured.proto, line 472 at r3 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

I felt that "index" was redundant given that this is within IndexDescriptor. Would partial_predicate be better than predicate?

Nah, that's more confusing (sounds like the predicate is partial). Better to keep it as is.

Copy link
Contributor

@asubiotto asubiotto left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @jordanlewis and @mgartner)


pkg/sql/logictest/testdata/logic_test/partial_index, line 1 at r3 (raw file):

Previously, RaduBerinde wrote…

Maybe @asubiotto knows. It looks like it's blacklisted in a lot of other tests so this is probably fine

Because system.zones only exists on the system tenant: #49445. #49784 should make it so that we can remove this blacklist for a lot of tests that depend on accessing zone configs. Blacklisting is fine.

Copy link
Collaborator Author

@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.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @jordanlewis)


pkg/sql/logictest/testdata/logic_test/partial_index, line 1 at r3 (raw file):

Previously, asubiotto (Alfonso Subiotto Marqués) wrote…

Because system.zones only exists on the system tenant: #49445. #49784 should make it so that we can remove this blacklist for a lot of tests that depend on accessing zone configs. Blacklisting is fine.

Thanks for the explanation!


pkg/sql/sqlbase/structured.proto, line 472 at r3 (raw file):

Previously, RaduBerinde wrote…

Nah, that's more confusing (sounds like the predicate is partial). Better to keep it as is.

Ok. I'll keep an eye on this, and if it is confusing us again before the release, I can rename it.

@mgartner
Copy link
Collaborator Author

mgartner commented Jun 2, 2020

bors r+

@craig
Copy link
Contributor

craig bot commented Jun 2, 2020

Build succeeded

@craig craig bot merged commit 455a67b into cockroachdb:master Jun 2, 2020
@mgartner mgartner deleted the descriptor-partial-index branch June 2, 2020 17:42
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