Skip to content

opt: remove panic when in between filters are not constrained#81465

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
rharding6373:in_between_filters
May 18, 2022
Merged

opt: remove panic when in between filters are not constrained#81465
craig[bot] merged 1 commit intocockroachdb:masterfrom
rharding6373:in_between_filters

Conversation

@rharding6373
Copy link
Copy Markdown
Collaborator

@rharding6373 rharding6373 commented May 18, 2022

Before this change, the optimizer assumed that if partition filters are
constrained on an index then the in-between filters are also
constrained, and would panic if it was unable to find a constraint.

However, when an index is partitioned on multiple columns and the
columns have different orders, the optimizer may be unable to generate a
constraint for the in between filters of the partitions, even if the
partition filters are constrained. This change removes the panic, since
the assumption does not hold. As a consequence, the optimizer abandons
the GenerateConstrainedScan rule, but doesn't crash.

I did not include a release note since this appears to be a rare bug
that we have not encountered in the wild.

Fixes #80820

Release note: None

@rharding6373 rharding6373 requested review from msirek and rytaft May 18, 2022 17:21
@rharding6373 rharding6373 requested a review from a team as a code owner May 18, 2022 17:21
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Contributor

@msirek msirek left a comment

Choose a reason for hiding this comment

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

Nice fix! Another option would have been to keep the panic if the ordering of the in-between filter column matches that of the previous column, but maybe it's better to remove the panic entirely, as you've done. A sub-optimal access path shouldn't necessarily throw an error.

:lgtm:

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


-- commits line 12 at r1:
nit: abondons -> abandons

Copy link
Copy Markdown
Collaborator Author

@rharding6373 rharding6373 left a comment

Choose a reason for hiding this comment

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

TFTR!

I tried to do that approach at first, but I don't think we have the partition columns readily available (only partitions, whose lengths are unreliable) in our index interface so it would have required additional plumbing for this one case. I think it's better for the optimizer to not crash anyway since failing to find a constraint here does not mean that other parts of the database will fail.

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


-- commits line 12 at r1:

Previously, msirek (Mark Sirek) wrote…

nit: abondons -> abandons

Done.

Copy link
Copy Markdown
Contributor

@msirek msirek 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 @rytaft)

Copy link
Copy Markdown
Collaborator

@rytaft rytaft left a comment

Choose a reason for hiding this comment

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

:lgtm:

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


pkg/sql/opt/xform/select_funcs.go line 267 at r2 (raw file):

	//
	// However, since region and zone are in ascending and descending order,
	// respectively, the optimizer is currently unable to represent a span with

nit: we could represent a span -- I'd say "is unable to build an expression that would correspond to the in-between spans"

Before this change, the optimizer assumed that if partition filters are
constrained on an index then the in-between filters are also
constrained, and would panic if it was unable to find a constraint.

However, when an index is partitioned on multiple columns and the
columns have different orders, the optimizer may be unable to generate a
constraint for the in between filters of the partitions, even if the
partition filters are constrained. This change removes the panic, since
the assumption does not hold. As a consequence, the optimizer abandons
the GenerateConstrainedScan rule, but doesn't crash.

I did not include a release note since this appears to be a rare bug
that we have not encountered in the wild.

Fixes cockroachdb#80820

Release note: None
Copy link
Copy Markdown
Collaborator Author

@rharding6373 rharding6373 left a comment

Choose a reason for hiding this comment

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

TFTRs!

bors r+

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 2 stale) (waiting on @msirek and @rytaft)


pkg/sql/opt/xform/select_funcs.go line 267 at r2 (raw file):

Previously, rytaft (Rebecca Taft) wrote…

nit: we could represent a span -- I'd say "is unable to build an expression that would correspond to the in-between spans"

Done.

@craig
Copy link
Copy Markdown
Contributor

craig bot commented May 18, 2022

Build succeeded:

@craig craig bot merged commit d2b5acf into cockroachdb:master May 18, 2022
@rharding6373 rharding6373 deleted the in_between_filters branch May 26, 2022 23:00
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: internal error: in-between filters didn't yield a constraint

4 participants