Commit 0eedb3e1 authored by Yahor Yuzefovich's avatar Yahor Yuzefovich

colexec: do not generate some dead code

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
parent a9ff82f3
......@@ -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) {
......
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