Skip to content

Commit

Permalink
Merge pull request cockroachdb#88581 from yuzefovich/backport21.2-88530
Browse files Browse the repository at this point in the history
release-21.2: colbuilder: avoid some allocations
  • Loading branch information
yuzefovich authored Sep 26, 2022
2 parents 33122bd + 6a0a5ec commit 53b90e9
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions pkg/sql/colexec/colbuilder/execplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func supportedNatively(spec *execinfrapb.ProcessorSpec) error {
case spec.Core.Aggregator != nil:
for _, agg := range spec.Core.Aggregator.Aggregations {
if agg.FilterColIdx != nil {
return errors.Newf("filtering aggregation not supported")
return errFilteringAggregation
}
}
return nil
Expand All @@ -212,13 +212,13 @@ func supportedNatively(spec *execinfrapb.ProcessorSpec) error {

case spec.Core.HashJoiner != nil:
if !spec.Core.HashJoiner.OnExpr.Empty() && spec.Core.HashJoiner.Type != descpb.InnerJoin {
return errors.Newf("can't plan vectorized non-inner hash joins with ON expressions")
return errNonInnerHashJoinWithOnExpr
}
return nil

case spec.Core.MergeJoiner != nil:
if !spec.Core.MergeJoiner.OnExpr.Empty() && spec.Core.MergeJoiner.Type != descpb.InnerJoin {
return errors.Errorf("can't plan non-inner merge join with ON expressions")
return errNonInnerMergeJoinWithOnExpr
}
return nil

Expand All @@ -228,11 +228,11 @@ func supportedNatively(spec *execinfrapb.ProcessorSpec) error {
case spec.Core.Windower != nil:
for _, wf := range spec.Core.Windower.WindowFns {
if wf.FilterColIdx != tree.NoColumnIdx {
return errors.Newf("window functions with FILTER clause are not supported")
return errWindowFunctionFilterClause
}
if wf.Func.AggregateFunc != nil {
if !colexecagg.IsAggOptimized(*wf.Func.AggregateFunc) {
return errors.Newf("default aggregate window functions not supported")
return errDefaultAggregateWindowFunction
}
}
}
Expand Down Expand Up @@ -266,6 +266,11 @@ var (
errWrappedCast = errors.New("mismatched types in NewColOperator and unsupported casts")
errLookupJoinUnsupported = errors.New("lookup join reader is unsupported in vectorized")
errInterleavedIndexJoin = errors.New("vectorized join reader is unsupported for interleaved indexes")
errFilteringAggregation = errors.New("filtering aggregation not supported")
errNonInnerHashJoinWithOnExpr = errors.New("can't plan vectorized non-inner hash joins with ON expressions")
errNonInnerMergeJoinWithOnExpr = errors.New("can't plan vectorized non-inner merge joins with ON expressions")
errWindowFunctionFilterClause = errors.New("window functions with FILTER clause are not supported")
errDefaultAggregateWindowFunction = errors.New("default aggregate window functions not supported")
)

func canWrap(mode sessiondatapb.VectorizeExecMode, spec *execinfrapb.ProcessorSpec) error {
Expand Down Expand Up @@ -1689,6 +1694,8 @@ var renderWrappingRenderCountThreshold = settings.RegisterIntSetting(
settings.NonNegativeInt,
)

var errFallbackToRenderWrapping = errors.New("falling back to wrapping a row-by-row processor due to many renders and low estimated row count")

// planPostProcessSpec plans the post processing stage specified in post on top
// of r.Op.
func (r *postProcessResult) planPostProcessSpec(
Expand Down Expand Up @@ -1727,10 +1734,7 @@ func (r *postProcessResult) planPostProcessSpec(
for _, expr := range exprs {
tree.WalkExpr(&v, expr)
if v.renderCount >= renderCountThreshold {
return errors.Newf(
"falling back to wrapping a row-by-row processor for at least "+
"%d renders, estimated row count = %d", v.renderCount, estimatedRowCount,
)
return errFallbackToRenderWrapping
}
}
}
Expand Down Expand Up @@ -2372,6 +2376,8 @@ func planProjectionOperators(
}
}

var errMixedTypeUnsupported = errors.New("dates and timestamp(tz) not supported in mixed-type expressions in the vectorized engine")

func checkSupportedProjectionExpr(left, right tree.TypedExpr) error {
leftTyp := left.ResolvedType()
rightTyp := right.ResolvedType()
Expand All @@ -2384,19 +2390,20 @@ func checkSupportedProjectionExpr(left, right tree.TypedExpr) error {
for _, t := range []*types.T{leftTyp, rightTyp} {
switch t.Family() {
case types.DateFamily, types.TimestampFamily, types.TimestampTZFamily:
return errors.New("dates and timestamp(tz) not supported in mixed-type expressions in the vectorized engine")
return errMixedTypeUnsupported
}
}
return nil
}

var errBinaryExprWithDatums = errors.New("datum-backed arguments on both sides and not datum-backed output of a binary expression is currently not supported")

func checkSupportedBinaryExpr(left, right tree.TypedExpr, outputType *types.T) error {
leftDatumBacked := typeconv.TypeFamilyToCanonicalTypeFamily(left.ResolvedType().Family()) == typeconv.DatumVecCanonicalTypeFamily
rightDatumBacked := typeconv.TypeFamilyToCanonicalTypeFamily(right.ResolvedType().Family()) == typeconv.DatumVecCanonicalTypeFamily
outputDatumBacked := typeconv.TypeFamilyToCanonicalTypeFamily(outputType.Family()) == typeconv.DatumVecCanonicalTypeFamily
if (leftDatumBacked && rightDatumBacked) && !outputDatumBacked {
return errors.New("datum-backed arguments on both sides and not datum-backed " +
"output of a binary expression is currently not supported")
return errBinaryExprWithDatums
}
return nil
}
Expand Down

0 comments on commit 53b90e9

Please sign in to comment.