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: warn when creating non-partitioned index #39154

Merged

Conversation

solongordon
Copy link
Contributor

In most cases, secondary indexes created on a partitioned table should
also be partitioned. To protect users from this gotcha, we now return an
error in this case if sql_safe_updates is on.

This isn't an ideal solution to the problem. It only really protects
users who are using the interactive CLI, and if a user really does want
an unpartitioned index it will force them to turn off sql_safe_updates,
at least temporarily. However, I didn't have much luck finding another
way to deliver a warning which users were likely to see.

Fixes #38475

Release note: None

@solongordon solongordon requested review from jordanlewis, rohany and a team July 29, 2019 20:44
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@solongordon
Copy link
Contributor Author

Open to other ideas about how to deliver this warning if people have them!

Copy link
Contributor

@rohany rohany left a comment

Choose a reason for hiding this comment

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

Is there a way to make a unit/logic test for this?

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @jordanlewis, @rohany, and @solongordon)


pkg/sql/create_index.go, line 95 at r1 (raw file):

	// which is undesirable in most cases.
	if params.SessionData().SafeUpdates && n.n.PartitionBy == nil &&
		n.tableDesc.PrimaryIndex.Partitioning.NumColumns > 0 {

do you need to check all indexes, not just the primary index?


pkg/sql/create_table.go, line 142 at r1 (raw file):

	if params.SessionData().SafeUpdates && n.n.PartitionBy != nil {
		for _, def := range n.n.Defs {
			if d, ok := def.(*tree.IndexTableDef); ok {

I think you also want to check here if the primary key isn't partitioned, but a secondary index is partitioned.

In most cases, secondary indexes created on a partitioned table should
also be partitioned. To protect users from this gotcha, we now return an
error in this case if sql_safe_updates is on.

This isn't an ideal solution to the problem. It only really protects
users who are using the interactive CLI, and if a user really does want
an unpartitioned index it will force them to turn off sql_safe_updates,
at least temporarily. However, I didn't have much luck finding another
way to deliver a warning which users were likely to see.

Fixes cockroachdb#38475

Release note: None
@solongordon solongordon force-pushed the non-partitioned-index-warning branch from 2030756 to 8dde5f6 Compare July 29, 2019 20:53
@solongordon solongordon requested a review from a team July 29, 2019 20:53
Copy link
Contributor Author

@solongordon solongordon left a comment

Choose a reason for hiding this comment

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

Yup, added a few logic tests. (I was trying to slip them in before anyone reviewed but you were too fast.)

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


pkg/sql/create_index.go, line 95 at r1 (raw file):

Previously, rohany (Rohan Yadav) wrote…

do you need to check all indexes, not just the primary index?

My understanding is that checking the primary index tells you whether the "table" is partitioned, so I think it's enough? I don't think we need to error if the user is adding an unpartitioned index to a table where the primary index isn't partitioned but some other index is.


pkg/sql/create_table.go, line 142 at r1 (raw file):

Previously, rohany (Rohan Yadav) wrote…

I think you also want to check here if the primary key isn't partitioned, but a secondary index is partitioned.

Interesting, yeah that seems unlikely but I suppose it would be weird enough to warn about.

Copy link
Contributor

@rohany rohany 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 @jordanlewis and @solongordon)


pkg/sql/create_index.go, line 95 at r1 (raw file):

Previously, solongordon (Solon) wrote…

My understanding is that checking the primary index tells you whether the "table" is partitioned, so I think it's enough? I don't think we need to error if the user is adding an unpartitioned index to a table where the primary index isn't partitioned but some other index is.

yeah that makes sense


pkg/sql/create_table.go, line 142 at r1 (raw file):

Previously, solongordon (Solon) wrote…

Interesting, yeah that seems unlikely but I suppose it would be weird enough to warn about.

yup, since we are warning anyway, might as well.

@solongordon
Copy link
Contributor Author

bors r+

craig bot pushed a commit that referenced this pull request Aug 6, 2019
39154: sql: warn when creating non-partitioned index r=solongordon a=solongordon

In most cases, secondary indexes created on a partitioned table should
also be partitioned. To protect users from this gotcha, we now return an
error in this case if sql_safe_updates is on.

This isn't an ideal solution to the problem. It only really protects
users who are using the interactive CLI, and if a user really does want
an unpartitioned index it will force them to turn off sql_safe_updates,
at least temporarily. However, I didn't have much luck finding another
way to deliver a warning which users were likely to see.

Fixes #38475

Release note: None

Co-authored-by: Solon Gordon <[email protected]>
@craig
Copy link
Contributor

craig bot commented Aug 6, 2019

Build succeeded

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.

sql: warn or forbid unpartitioned secondary indexes on partitioned tables
3 participants