Skip to content

Commit

Permalink
gen4: support added for ordering on vindex function
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal committed Oct 15, 2021
1 parent d09e8d1 commit 2c3adcf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
18 changes: 12 additions & 6 deletions go/vt/vtgate/planbuilder/horizon_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,12 @@ func pushProjection(expr *sqlparser.AliasedExpr, plan logicalPlan, semTable *sem
}
return 0, false, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "cannot push projections in ordered aggregates")
case *vindexFunc:
colsBefore := len(node.eVindexFunc.Cols)
i, err := node.SupplyProjection(expr, reuseCol)
if err != nil {
return 0, false, err
}
return i, true, nil
return i /* col added */, len(node.eVindexFunc.Cols) > colsBefore, nil
case *limit:
return pushProjection(expr, node.input, semTable, inner, reuseCol)
case *distinct:
Expand Down Expand Up @@ -629,9 +630,10 @@ func (hp *horizonPlanning) planOrderBy(ctx *planningContext, orderExprs []abstra
plan.input = newUnderlyingPlan
return plan, nil
case *simpleProjection:
return hp.createMemorySortPlan(ctx, plan, orderExprs)
return hp.createMemorySortPlan(ctx, plan, orderExprs, true)
case *vindexFunc:
return nil, semantics.Gen4NotSupportedF("unsupported: ordering on vindex func")
// This is evaluated at VTGate only, so weight_string function cannot be used.
return hp.createMemorySortPlan(ctx, plan, orderExprs /* useWeightStr */, false)
default:
return nil, vterrors.Errorf(vtrpcpb.Code_UNIMPLEMENTED, "ordering on complex query %T", plan)
}
Expand Down Expand Up @@ -760,7 +762,7 @@ func (hp *horizonPlanning) planOrderByForJoin(ctx *planningContext, orderExprs [
plan.Left = newLeft
return plan, nil
}
sortPlan, err := hp.createMemorySortPlan(ctx, plan, orderExprs)
sortPlan, err := hp.createMemorySortPlan(ctx, plan, orderExprs, true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -807,7 +809,7 @@ func findExprInOrderedAggr(plan *orderedAggregate, order abstract.OrderBy) (int,
return 0, 0, false
}

func (hp *horizonPlanning) createMemorySortPlan(ctx *planningContext, plan logicalPlan, orderExprs []abstract.OrderBy) (logicalPlan, error) {
func (hp *horizonPlanning) createMemorySortPlan(ctx *planningContext, plan logicalPlan, orderExprs []abstract.OrderBy, useWeightStr bool) (logicalPlan, error) {
primitive := &engine.MemorySort{}
ms := &memorySort{
resultsBuilder: resultsBuilder{
Expand All @@ -819,7 +821,11 @@ func (hp *horizonPlanning) createMemorySortPlan(ctx *planningContext, plan logic
}

for _, order := range orderExprs {
offset, weightStringOffset, added, err := wrapAndPushExpr(order.Inner.Expr, order.WeightStrExpr, plan, ctx.semTable)
wsExpr := order.WeightStrExpr
if !useWeightStr {
wsExpr = nil
}
offset, weightStringOffset, added, err := wrapAndPushExpr(order.Inner.Expr, wsExpr, plan, ctx.semTable)
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions go/vt/vtgate/planbuilder/testdata/memory_sort_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ Gen4 plan same as above
]
}
}
Gen4 plan same as above

# unary expression
"select a from user order by binary a desc"
Expand Down

0 comments on commit 2c3adcf

Please sign in to comment.