From 1d712a9e4d0cd5cbc24a2ab205698d22d2b7e1ae Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Wed, 22 Sep 2021 17:12:52 +0200 Subject: [PATCH] Fixed regression for grouping by integer functions The regression in the linked issue was found to be occurring from adding weight_string function due to order by as introduced in #7678. MySQL does not support the generated query - ```sql select ascii(val1) as a, count(*), weight_string(ascii(val1)) from aggr_test group by a order by a asc ``` In order to fix this, we also add the weight_string function to the group by clause as follows - ``` select ascii(val1) as a, count(*), weight_string(ascii(val1)) from aggr_test group by a, weight_string(ascii(val1)) order by a asc ``` Co-authored-by: Manan Gupta Signed-off-by: Andres Taylor --- go/vt/vtgate/endtoend/aggr_test.go | 30 ++++++ go/vt/vtgate/engine/cached_size.go | 10 +- go/vt/vtgate/engine/ordered_aggregate.go | 3 + go/vt/vtgate/engine/route.go | 3 + go/vt/vtgate/executor_select_test.go | 4 +- go/vt/vtgate/planbuilder/concatenate.go | 2 +- go/vt/vtgate/planbuilder/grouping.go | 2 + go/vt/vtgate/planbuilder/join.go | 6 +- go/vt/vtgate/planbuilder/join2.go | 2 +- go/vt/vtgate/planbuilder/logical_plan.go | 14 +-- go/vt/vtgate/planbuilder/memory_sort.go | 12 +-- go/vt/vtgate/planbuilder/merge_sort.go | 7 +- go/vt/vtgate/planbuilder/ordered_aggregate.go | 6 +- go/vt/vtgate/planbuilder/ordering.go | 36 +++++-- go/vt/vtgate/planbuilder/postprocess.go | 11 ++- go/vt/vtgate/planbuilder/pullout_subquery.go | 4 +- go/vt/vtgate/planbuilder/route.go | 32 ++++--- .../vtgate/planbuilder/sql_calc_found_rows.go | 2 +- .../planbuilder/testdata/aggr_cases.txt | 96 +++++++++---------- .../testdata/memory_sort_cases.txt | 24 ++--- go/vt/vtgate/planbuilder/vindex_func.go | 2 +- 21 files changed, 185 insertions(+), 123 deletions(-) diff --git a/go/vt/vtgate/endtoend/aggr_test.go b/go/vt/vtgate/endtoend/aggr_test.go index b37697a72f4..ba161888815 100644 --- a/go/vt/vtgate/endtoend/aggr_test.go +++ b/go/vt/vtgate/endtoend/aggr_test.go @@ -54,4 +54,34 @@ func TestAggregateTypes(t *testing.T) { if got, want := fmt.Sprintf("%v", qr.Rows), `[[VARCHAR("c") INT64(2) INT64(2)] [VARCHAR("a") INT64(1) INT64(2)] [VARCHAR("b") INT64(1) INT64(1)] [VARCHAR("e") INT64(1) INT64(2)]]`; got != want { t.Errorf("select:\n%v want\n%v", got, want) } + + qr = exec(t, conn, "select ascii(val1) as a, count(*) from aggr_test group by a") + if got, want := fmt.Sprintf("%v", qr.Rows), `[[INT32(65) INT64(1)] [INT32(69) INT64(1)] [INT32(97) INT64(1)] [INT32(98) INT64(1)] [INT32(99) INT64(2)] [INT32(100) INT64(1)] [INT32(101) INT64(1)]]`; got != want { + t.Errorf("select:\n%v want\n%v", got, want) + } + + qr = exec(t, conn, "select ascii(val1) as a, count(*) from aggr_test group by a order by a") + if got, want := fmt.Sprintf("%v", qr.Rows), `[[INT32(65) INT64(1)] [INT32(69) INT64(1)] [INT32(97) INT64(1)] [INT32(98) INT64(1)] [INT32(99) INT64(2)] [INT32(100) INT64(1)] [INT32(101) INT64(1)]]`; got != want { + t.Errorf("select:\n%v want\n%v", got, want) + } + + qr = exec(t, conn, "select ascii(val1) as a, count(*) from aggr_test group by a order by 2, a") + if got, want := fmt.Sprintf("%v", qr.Rows), `[[INT32(65) INT64(1)] [INT32(69) INT64(1)] [INT32(97) INT64(1)] [INT32(98) INT64(1)] [INT32(100) INT64(1)] [INT32(101) INT64(1)] [INT32(99) INT64(2)]]`; got != want { + t.Errorf("select:\n%v want\n%v", got, want) + } + + qr = exec(t, conn, "select val1 as a, count(*) from aggr_test group by a") + if got, want := fmt.Sprintf("%v", qr.Rows), `[[VARCHAR("a") INT64(2)] [VARCHAR("b") INT64(1)] [VARCHAR("c") INT64(2)] [VARCHAR("d") INT64(1)] [VARCHAR("e") INT64(2)]]`; got != want { + t.Errorf("select:\n%v want\n%v", got, want) + } + + qr = exec(t, conn, "select val1 as a, count(*) from aggr_test group by a order by a") + if got, want := fmt.Sprintf("%v", qr.Rows), `[[VARCHAR("a") INT64(2)] [VARCHAR("b") INT64(1)] [VARCHAR("c") INT64(2)] [VARCHAR("d") INT64(1)] [VARCHAR("e") INT64(2)]]`; got != want { + t.Errorf("select:\n%v want\n%v", got, want) + } + + qr = exec(t, conn, "select val1 as a, count(*) from aggr_test group by a order by 2, a") + if got, want := fmt.Sprintf("%v", qr.Rows), `[[VARCHAR("b") INT64(1)] [VARCHAR("d") INT64(1)] [VARCHAR("a") INT64(2)] [VARCHAR("c") INT64(2)] [VARCHAR("e") INT64(2)]]`; got != want { + t.Errorf("select:\n%v want\n%v", got, want) + } } diff --git a/go/vt/vtgate/engine/cached_size.go b/go/vt/vtgate/engine/cached_size.go index 27ae3fb9540..56a1a4b5bdb 100644 --- a/go/vt/vtgate/engine/cached_size.go +++ b/go/vt/vtgate/engine/cached_size.go @@ -307,7 +307,7 @@ func (cached *MemorySort) CachedSize(alloc bool) int64 { size += cached.UpperLimit.CachedSize(false) // field OrderBy []vitess.io/vitess/go/vt/vtgate/engine.OrderbyParams { - size += int64(cap(cached.OrderBy)) * int64(17) + size += int64(cap(cached.OrderBy)) * int64(18) } // field Input vitess.io/vitess/go/vt/vtgate/engine.Primitive if cc, ok := cached.Input.(cachedObject); ok { @@ -334,7 +334,7 @@ func (cached *MergeSort) CachedSize(alloc bool) int64 { } // field OrderBy []vitess.io/vitess/go/vt/vtgate/engine.OrderbyParams { - size += int64(cap(cached.OrderBy)) * int64(17) + size += int64(cap(cached.OrderBy)) * int64(18) } return size } @@ -366,7 +366,7 @@ func (cached *OrderedAggregate) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(80) + size += int64(104) } // field Aggregates []vitess.io/vitess/go/vt/vtgate/engine.AggregateParams { @@ -379,6 +379,8 @@ func (cached *OrderedAggregate) CachedSize(alloc bool) int64 { { size += int64(cap(cached.Keys)) * int64(8) } + // field FromGroupBy []bool + size += int64(cap(cached.FromGroupBy)) // field Input vitess.io/vitess/go/vt/vtgate/engine.Primitive if cc, ok := cached.Input.(cachedObject); ok { size += cc.CachedSize(true) @@ -550,7 +552,7 @@ func (cached *Route) CachedSize(alloc bool) int64 { } // field OrderBy []vitess.io/vitess/go/vt/vtgate/engine.OrderbyParams { - size += int64(cap(cached.OrderBy)) * int64(17) + size += int64(cap(cached.OrderBy)) * int64(18) } // field SysTableTableSchema vitess.io/vitess/go/vt/vtgate/evalengine.Expr if cc, ok := cached.SysTableTableSchema.(cachedObject); ok { diff --git a/go/vt/vtgate/engine/ordered_aggregate.go b/go/vt/vtgate/engine/ordered_aggregate.go index 803a4223a32..7342b966401 100644 --- a/go/vt/vtgate/engine/ordered_aggregate.go +++ b/go/vt/vtgate/engine/ordered_aggregate.go @@ -48,6 +48,9 @@ type OrderedAggregate struct { // the aggregation key. Keys []int + // Keeps track if the keys above were added because of GroupBy or not + FromGroupBy []bool + // TruncateColumnCount specifies the number of columns to return // in the final result. Rest of the columns are truncated // from the result received. If 0, no truncation happens. diff --git a/go/vt/vtgate/engine/route.go b/go/vt/vtgate/engine/route.go index b77d8c115b3..def766b5df4 100644 --- a/go/vt/vtgate/engine/route.go +++ b/go/vt/vtgate/engine/route.go @@ -130,6 +130,9 @@ type OrderbyParams struct { // It is set to -1 if such a column is not added to the query WeightStringCol int Desc bool + + // v3 specific boolean. Used to also add weight strings originating from GroupBys to the Group by clause + FromGroupBy bool } func (obp OrderbyParams) String() string { diff --git a/go/vt/vtgate/executor_select_test.go b/go/vt/vtgate/executor_select_test.go index 6f25dc460bc..46ddd05343e 100644 --- a/go/vt/vtgate/executor_select_test.go +++ b/go/vt/vtgate/executor_select_test.go @@ -1430,7 +1430,7 @@ func TestSelectScatterAggregate(t *testing.T) { require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "select col, sum(foo), weight_string(col) from `user` group by col order by col asc", + Sql: "select col, sum(foo), weight_string(col) from `user` group by col, weight_string(col) order by col asc", BindVariables: map[string]*querypb.BindVariable{}, }} for _, conn := range conns { @@ -1489,7 +1489,7 @@ func TestStreamSelectScatterAggregate(t *testing.T) { require.NoError(t, err) wantQueries := []*querypb.BoundQuery{{ - Sql: "select col, sum(foo), weight_string(col) from `user` group by col order by col asc", + Sql: "select col, sum(foo), weight_string(col) from `user` group by col, weight_string(col) order by col asc", BindVariables: map[string]*querypb.BindVariable{}, }} for _, conn := range conns { diff --git a/go/vt/vtgate/planbuilder/concatenate.go b/go/vt/vtgate/planbuilder/concatenate.go index b482e795845..95abc21529a 100644 --- a/go/vt/vtgate/planbuilder/concatenate.go +++ b/go/vt/vtgate/planbuilder/concatenate.go @@ -70,7 +70,7 @@ func (c *concatenate) SupplyCol(col *sqlparser.ColName) (rc *resultColumn, colNu panic("implement me") } -func (c *concatenate) SupplyWeightString(colNumber int) (weightcolNumber int, err error) { +func (c *concatenate) SupplyWeightString(int, bool) (weightcolNumber int, err error) { panic("implement me") } diff --git a/go/vt/vtgate/planbuilder/grouping.go b/go/vt/vtgate/planbuilder/grouping.go index 49324a0e8bb..c228d9196d9 100644 --- a/go/vt/vtgate/planbuilder/grouping.go +++ b/go/vt/vtgate/planbuilder/grouping.go @@ -77,6 +77,7 @@ func planGroupBy(pb *primitiveBuilder, input logicalPlan, groupBy sqlparser.Grou return nil, vterrors.New(vtrpcpb.Code_UNIMPLEMENTED, "unsupported: in scatter query: only simple references allowed") } node.eaggr.Keys = append(node.eaggr.Keys, colNumber) + node.eaggr.FromGroupBy = append(node.eaggr.FromGroupBy, true) } // Append the distinct aggregate if any. if node.extraDistinct != nil { @@ -110,6 +111,7 @@ func planDistinct(input logicalPlan) (logicalPlan, error) { return newDistinct(node), nil } node.eaggr.Keys = append(node.eaggr.Keys, i) + node.eaggr.FromGroupBy = append(node.eaggr.FromGroupBy, false) } newInput, err := planDistinct(node.input) if err != nil { diff --git a/go/vt/vtgate/planbuilder/join.go b/go/vt/vtgate/planbuilder/join.go index 29b30d4c718..e3f688c07eb 100644 --- a/go/vt/vtgate/planbuilder/join.go +++ b/go/vt/vtgate/planbuilder/join.go @@ -212,20 +212,20 @@ func (jb *join) SupplyCol(col *sqlparser.ColName) (rc *resultColumn, colNumber i } // SupplyWeightString implements the logicalPlan interface -func (jb *join) SupplyWeightString(colNumber int) (weightcolNumber int, err error) { +func (jb *join) SupplyWeightString(colNumber int, alsoAddToGroupBy bool) (weightcolNumber int, err error) { rc := jb.resultColumns[colNumber] if weightcolNumber, ok := jb.weightStrings[rc]; ok { return weightcolNumber, nil } routeNumber := rc.column.Origin().Order() if jb.isOnLeft(routeNumber) { - sourceCol, err := jb.Left.SupplyWeightString(-jb.ejoin.Cols[colNumber] - 1) + sourceCol, err := jb.Left.SupplyWeightString(-jb.ejoin.Cols[colNumber]-1, alsoAddToGroupBy) if err != nil { return 0, err } jb.ejoin.Cols = append(jb.ejoin.Cols, -sourceCol-1) } else { - sourceCol, err := jb.Right.SupplyWeightString(jb.ejoin.Cols[colNumber] - 1) + sourceCol, err := jb.Right.SupplyWeightString(jb.ejoin.Cols[colNumber]-1, alsoAddToGroupBy) if err != nil { return 0, err } diff --git a/go/vt/vtgate/planbuilder/join2.go b/go/vt/vtgate/planbuilder/join2.go index 7b273c88865..88cd66e7f6a 100644 --- a/go/vt/vtgate/planbuilder/join2.go +++ b/go/vt/vtgate/planbuilder/join2.go @@ -73,7 +73,7 @@ func (j *joinV4) SupplyCol(col *sqlparser.ColName) (rc *resultColumn, colNumber } // SupplyWeightString implements the logicalPlan interface -func (j *joinV4) SupplyWeightString(colNumber int) (weightcolNumber int, err error) { +func (j *joinV4) SupplyWeightString(int, bool) (weightcolNumber int, err error) { panic("implement me") } diff --git a/go/vt/vtgate/planbuilder/logical_plan.go b/go/vt/vtgate/planbuilder/logical_plan.go index 81e4fae0aa2..a62036371f5 100644 --- a/go/vt/vtgate/planbuilder/logical_plan.go +++ b/go/vt/vtgate/planbuilder/logical_plan.go @@ -70,7 +70,7 @@ type logicalPlan interface { // SupplyWeightString must supply a weight_string expression of the // specified column. It returns an error if we cannot supply a weight column for it. - SupplyWeightString(colNumber int) (weightcolNumber int, err error) + SupplyWeightString(colNumber int, alsoAddToGroupBy bool) (weightcolNumber int, err error) // Primitive returns the underlying primitive. // This function should only be called after Wireup is finished. @@ -170,8 +170,8 @@ func (bc *logicalPlanCommon) SupplyCol(col *sqlparser.ColName) (rc *resultColumn return bc.input.SupplyCol(col) } -func (bc *logicalPlanCommon) SupplyWeightString(colNumber int) (weightcolNumber int, err error) { - return bc.input.SupplyWeightString(colNumber) +func (bc *logicalPlanCommon) SupplyWeightString(colNumber int, alsoAddToGroupBy bool) (weightcolNumber int, err error) { + return bc.input.SupplyWeightString(colNumber, alsoAddToGroupBy) } // Rewrite implements the logicalPlan interface @@ -239,12 +239,14 @@ func (rsb *resultsBuilder) SupplyCol(col *sqlparser.ColName) (rc *resultColumn, return rc, colNumber } -func (rsb *resultsBuilder) SupplyWeightString(colNumber int) (weightcolNumber int, err error) { +func (rsb *resultsBuilder) SupplyWeightString(colNumber int, alsoAddToGroupBy bool) (weightcolNumber int, err error) { rc := rsb.resultColumns[colNumber] - if weightcolNumber, ok := rsb.weightStrings[rc]; ok { + var ok bool + weightcolNumber, ok = rsb.weightStrings[rc] + if !alsoAddToGroupBy && ok { return weightcolNumber, nil } - weightcolNumber, err = rsb.input.SupplyWeightString(colNumber) + weightcolNumber, err = rsb.input.SupplyWeightString(colNumber, alsoAddToGroupBy) if err != nil { return 0, nil } diff --git a/go/vt/vtgate/planbuilder/memory_sort.go b/go/vt/vtgate/planbuilder/memory_sort.go index 1f96ed47d5e..c34c41882cd 100644 --- a/go/vt/vtgate/planbuilder/memory_sort.go +++ b/go/vt/vtgate/planbuilder/memory_sort.go @@ -40,7 +40,7 @@ type memorySort struct { } // newMemorySort builds a new memorySort. -func newMemorySort(plan logicalPlan, orderBy sqlparser.OrderBy) (*memorySort, error) { +func newMemorySort(plan logicalPlan, orderBy v3OrderBy) (*memorySort, error) { eMemorySort := &engine.MemorySort{} ms := &memorySort{ resultsBuilder: newResultsBuilder(plan, eMemorySort), @@ -113,15 +113,9 @@ func (ms *memorySort) Wireup(plan logicalPlan, jt *jointab) error { rc := ms.resultColumns[orderby.Col] // Add a weight_string column if we know that the column is a textual column or if its type is unknown if sqltypes.IsText(rc.column.typ) || rc.column.typ == sqltypes.Null { - // If a weight string was previously requested, reuse it. - if weightcolNumber, ok := ms.weightStrings[rc]; ok { - ms.eMemorySort.OrderBy[i].WeightStringCol = weightcolNumber - continue - } - weightcolNumber, err := ms.input.SupplyWeightString(orderby.Col) + weightcolNumber, err := ms.input.SupplyWeightString(orderby.Col, orderby.FromGroupBy) if err != nil { - _, isUnsupportedErr := err.(UnsupportedSupplyWeightString) - if isUnsupportedErr { + if _, isUnsupportedErr := err.(UnsupportedSupplyWeightString); isUnsupportedErr { continue } return err diff --git a/go/vt/vtgate/planbuilder/merge_sort.go b/go/vt/vtgate/planbuilder/merge_sort.go index 1fea7894cc4..3f36d436e6c 100644 --- a/go/vt/vtgate/planbuilder/merge_sort.go +++ b/go/vt/vtgate/planbuilder/merge_sort.go @@ -68,13 +68,8 @@ func (ms *mergeSort) Wireup(plan logicalPlan, jt *jointab) error { rc := ms.resultColumns[orderby.Col] // Add a weight_string column if we know that the column is a textual column or if its type is unknown if sqltypes.IsText(rc.column.typ) || rc.column.typ == sqltypes.Null { - // If a weight string was previously requested, reuse it. - if colNumber, ok := ms.weightStrings[rc]; ok { - rb.eroute.OrderBy[i].WeightStringCol = colNumber - continue - } var err error - rb.eroute.OrderBy[i].WeightStringCol, err = rb.SupplyWeightString(orderby.Col) + rb.eroute.OrderBy[i].WeightStringCol, err = rb.SupplyWeightString(orderby.Col, orderby.FromGroupBy) if err != nil { _, isUnsupportedErr := err.(UnsupportedSupplyWeightString) if isUnsupportedErr { diff --git a/go/vt/vtgate/planbuilder/ordered_aggregate.go b/go/vt/vtgate/planbuilder/ordered_aggregate.go index 82d06035b2b..b936918e246 100644 --- a/go/vt/vtgate/planbuilder/ordered_aggregate.go +++ b/go/vt/vtgate/planbuilder/ordered_aggregate.go @@ -334,11 +334,7 @@ func (oa *orderedAggregate) Wireup(plan logicalPlan, jt *jointab) error { for i, colNumber := range oa.eaggr.Keys { rc := oa.resultColumns[colNumber] if sqltypes.IsText(rc.column.typ) { - if weightcolNumber, ok := oa.weightStrings[rc]; ok { - oa.eaggr.Keys[i] = weightcolNumber - continue - } - weightcolNumber, err := oa.input.SupplyWeightString(colNumber) + weightcolNumber, err := oa.input.SupplyWeightString(colNumber, oa.eaggr.FromGroupBy[i]) if err != nil { _, isUnsupportedErr := err.(UnsupportedSupplyWeightString) if isUnsupportedErr { diff --git a/go/vt/vtgate/planbuilder/ordering.go b/go/vt/vtgate/planbuilder/ordering.go index c8c52739090..911735aa3ac 100644 --- a/go/vt/vtgate/planbuilder/ordering.go +++ b/go/vt/vtgate/planbuilder/ordering.go @@ -22,7 +22,14 @@ import ( "vitess.io/vitess/go/vt/vtgate/engine" ) -func planOrdering(pb *primitiveBuilder, input logicalPlan, orderBy sqlparser.OrderBy) (logicalPlan, error) { +type v3Order struct { + *sqlparser.Order + fromGroupBy bool +} + +type v3OrderBy []*v3Order + +func planOrdering(pb *primitiveBuilder, input logicalPlan, orderBy v3OrderBy) (logicalPlan, error) { switch node := input.(type) { case *subquery, *vindexFunc: if len(orderBy) == 0 { @@ -56,7 +63,7 @@ func planOrdering(pb *primitiveBuilder, input logicalPlan, orderBy sqlparser.Ord return nil, vterrors.Errorf(vtrpc.Code_INTERNAL, "[BUG] unreachable %T.ordering", input) } -func planOAOrdering(pb *primitiveBuilder, orderBy sqlparser.OrderBy, oa *orderedAggregate) (logicalPlan, error) { +func planOAOrdering(pb *primitiveBuilder, orderBy v3OrderBy, oa *orderedAggregate) (logicalPlan, error) { // The requested order must be such that the ordering can be done // before the group by, which will allow us to push it down to the // route. This is actually true in most use cases, except for situations @@ -78,7 +85,7 @@ func planOAOrdering(pb *primitiveBuilder, orderBy sqlparser.OrderBy, oa *ordered // referenced tracks the keys referenced by the order by clause. referenced := make([]bool, len(oa.eaggr.Keys)) postSort := false - selOrderBy := make(sqlparser.OrderBy, 0, len(orderBy)) + selOrderBy := make(v3OrderBy, 0, len(orderBy)) for _, order := range orderBy { // Identify the order by column. var orderByCol *column @@ -110,6 +117,7 @@ func planOAOrdering(pb *primitiveBuilder, orderBy sqlparser.OrderBy, oa *ordered found = true referenced[j] = true + order.fromGroupBy = oa.eaggr.FromGroupBy[j] selOrderBy = append(selOrderBy, order) break } @@ -128,12 +136,19 @@ func planOAOrdering(pb *primitiveBuilder, orderBy sqlparser.OrderBy, oa *ordered if err != nil { return nil, vterrors.Wrapf(err, "generating order by clause") } - selOrderBy = append(selOrderBy, &sqlparser.Order{Expr: col, Direction: sqlparser.AscOrder}) + selOrderBy = append(selOrderBy, &v3Order{ + Order: &sqlparser.Order{Expr: col, Direction: sqlparser.AscOrder}, + fromGroupBy: oa.eaggr.FromGroupBy[i], + }) } // Append the distinct aggregate if any. if oa.extraDistinct != nil { - selOrderBy = append(selOrderBy, &sqlparser.Order{Expr: oa.extraDistinct, Direction: sqlparser.AscOrder}) + el := &sqlparser.Order{Expr: oa.extraDistinct, Direction: sqlparser.AscOrder} + selOrderBy = append(selOrderBy, &v3Order{ + Order: el, + fromGroupBy: true, + }) } // Push down the order by. @@ -151,7 +166,7 @@ func planOAOrdering(pb *primitiveBuilder, orderBy sqlparser.OrderBy, oa *ordered return oa, nil } -func planJoinOrdering(pb *primitiveBuilder, orderBy sqlparser.OrderBy, node *join) (logicalPlan, error) { +func planJoinOrdering(pb *primitiveBuilder, orderBy v3OrderBy, node *join) (logicalPlan, error) { isSpecial := false switch len(orderBy) { case 0: @@ -226,7 +241,7 @@ func planJoinOrdering(pb *primitiveBuilder, orderBy sqlparser.OrderBy, node *joi return node, nil } -func planRouteOrdering(orderBy sqlparser.OrderBy, node *route) (logicalPlan, error) { +func planRouteOrdering(orderBy v3OrderBy, node *route) (logicalPlan, error) { switch len(orderBy) { case 0: return node, nil @@ -240,14 +255,14 @@ func planRouteOrdering(orderBy sqlparser.OrderBy, node *route) (logicalPlan, err } } if isSpecial { - node.Select.AddOrder(orderBy[0]) + node.Select.AddOrder(orderBy[0].Order) return node, nil } } if node.isSingleShard() { for _, order := range orderBy { - node.Select.AddOrder(order) + node.Select.AddOrder(order.Order) } return node, nil } @@ -293,10 +308,11 @@ func planRouteOrdering(orderBy sqlparser.OrderBy, node *route) (logicalPlan, err Col: colNumber, WeightStringCol: -1, Desc: order.Direction == sqlparser.DescOrder, + FromGroupBy: order.fromGroupBy, } node.eroute.OrderBy = append(node.eroute.OrderBy, ob) - node.Select.AddOrder(order) + node.Select.AddOrder(order.Order) } return newMergeSort(node), nil } diff --git a/go/vt/vtgate/planbuilder/postprocess.go b/go/vt/vtgate/planbuilder/postprocess.go index 7b925b411fa..8ce3e717b22 100644 --- a/go/vt/vtgate/planbuilder/postprocess.go +++ b/go/vt/vtgate/planbuilder/postprocess.go @@ -54,7 +54,16 @@ func (pb *primitiveBuilder) pushOrderBy(orderBy sqlparser.OrderBy) error { if err := pb.st.ResolveSymbols(orderBy); err != nil { return err } - plan, err := planOrdering(pb, pb.plan, orderBy) + + var v3OrderBylist v3OrderBy + + if orderBy != nil { + v3OrderBylist = make(v3OrderBy, 0, len(orderBy)) + for _, order := range orderBy { + v3OrderBylist = append(v3OrderBylist, &v3Order{Order: order}) + } + } + plan, err := planOrdering(pb, pb.plan, v3OrderBylist) if err != nil { return err } diff --git a/go/vt/vtgate/planbuilder/pullout_subquery.go b/go/vt/vtgate/planbuilder/pullout_subquery.go index ec0862bcf0d..40393db86c2 100644 --- a/go/vt/vtgate/planbuilder/pullout_subquery.go +++ b/go/vt/vtgate/planbuilder/pullout_subquery.go @@ -110,8 +110,8 @@ func (ps *pulloutSubquery) SupplyCol(col *sqlparser.ColName) (rc *resultColumn, } // SupplyWeightString implements the logicalPlan interface -func (ps *pulloutSubquery) SupplyWeightString(colNumber int) (weightcolNumber int, err error) { - return ps.underlying.SupplyWeightString(colNumber) +func (ps *pulloutSubquery) SupplyWeightString(colNumber int, alsoAddToGroupBy bool) (weightcolNumber int, err error) { + return ps.underlying.SupplyWeightString(colNumber, alsoAddToGroupBy) } // Rewrite implements the logicalPlan interface diff --git a/go/vt/vtgate/planbuilder/route.go b/go/vt/vtgate/planbuilder/route.go index 0d9dbcb70bc..946857ef3bc 100644 --- a/go/vt/vtgate/planbuilder/route.go +++ b/go/vt/vtgate/planbuilder/route.go @@ -333,11 +333,8 @@ func (rb *route) SupplyCol(col *sqlparser.ColName) (rc *resultColumn, colNumber } // SupplyWeightString implements the logicalPlan interface -func (rb *route) SupplyWeightString(colNumber int) (weightcolNumber int, err error) { +func (rb *route) SupplyWeightString(colNumber int, alsoAddToGroupBy bool) (weightcolNumber int, err error) { rc := rb.resultColumns[colNumber] - if weightcolNumber, ok := rb.weightStrings[rc]; ok { - return weightcolNumber, nil - } s, ok := rb.Select.(*sqlparser.Select) if !ok { return 0, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "unexpected AST struct for query") @@ -347,16 +344,29 @@ func (rb *route) SupplyWeightString(colNumber int) (weightcolNumber int, err err if !ok { return 0, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "unexpected AST struct for query %T", s.SelectExprs[colNumber]) } - expr := &sqlparser.AliasedExpr{ - Expr: &sqlparser.FuncExpr{ - Name: sqlparser.NewColIdent("weight_string"), - Exprs: []sqlparser.SelectExpr{ - &sqlparser.AliasedExpr{ - Expr: aliasExpr.Expr, - }, + weightStringExpr := &sqlparser.FuncExpr{ + Name: sqlparser.NewColIdent("weight_string"), + Exprs: []sqlparser.SelectExpr{ + &sqlparser.AliasedExpr{ + Expr: aliasExpr.Expr, }, }, } + if alsoAddToGroupBy { + sel, isSelect := rb.Select.(*sqlparser.Select) + if !isSelect { + return 0, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "cannot add weight string in %T", rb.Select) + } + sel.GroupBy = append(sel.GroupBy, weightStringExpr) + } + + expr := &sqlparser.AliasedExpr{ + Expr: weightStringExpr, + } + + if weightcolNumber, ok := rb.weightStrings[rc]; ok { + return weightcolNumber, nil + } // It's ok to pass nil for pb and logicalPlan because PushSelect doesn't use them. // TODO: we are ignoring a potential error here. need to clean this up _, _, weightcolNumber, err = planProjection(nil, rb, expr, nil) diff --git a/go/vt/vtgate/planbuilder/sql_calc_found_rows.go b/go/vt/vtgate/planbuilder/sql_calc_found_rows.go index 21a7bae3d29..917dc8e7a04 100644 --- a/go/vt/vtgate/planbuilder/sql_calc_found_rows.go +++ b/go/vt/vtgate/planbuilder/sql_calc_found_rows.go @@ -90,7 +90,7 @@ func (s *sqlCalcFoundRows) SupplyCol(col *sqlparser.ColName) (*resultColumn, int } //SupplyWeightString implements the logicalPlan interface -func (s *sqlCalcFoundRows) SupplyWeightString(int) (weightcolNumber int, err error) { +func (s *sqlCalcFoundRows) SupplyWeightString(int, bool) (weightcolNumber int, err error) { return 0, UnsupportedSupplyWeightString{Type: "sqlCalcFoundRows"} } diff --git a/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt b/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt index 7c76066eec1..113ab24f411 100644 --- a/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt @@ -116,9 +116,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select count(*), a, textcol1, b, weight_string(textcol1), weight_string(a), weight_string(b) from `user` where 1 != 1 group by a, textcol1, b", + "FieldQuery": "select count(*), a, textcol1, b, weight_string(textcol1), weight_string(a), weight_string(b) from `user` where 1 != 1 group by a, textcol1, b, weight_string(textcol1), weight_string(a), weight_string(textcol1), weight_string(b)", "OrderBy": "1 ASC, 2 ASC, 3 ASC", - "Query": "select count(*), a, textcol1, b, weight_string(textcol1), weight_string(a), weight_string(b) from `user` group by a, textcol1, b order by a asc, textcol1 asc, b asc", + "Query": "select count(*), a, textcol1, b, weight_string(textcol1), weight_string(a), weight_string(b) from `user` group by a, textcol1, b, weight_string(textcol1), weight_string(a), weight_string(textcol1), weight_string(b) order by a asc, textcol1 asc, b asc", "Table": "`user`" } ] @@ -177,9 +177,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select count(*) as k, a, textcol1, b, weight_string(textcol1), weight_string(a), weight_string(b) from `user` where 1 != 1 group by a, textcol1, b", + "FieldQuery": "select count(*) as k, a, textcol1, b, weight_string(textcol1), weight_string(a), weight_string(b) from `user` where 1 != 1 group by a, textcol1, b, weight_string(textcol1), weight_string(textcol1), weight_string(a), weight_string(b)", "OrderBy": "2 ASC, 1 ASC, 3 ASC", - "Query": "select count(*) as k, a, textcol1, b, weight_string(textcol1), weight_string(a), weight_string(b) from `user` group by a, textcol1, b order by textcol1 asc, a asc, b asc", + "Query": "select count(*) as k, a, textcol1, b, weight_string(textcol1), weight_string(a), weight_string(b) from `user` group by a, textcol1, b, weight_string(textcol1), weight_string(textcol1), weight_string(a), weight_string(b) order by textcol1 asc, a asc, b asc", "Table": "`user`" } ] @@ -310,9 +310,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select col1, col2, weight_string(col1), weight_string(col2) from `user` where 1 != 1 group by col1", + "FieldQuery": "select col1, col2, weight_string(col1), weight_string(col2) from `user` where 1 != 1 group by col1, weight_string(col1)", "OrderBy": "0 ASC, 1 ASC, 0 ASC", - "Query": "select distinct col1, col2, weight_string(col1), weight_string(col2) from `user` group by col1 order by col1 asc, col2 asc, col1 asc", + "Query": "select distinct col1, col2, weight_string(col1), weight_string(col2) from `user` group by col1, weight_string(col1) order by col1 asc, col2 asc, col1 asc", "Table": "`user`" } ] @@ -411,9 +411,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select col, count(*), weight_string(col) from `user` where 1 != 1 group by col", + "FieldQuery": "select col, count(*), weight_string(col) from `user` where 1 != 1 group by col, weight_string(col)", "OrderBy": "0 ASC", - "Query": "select col, count(*), weight_string(col) from `user` group by col order by col asc", + "Query": "select col, count(*), weight_string(col) from `user` group by col, weight_string(col) order by col asc", "Table": "`user`" } ] @@ -443,9 +443,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select `name`, count(*), weight_string(`name`) from `user` where 1 != 1 group by `name`", + "FieldQuery": "select `name`, count(*), weight_string(`name`) from `user` where 1 != 1 group by `name`, weight_string(`name`)", "OrderBy": "0 ASC", - "Query": "select `name`, count(*), weight_string(`name`) from `user` group by `name` order by `name` asc", + "Query": "select `name`, count(*), weight_string(`name`) from `user` group by `name`, weight_string(`name`) order by `name` asc", "Table": "`user`" } ] @@ -651,9 +651,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select col, weight_string(col) from `user` where 1 != 1 group by col", + "FieldQuery": "select col, weight_string(col) from `user` where 1 != 1 group by col, weight_string(col)", "OrderBy": "0 ASC", - "Query": "select col, weight_string(col) from `user` group by col order by col asc", + "Query": "select col, weight_string(col) from `user` group by col, weight_string(col) order by col asc", "Table": "`user`" } ] @@ -697,9 +697,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select col, count(distinct id), weight_string(col) from `user` where 1 != 1 group by col", + "FieldQuery": "select col, count(distinct id), weight_string(col) from `user` where 1 != 1 group by col, weight_string(col)", "OrderBy": "0 ASC", - "Query": "select col, count(distinct id), weight_string(col) from `user` group by col order by col asc", + "Query": "select col, count(distinct id), weight_string(col) from `user` group by col, weight_string(col) order by col asc", "Table": "`user`" } ] @@ -725,9 +725,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select col1, col2, weight_string(col1), weight_string(col2) from `user` where 1 != 1 group by col1, col2", + "FieldQuery": "select col1, col2, weight_string(col1), weight_string(col2) from `user` where 1 != 1 group by col1, col2, weight_string(col1), weight_string(col2)", "OrderBy": "0 ASC, 1 ASC", - "Query": "select col1, col2, weight_string(col1), weight_string(col2) from `user` group by col1, col2 order by col1 asc, col2 asc", + "Query": "select col1, col2, weight_string(col1), weight_string(col2) from `user` group by col1, col2, weight_string(col1), weight_string(col2) order by col1 asc, col2 asc", "Table": "`user`" } ] @@ -752,9 +752,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select col2, weight_string(col2) from `user` where 1 != 1 group by col2", + "FieldQuery": "select col2, weight_string(col2) from `user` where 1 != 1 group by col2, weight_string(col2)", "OrderBy": "0 ASC", - "Query": "select col2, weight_string(col2) from `user` group by col2 order by col2 asc", + "Query": "select col2, weight_string(col2) from `user` group by col2, weight_string(col2) order by col2 asc", "Table": "`user`" } ] @@ -780,9 +780,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select col1, col2, weight_string(col1), weight_string(col2) from `user` where 1 != 1 group by col1, col2", + "FieldQuery": "select col1, col2, weight_string(col1), weight_string(col2) from `user` where 1 != 1 group by col1, col2, weight_string(col1), weight_string(col2)", "OrderBy": "0 ASC, 1 ASC", - "Query": "select col1, col2, weight_string(col1), weight_string(col2) from `user` group by col1, col2 order by col1 asc, col2 asc", + "Query": "select col1, col2, weight_string(col1), weight_string(col2) from `user` group by col1, col2, weight_string(col1), weight_string(col2) order by col1 asc, col2 asc", "Table": "`user`" } ] @@ -808,9 +808,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select col1, col2, weight_string(col1), weight_string(col2) from `user` where 1 != 1 group by col1, col2", + "FieldQuery": "select col1, col2, weight_string(col1), weight_string(col2) from `user` where 1 != 1 group by col1, col2, weight_string(col1), weight_string(col2)", "OrderBy": "0 ASC, 1 ASC", - "Query": "select col1, col2, weight_string(col1), weight_string(col2) from `user` group by col1, col2 order by col1 asc, col2 asc", + "Query": "select col1, col2, weight_string(col1), weight_string(col2) from `user` group by col1, col2, weight_string(col1), weight_string(col2) order by col1 asc, col2 asc", "Table": "`user`" } ] @@ -836,9 +836,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select col1, min(distinct col2), weight_string(col1) from `user` where 1 != 1 group by col1", + "FieldQuery": "select col1, min(distinct col2), weight_string(col1) from `user` where 1 != 1 group by col1, weight_string(col1)", "OrderBy": "0 ASC", - "Query": "select col1, min(distinct col2), weight_string(col1) from `user` group by col1 order by col1 asc", + "Query": "select col1, min(distinct col2), weight_string(col1) from `user` group by col1, weight_string(col1) order by col1 asc", "Table": "`user`" } ] @@ -869,9 +869,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select col1, col2, weight_string(col1), weight_string(col2) from `user` where 1 != 1 group by col1, col2", + "FieldQuery": "select col1, col2, weight_string(col1), weight_string(col2) from `user` where 1 != 1 group by col1, col2, weight_string(col1), weight_string(col2)", "OrderBy": "0 ASC, 1 ASC", - "Query": "select col1, col2, weight_string(col1), weight_string(col2) from `user` group by col1, col2 order by col1 asc, col2 asc", + "Query": "select col1, col2, weight_string(col1), weight_string(col2) from `user` group by col1, col2, weight_string(col1), weight_string(col2) order by col1 asc, col2 asc", "Table": "`user`" } ] @@ -903,9 +903,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select a, b, count(*), weight_string(b), weight_string(a) from `user` where 1 != 1 group by b, a", + "FieldQuery": "select a, b, count(*), weight_string(b), weight_string(a) from `user` where 1 != 1 group by b, a, weight_string(b), weight_string(a)", "OrderBy": "1 ASC, 0 ASC", - "Query": "select a, b, count(*), weight_string(b), weight_string(a) from `user` group by b, a order by b asc, a asc", + "Query": "select a, b, count(*), weight_string(b), weight_string(a) from `user` group by b, a, weight_string(b), weight_string(a) order by b asc, a asc", "Table": "`user`" } ] @@ -931,9 +931,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select a, b, count(*), weight_string(b), weight_string(a) from `user` where 1 != 1 group by 2, 1", + "FieldQuery": "select a, b, count(*), weight_string(b), weight_string(a) from `user` where 1 != 1 group by 2, 1, weight_string(b), weight_string(a)", "OrderBy": "1 ASC, 0 ASC", - "Query": "select a, b, count(*), weight_string(b), weight_string(a) from `user` group by 2, 1 order by b asc, a asc", + "Query": "select a, b, count(*), weight_string(b), weight_string(a) from `user` group by 2, 1, weight_string(b), weight_string(a) order by b asc, a asc", "Table": "`user`" } ] @@ -959,9 +959,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select a, b, count(*), weight_string(b), weight_string(a) from `user` where 1 != 1 group by b, a", + "FieldQuery": "select a, b, count(*), weight_string(b), weight_string(a) from `user` where 1 != 1 group by b, a, weight_string(b), weight_string(a)", "OrderBy": "1 ASC, 0 ASC", - "Query": "select a, b, count(*), weight_string(b), weight_string(a) from `user` group by b, a order by b asc, a asc", + "Query": "select a, b, count(*), weight_string(b), weight_string(a) from `user` group by b, a, weight_string(b), weight_string(a) order by b asc, a asc", "Table": "`user`" } ] @@ -986,9 +986,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select col, weight_string(col) from `user` where 1 != 1 group by 1", + "FieldQuery": "select col, weight_string(col) from `user` where 1 != 1 group by 1, weight_string(col)", "OrderBy": "0 ASC", - "Query": "select col, weight_string(col) from `user` group by 1 order by col asc", + "Query": "select col, weight_string(col) from `user` group by 1, weight_string(col) order by col asc", "Table": "`user`" } ] @@ -1048,9 +1048,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select a, b, c, d, count(*), weight_string(a), weight_string(b), weight_string(c) from `user` where 1 != 1 group by 1, 2, 3", + "FieldQuery": "select a, b, c, d, count(*), weight_string(a), weight_string(b), weight_string(c) from `user` where 1 != 1 group by 1, 2, 3, weight_string(a), weight_string(b), weight_string(c)", "OrderBy": "0 ASC, 1 ASC, 2 ASC", - "Query": "select a, b, c, d, count(*), weight_string(a), weight_string(b), weight_string(c) from `user` group by 1, 2, 3 order by 1 asc, 2 asc, 3 asc", + "Query": "select a, b, c, d, count(*), weight_string(a), weight_string(b), weight_string(c) from `user` group by 1, 2, 3, weight_string(a), weight_string(b), weight_string(c) order by 1 asc, 2 asc, 3 asc", "Table": "`user`" } ] @@ -1076,9 +1076,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select a, b, c, d, count(*), weight_string(a), weight_string(b), weight_string(c) from `user` where 1 != 1 group by 1, 2, 3", + "FieldQuery": "select a, b, c, d, count(*), weight_string(a), weight_string(b), weight_string(c) from `user` where 1 != 1 group by 1, 2, 3, weight_string(a), weight_string(b), weight_string(c)", "OrderBy": "0 ASC, 1 ASC, 2 ASC", - "Query": "select a, b, c, d, count(*), weight_string(a), weight_string(b), weight_string(c) from `user` group by 1, 2, 3 order by a asc, b asc, c asc", + "Query": "select a, b, c, d, count(*), weight_string(a), weight_string(b), weight_string(c) from `user` group by 1, 2, 3, weight_string(a), weight_string(b), weight_string(c) order by a asc, b asc, c asc", "Table": "`user`" } ] @@ -1104,9 +1104,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select a, b, c, d, count(*), weight_string(d), weight_string(b), weight_string(a), weight_string(c) from `user` where 1 != 1 group by 1, 2, 3, 4", + "FieldQuery": "select a, b, c, d, count(*), weight_string(d), weight_string(b), weight_string(a), weight_string(c) from `user` where 1 != 1 group by 1, 2, 3, 4, weight_string(d), weight_string(b), weight_string(a), weight_string(c)", "OrderBy": "3 ASC, 1 ASC, 0 ASC, 2 ASC", - "Query": "select a, b, c, d, count(*), weight_string(d), weight_string(b), weight_string(a), weight_string(c) from `user` group by 1, 2, 3, 4 order by d asc, b asc, a asc, c asc", + "Query": "select a, b, c, d, count(*), weight_string(d), weight_string(b), weight_string(a), weight_string(c) from `user` group by 1, 2, 3, 4, weight_string(d), weight_string(b), weight_string(a), weight_string(c) order by d asc, b asc, a asc, c asc", "Table": "`user`" } ] @@ -1132,9 +1132,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select a, b, c, d, count(*), weight_string(d), weight_string(b), weight_string(a), weight_string(c) from `user` where 1 != 1 group by 3, 2, 1, 4", + "FieldQuery": "select a, b, c, d, count(*), weight_string(d), weight_string(b), weight_string(a), weight_string(c) from `user` where 1 != 1 group by 3, 2, 1, 4, weight_string(d), weight_string(b), weight_string(a), weight_string(c)", "OrderBy": "3 ASC, 1 ASC, 0 ASC, 2 ASC", - "Query": "select a, b, c, d, count(*), weight_string(d), weight_string(b), weight_string(a), weight_string(c) from `user` group by 3, 2, 1, 4 order by d asc, b asc, a asc, c asc", + "Query": "select a, b, c, d, count(*), weight_string(d), weight_string(b), weight_string(a), weight_string(c) from `user` group by 3, 2, 1, 4, weight_string(d), weight_string(b), weight_string(a), weight_string(c) order by d asc, b asc, a asc, c asc", "Table": "`user`" } ] @@ -1160,9 +1160,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select a, b, c, count(*), weight_string(a), weight_string(c), weight_string(b) from `user` where 1 != 1 group by 3, 2, 1", + "FieldQuery": "select a, b, c, count(*), weight_string(a), weight_string(c), weight_string(b) from `user` where 1 != 1 group by 3, 2, 1, weight_string(a), weight_string(c), weight_string(b)", "OrderBy": "0 DESC, 2 DESC, 1 ASC", - "Query": "select a, b, c, count(*), weight_string(a), weight_string(c), weight_string(b) from `user` group by 3, 2, 1 order by 1 desc, 3 desc, b asc", + "Query": "select a, b, c, count(*), weight_string(a), weight_string(c), weight_string(b) from `user` group by 3, 2, 1, weight_string(a), weight_string(c), weight_string(b) order by 1 desc, 3 desc, b asc", "Table": "`user`" } ] @@ -1196,9 +1196,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select col, count(*), weight_string(col) from `user` where 1 != 1 group by col", + "FieldQuery": "select col, count(*), weight_string(col) from `user` where 1 != 1 group by col, weight_string(col)", "OrderBy": "0 ASC", - "Query": "select col, count(*), weight_string(col) from `user` group by col order by col asc limit :__upper_limit", + "Query": "select col, count(*), weight_string(col) from `user` group by col, weight_string(col) order by col asc limit :__upper_limit", "Table": "`user`" } ] @@ -1322,9 +1322,9 @@ Gen4 plan same as above "Name": "user", "Sharded": true }, - "FieldQuery": "select a, count(*), weight_string(a) from `user` where 1 != 1 group by a", + "FieldQuery": "select a, count(*), weight_string(a) from `user` where 1 != 1 group by a, weight_string(a)", "OrderBy": "0 ASC, 0 ASC", - "Query": "select a, count(*), weight_string(a) from `user` group by a order by a asc, a asc", + "Query": "select a, count(*), weight_string(a) from `user` group by a, weight_string(a) order by a asc, a asc", "Table": "`user`" } ] diff --git a/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.txt b/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.txt index 53b22207510..72432a8347e 100644 --- a/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.txt @@ -23,9 +23,9 @@ "Name": "user", "Sharded": true }, - "FieldQuery": "select a, b, count(*), weight_string(b), weight_string(a) from `user` where 1 != 1 group by a", + "FieldQuery": "select a, b, count(*), weight_string(b), weight_string(a) from `user` where 1 != 1 group by a, weight_string(a)", "OrderBy": "0 ASC", - "Query": "select a, b, count(*), weight_string(b), weight_string(a) from `user` group by a order by a asc", + "Query": "select a, b, count(*), weight_string(b), weight_string(a) from `user` group by a, weight_string(a) order by a asc", "Table": "`user`" } ] @@ -58,9 +58,9 @@ "Name": "user", "Sharded": true }, - "FieldQuery": "select a, b, count(*) as k, weight_string(a) from `user` where 1 != 1 group by a", + "FieldQuery": "select a, b, count(*) as k, weight_string(a) from `user` where 1 != 1 group by a, weight_string(a)", "OrderBy": "0 ASC", - "Query": "select a, b, count(*) as k, weight_string(a) from `user` group by a order by a asc", + "Query": "select a, b, count(*) as k, weight_string(a) from `user` group by a, weight_string(a) order by a asc", "Table": "`user`" } ] @@ -93,9 +93,9 @@ "Name": "user", "Sharded": true }, - "FieldQuery": "select a, b, count(*) as k, weight_string(b), weight_string(a) from `user` where 1 != 1 group by a", + "FieldQuery": "select a, b, count(*) as k, weight_string(b), weight_string(a) from `user` where 1 != 1 group by a, weight_string(a)", "OrderBy": "0 ASC", - "Query": "select a, b, count(*) as k, weight_string(b), weight_string(a) from `user` group by a order by a asc", + "Query": "select a, b, count(*) as k, weight_string(b), weight_string(a) from `user` group by a, weight_string(a) order by a asc", "Table": "`user`" } ] @@ -132,9 +132,9 @@ "Name": "user", "Sharded": true }, - "FieldQuery": "select a, b, count(*) as k, weight_string(a) from `user` where 1 != 1 group by a", + "FieldQuery": "select a, b, count(*) as k, weight_string(a) from `user` where 1 != 1 group by a, weight_string(a)", "OrderBy": "0 ASC", - "Query": "select a, b, count(*) as k, weight_string(a) from `user` group by a order by a asc", + "Query": "select a, b, count(*) as k, weight_string(a) from `user` group by a, weight_string(a) order by a asc", "Table": "`user`" } ] @@ -169,9 +169,9 @@ "Name": "user", "Sharded": true }, - "FieldQuery": "select a, b, count(*) as k, weight_string(a) from `user` where 1 != 1 group by a", + "FieldQuery": "select a, b, count(*) as k, weight_string(a) from `user` where 1 != 1 group by a, weight_string(a)", "OrderBy": "0 ASC", - "Query": "select a, b, count(*) as k, weight_string(a) from `user` group by a order by 1 asc", + "Query": "select a, b, count(*) as k, weight_string(a) from `user` group by a, weight_string(a) order by 1 asc", "Table": "`user`" } ] @@ -205,9 +205,9 @@ "Name": "user", "Sharded": true }, - "FieldQuery": "select textcol1 as t, count(*) as k, weight_string(textcol1) from `user` where 1 != 1 group by textcol1", + "FieldQuery": "select textcol1 as t, count(*) as k, weight_string(textcol1) from `user` where 1 != 1 group by textcol1, weight_string(textcol1), weight_string(textcol1), weight_string(textcol1)", "OrderBy": "0 ASC, 0 ASC", - "Query": "select textcol1 as t, count(*) as k, weight_string(textcol1) from `user` group by textcol1 order by textcol1 asc, textcol1 asc", + "Query": "select textcol1 as t, count(*) as k, weight_string(textcol1) from `user` group by textcol1, weight_string(textcol1), weight_string(textcol1), weight_string(textcol1) order by textcol1 asc, textcol1 asc", "Table": "`user`" } ] diff --git a/go/vt/vtgate/planbuilder/vindex_func.go b/go/vt/vtgate/planbuilder/vindex_func.go index 8d9a6d0a74a..b08b7002182 100644 --- a/go/vt/vtgate/planbuilder/vindex_func.go +++ b/go/vt/vtgate/planbuilder/vindex_func.go @@ -142,7 +142,7 @@ func (err UnsupportedSupplyWeightString) Error() string { } // SupplyWeightString implements the logicalPlan interface -func (vf *vindexFunc) SupplyWeightString(colNumber int) (weightcolNumber int, err error) { +func (vf *vindexFunc) SupplyWeightString(int, bool) (weightcolNumber int, err error) { return 0, UnsupportedSupplyWeightString{Type: "vindex function"} }