Commit a6a58f4b authored by craig[bot]'s avatar craig[bot]

Merge #50650 #50770 #50815 #50832

50650: colexec: do not generate some dead code r=jordanlewis a=yuzefovich

6 comparison operators that are handled by `proj_const_ops_tmpl.go` are
normalized so that the constant is always on the right side. This
renders the code for these comparison operators useless for the case
when the constant is on the left, so we omit generating it.

Release note: None

50770: roachtest: update version map and create fixtures r=jlinder a=asubiotto

This commit adds the recently released 19.1.10, 19.2.8, and 20.1.3 to the
version map in PredecessorVersion.

Release note: None (testing change)

50815: opt: fix ResolvedType() for aggregateInfo in the optbuilder r=rytaft a=rytaft

Prior to this commit, it was possible that calling `ResolvedType()`
on an `aggregateInfo` object returned the wrong type. This was because
`aggregateInfo` did not implement `ResolvedType()`, and was therefore
passing the call to the embedded `tree.FuncExpr`, which may have been
stripped of its original type information. This commit fixes the
problem by adding an implementation of `ResolvedType()` to `aggregateInfo`,
which simply returns the type of the aggregation column represented by
the struct.

Fixes #46914

Release note (bug fix): Fixed an internal error that could happen
during planning for some queries with aggregate functions embedded in
complex scalar expressions.

50832: Add [email protected] to AUTHORS r=jreut a=jreut

Release note: None
Co-authored-by: default avatarYahor Yuzefovich <[email protected]>
Co-authored-by: default avatarAlfonso Subiotto Marques <[email protected]>
Co-authored-by: default avatarRebecca Taft <[email protected]>
Co-authored-by: default avatarjordan ryan reuter <[email protected]>
......@@ -153,6 +153,7 @@ Jonas <[email protected]>
joowon <[email protected]>
Jordan Krage <[email protected]>
Jordan Lewis <[email protected]> <[email protected]> <[email protected]>
jordan ryan reuter <[email protected]>
Jorge Puente Sarrín <[email protected]>
Joseph Botros <[email protected]>
Joseph Lowinske <[email protected]>
......
......@@ -1146,9 +1146,9 @@ func PredecessorVersion(buildVersion version.Version) (string, error) {
// (see runVersionUpgrade). The same is true for adding a new key to this
// map.
verMap := map[string]string{
"20.2": "20.1.2",
"20.1": "19.2.7",
"19.2": "19.1.5",
"20.2": "20.1.3",
"20.1": "19.2.8",
"19.2": "19.1.10",
"19.1": "2.1.9",
"2.2": "2.1.9",
"2.1": "2.0.7",
......
......@@ -1574,7 +1574,7 @@ func planProjectionOperators(
case *tree.ComparisonExpr:
return planProjectionExpr(
ctx, evalCtx, t.Operator, t.ResolvedType(), t.TypedLeft(), t.TypedRight(),
columnTypes, input, acc, factory, nil,
columnTypes, input, acc, factory, nil, /* binFn */
)
case *tree.BinaryExpr:
if err = checkSupportedBinaryExpr(t.TypedLeft(), t.TypedRight(), t.ResolvedType()); err != nil {
......
This diff was suppressed by a .gitattributes entry.
......@@ -197,8 +197,17 @@ func _SET_SINGLE_TUPLE_PROJECTION(_HAS_NULLS bool) { // */}}
// {{range .RightFamilies}}
// {{range .RightWidths}}
// {{if not _IS_CONST_LEFT}}
// {{/*
// Comparison operators are always normalized so that the constant is on
// the right side, so we skip generating the code when the constant is on
// the left.
// */}}
// {{template "projConstOp" .}}
// {{end}}
// {{end}}
// {{end}}
// {{end}}
......@@ -289,6 +298,12 @@ func GetProjection_CONST_SIDEConstOperator(
}
// {{end}}
}
// {{if not _IS_CONST_LEFT}}
// {{/*
// Comparison operators are always normalized so that the constant is on
// the right side, so we skip generating the code when the constant is on
// the left.
// */}}
case tree.ComparisonOperator:
switch op {
// {{range .CmpOps}}
......@@ -308,31 +323,7 @@ func GetProjection_CONST_SIDEConstOperator(
case _RIGHT_TYPE_WIDTH:
return &_OP_CONST_NAME{
projConstOpBase: projConstOpBase,
// {{if _IS_CONST_LEFT}}
// {{if eq $leftFamilyStr "typeconv.DatumVecCanonicalTypeFamily"}}
// {{/*
// Comparison operations are evaluated using
// coldataext.Datum.CompareDatum method which requires that we
// have *coldataext.Datum on the left, so we create that at the
// operator construction time to avoid runtime conversion. Note
// that when the constant is on the right side, then the left
// element necessarily comes from the vector and will be of the
// desired type, so no additional work is needed.
// Note: although it appears as if the comparison expressions
// supported by this template (EQ, NE, LT, GT, LE, GE) are
// normalized so that the constant is on the right side, we
// choose to be safe and perform the conversion here.
// TODO(yuzefovich): this appears to be a dead code, look into
// whether we can skip generation of the code for the case when
// the constant is on the left.
// */}}
constArg: &coldataext.Datum{Datum: c.(tree.Datum)},
// {{else}}
constArg: c.(_L_GO_TYPE),
// {{end}}
// {{else}}
constArg: c.(_R_GO_TYPE),
// {{end}}
constArg: c.(_R_GO_TYPE),
}, nil
// {{end}}
}
......@@ -344,6 +335,7 @@ func GetProjection_CONST_SIDEConstOperator(
}
// {{end}}
}
// {{end}}
}
return nil, errors.Errorf("couldn't find overload for %s %s %s", leftType.Name(), op, rightType.Name())
}
......@@ -74,6 +74,12 @@ func (e *distSQLSpecExecFactory) getPlanCtx(recommendation distRecommendation) *
return e.planContexts.localPlanCtx
}
// TODO(yuzefovich): consider adding machinery that would confirm that
// assumptions that the execution makes about the plans coming from the
// optimizer are satisfied. A couple of examples are making sure that the
// constants in comparison expressions are always on the right and that the
// tuples in IN clause are sorted.
func (e *distSQLSpecExecFactory) ConstructValues(
rows [][]tree.TypedExpr, cols sqlbase.ResultColumns,
) (exec.Node, error) {
......
......@@ -270,6 +270,11 @@ func (a *aggregateInfo) Eval(_ *tree.EvalContext) (tree.Datum, error) {
panic(errors.AssertionFailedf("aggregateInfo must be replaced before evaluation"))
}
// ResolvedType is part of the tree.TypedExpr interface.
func (a *aggregateInfo) ResolvedType() *types.T {
return a.col.typ
}
var _ tree.Expr = &aggregateInfo{}
var _ tree.TypedExpr = &aggregateInfo{}
......
......@@ -3939,3 +3939,38 @@ scalar-group-by
└── aggregations
└── const-agg [as=percentile_cont:6]
└── percentile_cont:6
# Regression test for #46914.
exec-ddl
CREATE TABLE t0(c0 INT)
----
build format=(show-types,show-scalars)
SELECT * FROM t0 GROUP BY t0.c0 HAVING min((CASE WHEN false THEN NULL END):::FLOAT) IS NOT NAN
----
project
├── columns: c0:1(int)
└── select
├── columns: c0:1(int) min:4(float!null)
├── group-by
│ ├── columns: c0:1(int) min:4(float)
│ ├── grouping columns: c0:1(int)
│ ├── project
│ │ ├── columns: column3:3(float) c0:1(int)
│ │ ├── scan t0
│ │ │ └── columns: c0:1(int) rowid:2(int!null)
│ │ └── projections
│ │ └── case [as=column3:3, type=float]
│ │ ├── true [type=bool]
│ │ ├── when [type=float]
│ │ │ ├── false [type=bool]
│ │ │ └── cast: FLOAT8 [type=float]
│ │ │ └── null [type=unknown]
│ │ └── null [type=float]
│ └── aggregations
│ └── min [as=min:4, type=float]
│ └── variable: column3:3 [type=float]
└── filters
└── ne [type=bool]
├── variable: min:4 [type=float]
└── const: NaN [type=float]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment