-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
opt: fix panic due to incorrect type of ArrayFlatten #39469
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix!
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @justinj, @RaduBerinde, and @rytaft)
pkg/sql/opt/norm/custom_funcs.go, line 1630 at r1 (raw file):
// SubqueryRequestedCol returns the requested column from a SubqueryPrivate. func (c *CustomFuncs) SubqueryRequestedCol(sub *memo.SubqueryPrivate) opt.ColumnID { return sub.RequestedCol
I found that this field is not set for SubqueryOp..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hoistAll
seems to have the same problem:
cockroach/pkg/sql/opt/norm/decorrelate.go
Line 805 in fe76c37
colID, _ := subqueryProps.OutputCols.Next(0) |
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @justinj and @rytaft)
3aebad6
to
45421a2
Compare
There was a problem hiding this 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 set RequestedCol
for all types of subqueries, but it turned out to be a fair amount of trouble, especially for ANY
and EXISTS
. Since ArrayFlatten
is the only subquery type where it's necessary, I think we should just make it clear that RequestedCol
is only used by ArrayFlatten
. I added a comment to that effect in the definition of SubqueryPrivate
. I also updated hoistAll
to make sure that if the subquery has type ArrayFlatten
, we use RequestedCol
instead of the first output column.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @justinj and @RaduBerinde)
pkg/sql/opt/norm/custom_funcs.go, line 1630 at r1 (raw file):
Previously, RaduBerinde wrote…
I found that this field is not set for SubqueryOp..
Added a comment to say this function should only be used with ArrayFlatten
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a SubqueryColumn method to SubqueryExpr and others.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @justinj and @rytaft)
pkg/sql/opt/norm/custom_funcs.go, line 1630 at r1 (raw file):
Previously, rytaft (Rebecca Taft) wrote…
Added a comment to say this function should only be used with
ArrayFlatten
Maybe we can change it to take an ArrayFlattenExpr.
pkg/sql/opt/norm/decorrelate.go, line 805 at r2 (raw file):
// Replace the Subquery operator with a Variable operator referring to // the output column of the hoisted query. colID, _ := subqueryProps.OutputCols.Next(0)
Ideally we should assert there is a single column (except for ArrayFlatten).
45421a2
to
b86c877
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a SubqueryColumn method to SubqueryExpr and others.
I tried creating a Subquery
interface with a SubqueryColumn
method implemented by all four expressions, but it felt like a lot of overhead for the single use case of the hoistAll
function. Instead I implemented your suggestion from the issue of adding a SingleColumn
method to ColSet
which panics if there is more than one column present.
Also added your other suggestion from the issue to update the comment for ConstructApplyJoin
.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @justinj and @RaduBerinde)
pkg/sql/opt/norm/custom_funcs.go, line 1630 at r1 (raw file):
Previously, RaduBerinde wrote…
Maybe we can change it to take an ArrayFlattenExpr.
The problem is the one rule it is used with has ArrayFlatten
as the root expression, so we can't pass that in.
pkg/sql/opt/norm/decorrelate.go, line 805 at r2 (raw file):
Previously, RaduBerinde wrote…
Ideally we should assert there is a single column (except for ArrayFlatten).
Changed to use SingleColumn
method
b86c877
to
203ceae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
nit: maybe try doing a grep for other instances of Next(0) that can be replaced with the new method.
This commit fixes a panic caused by incorrect typing of an ArrayFlatten expression. If the input to an ArrayFlatten expression is sorted, there may be more than one output column (although the columns used for sorting are hidden). If one of these hidden columns is chosen to infer the type of the expression, the type could be incorrect. This commit fixes the problem so that only the requested column is chosen for type inference. Fixes cockroachdb#38867 Release note (bug fix): Fixed a panic due to incorrect type inference of some ARRAY(...) expressions.
203ceae
to
1bceb6c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe try doing a grep for other instances of Next(0) that can be replaced with the new method.
Good idea - fixed a couple of cases
bors r+
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @justinj)
39034: storage: use learner replicas for replica addition by default r=tbg a=danhhz This was previously available by flipping a cluster setting that defaulted to off, this defaults it to on. With any luck, we'll be confident enough in this to remove the cluster setting in 19.2, which will allow us to rip out a bunch of code at the beginning of the 20.1 cycle. Closes #38902 Release note (general change): Replicas are now added using a raft learner and going through the normal raft snapshot process to catch them up, eliminating technical debt. No user facing changes are expected. 39469: opt: fix panic due to incorrect type of ArrayFlatten r=rytaft a=rytaft This commit fixes a panic caused by incorrect typing of an `ArrayFlatten` expression. If the input to an `ArrayFlatten` expression is sorted, there may be more than one output column (although the columns used for sorting are hidden). If one of these hidden columns is chosen to infer the type of the expression, the type could be incorrect. This commit fixes the problem so that only the requested column is chosen for type inference. Fixes #38867 Release note (bug fix): Fixed a panic due to incorrect type inference of some ARRAY(...) expressions. Co-authored-by: Daniel Harrison <daniel.harrison@gmail.com> Co-authored-by: Rebecca Taft <becca@cockroachlabs.com>
Build succeeded |
This commit fixes a panic caused by incorrect typing of an
ArrayFlatten
expression. If the input to an
ArrayFlatten
expression is sorted, theremay be more than one output column (although the columns used for sorting
are hidden). If one of these hidden columns is chosen to infer the type
of the expression, the type could be incorrect. This commit fixes the
problem so that only the requested column is chosen for type inference.
Fixes #38867
Release note (bug fix): Fixed a panic due to incorrect type inference
of some ARRAY(...) expressions.