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: fix incorrect distsql plan caused by nil filter #44307

Merged
merged 1 commit into from
Jan 27, 2020

Conversation

RaduBerinde
Copy link
Member

In some cases, filters that are not constant-folded by the optimizer
can be evaluated statically to true when building the filterNode. In
this case we create a filterNode with a nil filter, which is ill
handled by the distsql planner.

This change elides the filterNode in this case, and fixes up the
distsl code to error out in this case.

Release note (bug fix): fixed incorrect plans in very rare cases
involving filters that aren't constant folded in the optimizer but
that can be evaluated statically when running a given query.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @RaduBerinde and @solongordon)


pkg/sql/logictest/testdata/logic_test/select, line 647 at r1 (raw file):

# but is statically evaluated to true when building the filterNode).
statement ok
CREATE TABLE t44203(c0 BOOL);

[nit]: unnecessary semicolon.


pkg/sql/physicalplan/physical_plan.go, line 638 at r1 (raw file):

		filter.LocalExpr = tree.NewTypedAndExpr(
			post.Filter.LocalExpr,
			filter.LocalExpr,

Will this work in case when filter.LocalExpr is nil?

I also think that this distinction between .Expr and .LocalExpr was put in-place by Jordan to improve the performance, but I guess it is ok to "write" .Expr even if we're using .LocalExpr since it'll happen only once during planning, right?

Copy link
Member Author

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

TFTR!

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


pkg/sql/logictest/testdata/logic_test/select, line 647 at r1 (raw file):

Previously, yuzefovich wrote…

[nit]: unnecessary semicolon.

Done.


pkg/sql/physicalplan/physical_plan.go, line 638 at r1 (raw file):

Previously, yuzefovich wrote…

Will this work in case when filter.LocalExpr is nil?

I also think that this distinction between .Expr and .LocalExpr was put in-place by Jordan to improve the performance, but I guess it is ok to "write" .Expr even if we're using .LocalExpr since it'll happen only once during planning, right?

Wasn't sure about this, added the if back in.

Copy link
Member

@yuzefovich yuzefovich 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 2 of 2 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @RaduBerinde, @solongordon, and @yuzefovich)


pkg/sql/physicalplan/physical_plan.go, line 638 at r1 (raw file):

Previously, RaduBerinde wrote…

Wasn't sure about this, added the if back in.

Personally, I'd keep this whole code chunk untouched (because we might not want to fill in .Expr when .LocalExpr is non-nil - I feel like there is an implicit assumption that only of them is actually set), but it's up to you.

In some cases, filters that are not constant-folded by the optimizer
can be evaluated statically to true when building the filterNode. In
this case we create a filterNode with a nil filter, which is ill
handled by the distsql planner.

This change elides the filterNode in this case, and fixes up the
distsl code to error out in this case.

Release note (bug fix): fixed incorrect plans in very rare cases
involving filters that aren't constant folded in the optimizer but
that can be evaluated statically when running a given query.
Copy link
Member Author

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

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


pkg/sql/physicalplan/physical_plan.go, line 638 at r1 (raw file):

Previously, yuzefovich wrote…

Personally, I'd keep this whole code chunk untouched (because we might not want to fill in .Expr when .LocalExpr is non-nil - I feel like there is an implicit assumption that only of them is actually set), but it's up to you.

Ok, added a comment.

@RaduBerinde
Copy link
Member Author

bors r+

craig bot pushed a commit that referenced this pull request Jan 27, 2020
44307: sql: fix incorrect distsql plan caused by nil filter r=RaduBerinde a=RaduBerinde

In some cases, filters that are not constant-folded by the optimizer
can be evaluated statically to true when building the filterNode. In
this case we create a filterNode with a nil filter, which is ill
handled by the distsql planner.

This change elides the filterNode in this case, and fixes up the
distsl code to error out in this case.

Release note (bug fix): fixed incorrect plans in very rare cases
involving filters that aren't constant folded in the optimizer but
that can be evaluated statically when running a given query.

Co-authored-by: Radu Berinde <radu@cockroachlabs.com>
@craig
Copy link
Contributor

craig bot commented Jan 27, 2020

Build succeeded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants