Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
66444: opt: improve FDs for Intersect and Except variants r=RaduBerinde a=RaduBerinde

We can pass through FDs from the left side on Except/ExceptAll; and we
can pass through FDs from both sides on Intersect/IntersectAll.

Release note: None

66452: sql: properly wrap some errors r=ajwerner a=ajwerner

These errors may contain transaction restarts. We need to wrap them instead of
swallowing them.

Touches most recent failures on #64461.

Release note: None

66454: sql: add a hint for timestamptz -> string error r=RaduBerinde a=RaduBerinde

This adds a hint to the error that you get if you try to cast a
TIMESTAMPTZ to STRING in a computed column expression. It mentions a
workaround where you first convert to a timestamp using a specific
timezone.

Release note: None

Co-authored-by: Radu Berinde <[email protected]>
Co-authored-by: Andrew Werner <[email protected]>
  • Loading branch information
3 people committed Jun 15, 2021
4 parents ac5a718 + 74a99f8 + cef6708 + 2defc06 commit a61f01d
Show file tree
Hide file tree
Showing 27 changed files with 271 additions and 116 deletions.
2 changes: 1 addition & 1 deletion pkg/sql/alter_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ func (p *planner) updateFKBackReferenceName(
} else {
lookup, err := p.Descriptors().GetMutableTableVersionByID(ctx, ref.ReferencedTableID, p.txn)
if err != nil {
return errors.Errorf("error resolving referenced table ID %d: %v", ref.ReferencedTableID, err)
return errors.Wrapf(err, "error resolving referenced table ID %d", ref.ReferencedTableID)
}
referencedTableDesc = lookup
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/backfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -2222,7 +2222,7 @@ func runSchemaChangesInTxn(
} else {
lookup, err := planner.Descriptors().GetMutableTableVersionByID(ctx, fk.ReferencedTableID, planner.Txn())
if err != nil {
return errors.Errorf("error resolving referenced table ID %d: %v", fk.ReferencedTableID, err)
return errors.Wrapf(err, "error resolving referenced table ID %d", fk.ReferencedTableID)
}
referencedTableDesc = lookup
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/conn_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func (s *Server) GetUnscrubbedStmtStats(
s.sqlStats.IterateStatementStats(ctx, &sqlstats.IteratorOptions{}, stmtStatsVisitor)

if err != nil {
return nil, errors.Errorf("failed to fetch statement stats: %s", err)
return nil, errors.Wrap(err, "failed to fetch statement stats")
}

return stmtStats, nil
Expand All @@ -459,7 +459,7 @@ func (s *Server) GetUnscrubbedTxnStats(
s.sqlStats.IterateTransactionStats(ctx, &sqlstats.IteratorOptions{}, txnStatsVisitor)

if err != nil {
return nil, errors.Errorf("failed to fetch statement stats: %s", err)
return nil, errors.Wrap(err, "failed to fetch statement stats")
}

return txnStats, nil
Expand Down Expand Up @@ -509,7 +509,7 @@ func (s *Server) getScrubbedStmtStats(
statsProvider.IterateStatementStats(ctx, &sqlstats.IteratorOptions{}, stmtStatsVisitor)

if err != nil {
return nil, errors.Errorf("failed to fetch scrubbed statement stats: %s", err)
return nil, errors.Wrap(err, "failed to fetch scrubbed statement stats")
}

return scrubbedStats, nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/drop_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ func (p *planner) removeFKForBackReference(
} else {
lookup, err := p.Descriptors().GetMutableTableVersionByID(ctx, ref.OriginTableID, p.txn)
if err != nil {
return errors.Errorf("error resolving origin table ID %d: %v", ref.OriginTableID, err)
return errors.Wrapf(err, "error resolving origin table ID %d", ref.OriginTableID)
}
originTableDesc = lookup
}
Expand Down Expand Up @@ -607,7 +607,7 @@ func (p *planner) removeFKBackReference(
} else {
lookup, err := p.Descriptors().GetMutableTableVersionByID(ctx, ref.ReferencedTableID, p.txn)
if err != nil {
return errors.Errorf("error resolving referenced table ID %d: %v", ref.ReferencedTableID, err)
return errors.Wrapf(err, "error resolving referenced table ID %d", ref.ReferencedTableID)
}
referencedTableDesc = lookup
}
Expand Down Expand Up @@ -663,7 +663,7 @@ func (p *planner) removeInterleaveBackReference(
} else {
lookup, err := p.Descriptors().GetMutableTableVersionByID(ctx, ancestor.TableID, p.txn)
if err != nil {
return errors.Errorf("error resolving referenced table ID %d: %v", ancestor.TableID, err)
return errors.Wrapf(err, "error resolving referenced table ID %d", ancestor.TableID)
}
t = lookup
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/computed
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,20 @@ CREATE TABLE y (
b TIMESTAMP AS (a::TIMESTAMP) STORED
)

# Make sure the error has a hint that mentions AT TIME ZONE.
statement error context-dependent operators are not allowed in computed column.*\nHINT:.*AT TIME ZONE
CREATE TABLE y (
a TIMESTAMPTZ,
b STRING AS (a::STRING) STORED
)

# Make sure the error has a hint that mentions AT TIME ZONE.
statement error context-dependent operators are not allowed in computed column.*\nHINT:.*AT TIME ZONE
CREATE TABLE y (
a TIMESTAMPTZ,
b TIMESTAMP AS (a::TIMESTAMP) STORED
)

statement error context-dependent operators are not allowed in computed column
CREATE TABLE y (
a TIMESTAMPTZ,
Expand Down
28 changes: 18 additions & 10 deletions pkg/sql/opt/colset.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,18 @@ func (s ColSet) ToList() ColList {
// TranslateColSet(ColSet{5, 6}, Right, Out) -> ColSet{8, 9}
// TranslateColSet(ColSet{9}, Out, Right) -> ColSet{6}
//
// Note that for the output of TranslateColSet to be correct, colSetIn must be
// a subset of the columns in `from`. TranslateColSet does not check that this
// is the case, because that would require building a ColSet from `from`, and
// checking that colSetIn.SubsetOf(fromColSet) is true -- a lot of computation
// for a validation check. It is not correct or sufficient to check that
// colSetIn.Len() == colSetOut.Len(), because it is possible that colSetIn and
// colSetOut could have different lengths and still be valid. Consider the
// following case:
// Any columns in the input set that do not appear in the from list are ignored.
//
// Even when all the columns in the input set appear in the from list, it is
// possible for the input and output sets to have different cardinality.
// Consider the following case:
//
// SELECT x, x, y FROM xyz UNION SELECT a, b, c FROM abc
//
// TranslateColSet(ColSet{x, y}, Left, Right) correctly returns
// ColSet{a, b, c}, even though ColSet{x, y}.Len() != ColSet{a, b, c}.Len().
// TranslateColSet(ColSet{x, y}, {x, x, y}, {a, b, c}) returns ColSet{a, b, c}.
//
// Conversely, TranslateColSet(ColSet{a, b, c}, {a, b, c}, {x, x, y}) returns
// ColSet{x, y}.
func TranslateColSet(colSetIn ColSet, from ColList, to ColList) ColSet {
var colSetOut ColSet
for i := range from {
Expand All @@ -147,3 +146,12 @@ func TranslateColSet(colSetIn ColSet, from ColList, to ColList) ColSet {

return colSetOut
}

// TranslateColSetStrict is a version of TranslateColSet which requires that all
// columns in the input set appear in the from list.
func TranslateColSetStrict(colSetIn ColSet, from ColList, to ColList) ColSet {
if util.CrdbTestBuild && !colSetIn.SubsetOf(from.ToSet()) {
panic(errors.AssertionFailedf("input set contains unknown columns"))
}
return TranslateColSet(colSetIn, from, to)
}
5 changes: 5 additions & 0 deletions pkg/sql/opt/exec/execbuilder/testdata/fk
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ vectorized: true
│ │
│ └── • hash join
│ │ equality: (p) = (p)
│ │ left cols are key
│ │ right cols are key
│ │
│ ├── • except all
Expand All @@ -512,6 +513,7 @@ vectorized: true
└── • hash join
│ equality: (p) = (p)
│ left cols are key
│ right cols are key
├── • except all
Expand Down Expand Up @@ -618,6 +620,7 @@ vectorized: true
└── • hash join
│ equality: (c) = (c)
│ left cols are key
│ right cols are key
├── • except all
Expand Down Expand Up @@ -758,6 +761,7 @@ vectorized: true
└── • hash join
│ equality: (c) = (c)
│ left cols are key
│ right cols are key
├── • except all
Expand Down Expand Up @@ -890,6 +894,7 @@ vectorized: true
└── • hash join
│ equality: (x) = (y)
│ left cols are key
│ right cols are key
├── • except all
Expand Down
12 changes: 6 additions & 6 deletions pkg/sql/opt/exec/execbuilder/testdata/union
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ vectorized: true
·
• intersect
│ columns: (b, c, d, e)
│ ordering: +b,+c,+d,+e
│ ordering: +b,+d,+c,+e
│ estimated row count: 1 (missing stats)
├── • filter
Expand Down Expand Up @@ -624,7 +624,7 @@ vectorized: true
table: abcde@abcde_b_c_d_e_idx
spans: FULL SCAN
·
Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJy0lF-L2kAUxd_7KS73KcEpbv7olgFhdmuWBlyzTUL_UERi5tYG0iSdjLBF_O4lSdtVu6Z12b4Ic2Z-95x7kGyx_pYjR-_D3ezKn4Mx9aM4ejtj8M4Lr4PIMyHyZt7rGFYMUgaSAcFNGNyCcUJPVqkk8OexF0bNfd8zE96_8UIPjBQmYJlwNZ-CIWECZEIQTr0Qrj_CChkWpaR58pVq5J_QwgXDSpUp1XWpGmnbPvDlPfILhllRbXQjLximpSLkW9SZzgk5xskqp5ASSWp4gQwl6STL27FtItH-LlfLdCmXtMzkPTKMqqSoObxEhsFGcxA2Ew4TLhMjXOwYlhv94FjrZE3IrR3791Q3Wa5JkRpah5E6nYMh7KYgzrk_j1_97Ek4MAHhmicj2OdE2C_G_p_FOE8qxnnOYtxzIkyzWmdFqofuYQRhsV_rNusrSYokh0Z2TjqPnuQ8egbn8UnnB8NNUXbDDvwWDfm3J4_EvyW1poh0UA3HhwvE3yvie5-Iq9kMGeb0WRvCGjBhD5hwBky4A3OisvWXP-Xff7i9Kk5tfnlO5yHVVVnUdNzAo5MvmrVJrqmrsS43KqU7VaatTXcMWq4VJNW6u7W6g190V03AfdjqhUf9sN0LO_2w0wu7_bDbC48PYOsYHp0B28fwuBe-PIq92L34EQAA___K-yzi
Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJy0lF-L2kAUxd_7KS73KcEpbv7olgFhdmuWBlyzTUL_UERi5tYG0iSdjLBF_O4lSdtVu6Z12b4Ic2Z-95x7kGyx_pYjR-_D3ezKn4Mx9aM4ejtj8M4Lr4PIMyHyZt7rGFYMUgaSAcFNGNyCcUJPVqkk8OexF0bNfd8zE96_8UIPjBQmYJlwNZ-CIWECZEIQTr0Qrj_CChkWpaR58pVq5J_QwgXDSpUp1XWpGmnbPvDlPfILhllRbXQjLximpSLkW9SZzgk5xskqp5ASSWp4gQwl6STL27FtItH-LlfLdCmXtMzkPTKMqqSoObxEhsFGcxA2Ew4TLhMjXOwYlhv94FjrZE3IrR3791Q3Wa5JkRpah5E6nYMh7KYgzrk_j1_97Ek4MAHhmicj2OdE2C_G_p_FOE8qxnnOYtxzIkyzWmdFqofuYQRhsV_rNusrSYokh0Z2TjqPnuQ8egbn8UnnB8NNUXbDDvwWDfm3J4_EvyW1poh0UA3HhwvE3yvie5-Iq9kMGeb0WRvCGjDhDJiwB0y4A3OisvWXP-Xff7i9Kk5tfnlO5yHVVVnUdNzAo5MvmrVJrqmrsS43KqU7VaatTXcMWq4VJNW6u7W6g190V03AfdjqhUf9sN0LO_2w0wu7_bDbC48PYOsYHp0B28fwuBe-PIq92L34EQAA___LAyzi

query T
EXPLAIN (DISTSQL,VERBOSE) SELECT b, c, d, e FROM (SELECT b, c, d, e FROM abcde EXCEPT SELECT b, c, d, e FROM abcde) WHERE c = 1 AND d = e ORDER BY b, c, d, e
Expand All @@ -634,7 +634,7 @@ vectorized: true
·
• except
│ columns: (b, c, d, e)
│ ordering: +b,+c,+d,+e
│ ordering: +b,+d,+c,+e
│ estimated row count: 1 (missing stats)
├── • filter
Expand Down Expand Up @@ -663,7 +663,7 @@ vectorized: true
table: abcde@abcde_b_c_d_e_idx
spans: FULL SCAN
·
Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJy0lN9q20wQxe-_pxjmSsL74eiPnbJg2CRWqMGxUkm0KcUYWTt1BaqkrtaQEvzuRVLT2G6k1iG9MezZ_c05czB6wOpbhhy9u9v5xWwBxnQWRuG7OYP3XnDph54JoTf3riJYM0gYSAYE14F_A0aHHq8TSeDdXXm3URfbvDHhw1sv8MBIYAKWCReLKRgSJkAm-MHUC-Dy4x6JDPNC0iL-ShXyT2jhkmGpioSqqlC19NA8mMl75GcM07zc6lpeMkwKRcgfUKc6I-QYxeuMAoolqeEZMpSk4zRrxjbRRPO7Wq-SlVzRKpX3yDAs47zi8D8y9Leag7CZcJhwmRjhcsew2Oonx0rHG0Ju7djfp7pOM02K1NA6jNTqHAxh101xzmeL6M3PwoQDExCu2RnBPiXCfjH2vyzGeVExzmsW454SYZpWOs0TPXQPIwiLPa5br68kKZIcatnpdB69yHn0Cs7jTucnw21etMMO_JY1-acnz8S_IbWhkLRfDseHC0TfS-KPH4qL-RwZZvRZG8IaMGEPmHAGTLgDc6LSzZff5V__tr0eutY-P6XwgKqyyCs6Xv_ZyWf1ziQ31HZYFVuV0K0qksamPfoN1wiSKt3eWu1hlrdXdcB92OqF3X7Y7oWdftjphUf9sNsLjw9g6xgenQDbx_C4Fz4_ir3c_fcjAAD__7UbLSI=
Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJy0lN9q20wQxe-_pxjmSsL74eiPnbJg2CRWqMGxUkm0KcUYWTt1BaqkrtaQEvzuRVLT2G6k1iG9MezZ_c05czB6wOpbhhy9u9v5xWwBxnQWRuG7OYP3XnDph54JoTf3riJYM0gYSAYE14F_A0aHHq8TSeDdXXm3URfbvDHhw1sv8MBIYAKWCReLKRgSJkAm-MHUC-Dy4x6JDPNC0iL-ShXyT2jhkmGpioSqqlC19NA8mMl75GcM07zc6lpeMkwKRcgfUKc6I-QYxeuMAoolqeEZMpSk4zRrxjbRRPO7Wq-SlVzRKpX3yDAs47zi8D8y9Leag7CZcJhwmRjhcsew2Oonx0rHG0Ju7djfp7pOM02K1NA6jNTqHAxh101xzmeL6M3PwoQDExCu2RnBPiXCfjH2vyzGeVExzmsW454SYZpWOs0TPXQPIwiLPa5br68kKZIcatnpdB69yHn0Cs7jTucnw21etMMO_JY1-acnz8S_IbWhkLRfDseHC0TfS-KPH4qL-RwZZvRZG8IaMOEMmLAHTLgDc6LSzZff5V__tr0eutY-P6XwgKqyyCs6Xv_ZyWf1ziQ31HZYFVuV0K0qksamPfoN1wiSKt3eWu1hlrdXdcB92OqF3X7Y7oWdftjphUf9sNsLjw9g6xgenQDbx_C4Fz4_ir3c_fcjAAD__7UjLSI=

query T
EXPLAIN (DISTSQL,VERBOSE) SELECT * FROM (SELECT * FROM abcde EXCEPT ALL SELECT * FROM abcde) WHERE c = 1 AND d = e ORDER BY a
Expand Down Expand Up @@ -712,7 +712,7 @@ vectorized: true
·
• intersect all
│ columns: (a, b, c, d, e)
│ ordering: +b,+c,+d,+a,+e
│ ordering: +b,+d,+a,+c,+e
│ estimated row count: 1 (missing stats)
├── • filter
Expand Down Expand Up @@ -741,7 +741,7 @@ vectorized: true
table: abcde@abcde_b_c_d_e_idx
spans: FULL SCAN
·
Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJysk9uLm1AQxt_7VwzzpM2UjZdAORA42calQjZuVXqhhGA801Swao8GtoT870Ut7BqStCn7EpjLN993fsE91j9zFOh9fljM_CUYcz-Kow8Lgo9eeBtEngmRt_DexfAa7sLgHoxhmWxSxeAvYy-M2vZssYATGyZ8eu-FHhgpTMEyYbacg6FgCmxCEM69EG6_wIYgJVAETJAgYVEqXiY_uEbxFS1cEVa6TLmuS9229t2Crx5RjAmzoto1bXtFmJaaUeyxyZqcUWCcbHIOOVGsb8ZIqLhJsrw726WT3e96s07Xas3rTD0iYVQlRS3gDa4OhOWueTpfN8mWUVgH-vcId1nesGZ9Yw39-74AQzotGSGEv4zf_gEkXZiCnJhnI9jXRHhOwX4xCs5_UXBekoJ7NsKT864otWLNamC8apV_WznxjnvWW464Caobd_iS-FfFYvg9IGHO3xpD2iOSzoikOyJpjUhORuZUZ9vvp0dIGOwaAdIiaZN0SLokJ2chTK75H0Kuq7Ko-RjGycvjlgCrLfdE63KnU37QZdrZ9GXQ6bqG4rrpp1Zf-EU_agM-F1sXxe5AbB-L7Yti57Kzc4WzdSx2L4onR86rw6vfAQAA___SNa8C
Diagram: https://cockroachdb.github.io/distsqlplan/decode.html#eJysk9uLm1AQxt_7VwzzpM2UjZdAORA42calQjZuVXqhhGA801Swao8GtoT870Ut7BqStCn7EpjLN993fsE91j9zFOh9fljM_CUYcz-Kow8Lgo9eeBtEngmRt_DexfAa7sLgHoxhmWxSxeAvYy-M2vZssYATGyZ8eu-FHhgpTMEyYbacg6FgCmxCEM69EG6_wIYgJVAETJAgYVEqXiY_uEbxFS1cEVa6TLmuS9229t2Crx5RjAmzoto1bXtFmJaaUeyxyZqcUWCcbHIOOVGsb8ZIqLhJsrw726WT3e96s07Xas3rTD0iYVQlRS3gDa4OhOWueTpfN8mWUVgH-vcId1nesGZ9Yw39-74AQzotGSGEv4zf_gEkXZiCnJhnI9jXRHhOwX4xCs5_UXBekoJ7NsKT864otWLNamC8apV_WznxjnvWW464Caobd_iS-FfFYvg9IGHO3xpD2iOS7oikNSLpjEhORuZUZ9vvp0dIGOwaAdIiaZN0SLokJ2chTK75H0Kuq7Ko-RjGycvjlgCrLfdE63KnU37QZdrZ9GXQ6bqG4rrpp1Zf-EU_agM-F1sXxe5AbB-L7Yti57Kzc4WzdSx2L4onR86rw6vfAQAA___SLa8C

# Regression test for #64181. Ensure that a projection on top of an ordered
# UNION ALL correctly projects away ordering columns.
Expand Down
43 changes: 23 additions & 20 deletions pkg/sql/opt/memo/logical_props_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ func (b *logicalPropsBuilder) buildLocalityOptimizedSearchProps(
func (b *logicalPropsBuilder) buildSetProps(setNode RelExpr, rel *props.Relational) {
BuildSharedProps(setNode, &rel.Shared)

op := setNode.Op()
leftProps := setNode.Child(0).(RelExpr).Relational()
rightProps := setNode.Child(1).(RelExpr).Relational()
setPrivate := setNode.Private().(*SetPrivate)
Expand Down Expand Up @@ -720,12 +721,7 @@ func (b *logicalPropsBuilder) buildSetProps(setNode RelExpr, rel *props.Relation

// Functional Dependencies
// -----------------------
switch setNode.Op() {
case opt.UnionOp, opt.IntersectOp, opt.ExceptOp:
// These operators eliminate duplicates, so a strict key exists.
rel.FuncDeps.AddStrictKey(rel.OutputCols, rel.OutputCols)
}
switch setNode.Op() {
switch op {
case opt.UnionOp, opt.UnionAllOp, opt.LocalityOptimizedSearchOp:
// If columns at ordinals (i, j) are equivalent in both the left input
// and right input, then the output columns at ordinals at (i, j) are
Expand All @@ -738,27 +734,34 @@ func (b *logicalPropsBuilder) buildSetProps(setNode RelExpr, rel *props.Relation
}
}
}

case opt.IntersectOp, opt.IntersectAllOp, opt.ExceptOp, opt.ExceptAllOp:
// Intersect, IntersectAll, Except and ExceptAll only output rows from
// the left input, so if columns at ordinals (i, j) are equivalent in
// the left input, then they are equivalent in the output.
// TODO(mgartner): The entire FD set on the left side can be used, but
// columns may need to be mapped. Intersections can combine FD
// information from both the left and the right.
for i := range setPrivate.OutCols {
for j := i + 1; j < len(setPrivate.OutCols); j++ {
if leftProps.FuncDeps.AreColsEquiv(setPrivate.LeftCols[i], setPrivate.LeftCols[j]) {
rel.FuncDeps.AddEquivalency(setPrivate.OutCols[i], setPrivate.OutCols[j])
}
}
// With these operators, the output is a subset of the left input, so all
// the left FDs still hold (similar to a Select).
rel.FuncDeps.RemapFrom(&leftProps.FuncDeps, setPrivate.LeftCols, setPrivate.OutCols)

if op == opt.IntersectOp || op == opt.IntersectAllOp {
// With Intersect operators, the output is also a subset of the right input,
// so all the right FDs apply as well.
var remapped props.FuncDepSet
remapped.RemapFrom(&rightProps.FuncDeps, setPrivate.RightCols, setPrivate.OutCols)
rel.FuncDeps.AddFrom(&remapped)
}
}

// Add a strict key for variants that eliminate duplicates.
switch op {
case opt.UnionOp, opt.IntersectOp, opt.ExceptOp:
rel.FuncDeps.AddStrictKey(rel.OutputCols, rel.OutputCols)
}

// Cardinality
// -----------
// Calculate cardinality of the set operator.
rel.Cardinality = b.makeSetCardinality(
setNode.Op(), leftProps.Cardinality, rightProps.Cardinality)
rel.Cardinality = b.makeSetCardinality(op, leftProps.Cardinality, rightProps.Cardinality)
if rel.FuncDeps.HasMax1Row() {
rel.Cardinality = rel.Cardinality.Limit(1)
}

// Statistics
// ----------
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/opt/memo/statistics_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1851,8 +1851,8 @@ func (sb *statisticsBuilder) colStatSetNodeImpl(
s := &relProps.Stats
setPrivate := setNode.Private().(*SetPrivate)

leftCols := opt.TranslateColSet(outputCols, setPrivate.OutCols, setPrivate.LeftCols)
rightCols := opt.TranslateColSet(outputCols, setPrivate.OutCols, setPrivate.RightCols)
leftCols := opt.TranslateColSetStrict(outputCols, setPrivate.OutCols, setPrivate.LeftCols)
rightCols := opt.TranslateColSetStrict(outputCols, setPrivate.OutCols, setPrivate.RightCols)
leftColStat := sb.colStatFromChild(leftCols, setNode, 0 /* childIdx */)
rightColStat := sb.colStatFromChild(rightCols, setNode, 1 /* childIdx */)

Expand Down Expand Up @@ -2356,7 +2356,7 @@ func (sb *statisticsBuilder) colStatWithScan(

// Calculate the corresponding col stat in the bound expression and convert
// the result.
inColSet := opt.TranslateColSet(colSet, withScan.OutCols, withScan.InCols)
inColSet := opt.TranslateColSetStrict(colSet, withScan.OutCols, withScan.InCols)
inColStat := sb.colStat(inColSet, boundExpr)

colStat, _ := s.ColStats.Add(colSet)
Expand Down
12 changes: 8 additions & 4 deletions pkg/sql/opt/memo/testdata/logprops/set
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ intersect
├── columns: x:1(int!null) y:2(int) x:1(int!null)
├── left columns: x:1(int!null) y:2(int) x:1(int!null)
├── right columns: v:6(int) u:5(int) rowid:7(int)
├── key: (1,2)
├── key: (1)
├── fd: ()-->(2)
├── interesting orderings: (+1)
├── project
│ ├── columns: x:1(int!null) y:2(int)
Expand Down Expand Up @@ -92,7 +93,8 @@ except
├── columns: x:1(int!null) x:1(int!null) y:2(int)
├── left columns: x:1(int!null) x:1(int!null) y:2(int)
├── right columns: u:5(int) v:6(int) v:6(int)
├── key: (1,2)
├── key: (1)
├── fd: (1)-->(2)
├── interesting orderings: (+1)
├── project
│ ├── columns: x:1(int!null) y:2(int)
Expand Down Expand Up @@ -489,7 +491,8 @@ intersect-all
├── columns: a:1(int!null) b:2(int) c:3(int)
├── left columns: a:1(int!null) b:2(int) c:3(int)
├── right columns: a:6(int) b:7(int) c:8(int)
├── fd: (1)==(3), (3)==(1)
├── key: (1)
├── fd: (1)==(2,3), (3)==(1,2), (2)==(1,3)
├── interesting orderings: (+1)
├── select
│ ├── columns: a:1(int!null) b:2(int) c:3(int!null)
Expand Down Expand Up @@ -541,7 +544,8 @@ except-all
├── columns: a:1(int!null) b:2(int) c:3(int)
├── left columns: a:1(int!null) b:2(int) c:3(int)
├── right columns: a:6(int) b:7(int) c:8(int)
├── fd: (1)==(3), (3)==(1)
├── key: (1)
├── fd: (1)-->(2), (1)==(3), (3)==(1)
├── interesting orderings: (+1)
├── select
│ ├── columns: a:1(int!null) b:2(int) c:3(int!null)
Expand Down
Loading

0 comments on commit a61f01d

Please sign in to comment.