Skip to content

Commit

Permalink
opt: don't report invalid PruneCols from WithScan
Browse files Browse the repository at this point in the history
Fixes #40930.

This commit zeroes out the Rule field on the relational props copied
from the With node. Follow-up for post branching will be to correctly
prune the columns from the WithScan.

Release note (bug fix): Fixed a stack overflow that could occur via use
of WITH.

Release justification: Category 2: Low risk and important bugfix.
  • Loading branch information
Justin Jaffray committed Sep 20, 2019
1 parent 6c508db commit ac1aa5a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/sql/opt/memo/logical_props_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,10 @@ func (b *logicalPropsBuilder) buildWithScanProps(ref *WithScanExpr, rel *props.R
// references.
*rel = *ref.BindingProps

// Things like PruneCols are not valid here.
// TODO(justin): we should re-implement the relevant ones for WithScan.
rel.Rule = props.Relational{}.Rule

// Has Placeholder
// ---------------
// Overwrite this from the copied props.
Expand Down
33 changes: 33 additions & 0 deletions pkg/sql/opt/memo/testdata/logprops/with
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,36 @@ inner-join-apply
│ ├── fd: ()-->(3)
│ └── cte-uses: map[1:1]
└── filters (true)

# Regression test for #40930.

exec-ddl
CREATE TABLE t40930 (
s string
)
----

opt
WITH
with_4189
AS (
SELECT
tab_10102.s
FROM
t40930 AS tab_10102, (SELECT NULL) AS tab_10103 (col_24444)
)
SELECT
NULL
FROM
t40930, with_4189
----
project
├── columns: "?column?":7(unknown)
├── fd: ()-->(7)
├── prune: (7)
├── inner-join (hash)
│ ├── scan t40930
│ ├── scan tab_10102
│ └── filters (true)
└── projections
└── null [type=unknown]
6 changes: 6 additions & 0 deletions pkg/sql/opt/props/logical.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,12 @@ func (r *Relational) Verify() {
"max cardinality must be <= 1 if FDs have max 1 row: %s", r.Cardinality))
}
}
if r.IsAvailable(PruneCols) {
if !r.Rule.PruneCols.SubsetOf(r.OutputCols) {
panic(errors.AssertionFailedf("prune cols %s must be a subset of output cols %s",
log.Safe(r.Rule.PruneCols), log.Safe(r.OutputCols)))
}
}
}

// VerifyAgainst checks that the two properties don't contradict each other.
Expand Down

0 comments on commit ac1aa5a

Please sign in to comment.