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/ordered_aggregate.go b/go/vt/vtgate/engine/ordered_aggregate.go index 9411ee1a24c..47f9aa64dad 100644 --- a/go/vt/vtgate/engine/ordered_aggregate.go +++ b/go/vt/vtgate/engine/ordered_aggregate.go @@ -49,6 +49,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 f3f169bc477..2364944d316 100644 --- a/go/vt/vtgate/engine/route.go +++ b/go/vt/vtgate/engine/route.go @@ -131,6 +131,9 @@ type OrderbyParams struct { WeightStringCol int Desc bool StarColFixedIndex int + + // 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 371df7c2acb..db07f101870 100644 --- a/go/vt/vtgate/executor_select_test.go +++ b/go/vt/vtgate/executor_select_test.go @@ -1569,7 +1569,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 { @@ -1628,7 +1628,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 93cb30d5935..adbff8f1695 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 a1b8614a64b..788942d061e 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 30f79b69060..b5c499973f8 100644 --- a/go/vt/vtgate/planbuilder/join.go +++ b/go/vt/vtgate/planbuilder/join.go @@ -210,20 +210,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/joinGen4.go b/go/vt/vtgate/planbuilder/joinGen4.go index 4339f1f2452..6da7e618a50 100644 --- a/go/vt/vtgate/planbuilder/joinGen4.go +++ b/go/vt/vtgate/planbuilder/joinGen4.go @@ -76,7 +76,7 @@ func (j *joinGen4) SupplyCol(col *sqlparser.ColName) (rc *resultColumn, colNumbe } // SupplyWeightString implements the logicalPlan interface -func (j *joinGen4) SupplyWeightString(colNumber int) (weightcolNumber int, err error) { +func (j *joinGen4) 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 00ee488a2cf..0cf87f05567 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 8f06423699f..4793edc38db 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), @@ -115,15 +115,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 76915f3b623..2646d9b2627 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 e3a82a08f47..3b7546e6feb 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 57f3b268db6..7bdb77c9f22 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 } @@ -318,10 +333,11 @@ func planRouteOrdering(orderBy sqlparser.OrderBy, node *route) (logicalPlan, err WeightStringCol: -1, Desc: order.Direction == sqlparser.DescOrder, StarColFixedIndex: starColFixedIndex, + 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 2df10473fe6..b1c0b936360 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 8b03ec852bd..68f3d0073ef 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 7d45620f2f7..4988f28f578 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 5534d20bee0..ac55baada8e 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 b109137932f..e825db92424 100644 --- a/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/aggr_cases.txt @@ -115,9 +115,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", "ResultColumns": 5, "Table": "`user`" } @@ -175,9 +175,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", "ResultColumns": 5, "Table": "`user`" } @@ -308,9 +308,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", "ResultColumns": 2, "Table": "`user`" } @@ -409,9 +409,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", "ResultColumns": 2, "Table": "`user`" } @@ -441,9 +441,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", "ResultColumns": 2, "Table": "`user`" } @@ -648,9 +648,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", "ResultColumns": 1, "Table": "`user`" } @@ -694,9 +694,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", "ResultColumns": 2, "Table": "`user`" } @@ -722,9 +722,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", "ResultColumns": 2, "Table": "`user`" } @@ -749,9 +749,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", "ResultColumns": 1, "Table": "`user`" } @@ -777,9 +777,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", "ResultColumns": 2, "Table": "`user`" } @@ -805,9 +805,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", "ResultColumns": 2, "Table": "`user`" } @@ -833,9 +833,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", "ResultColumns": 2, "Table": "`user`" } @@ -866,9 +866,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", "ResultColumns": 2, "Table": "`user`" } @@ -900,9 +900,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", "ResultColumns": 3, "Table": "`user`" } @@ -928,9 +928,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", "ResultColumns": 3, "Table": "`user`" } @@ -956,9 +956,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", "ResultColumns": 3, "Table": "`user`" } @@ -983,9 +983,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", "ResultColumns": 1, "Table": "`user`" } @@ -1044,9 +1044,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", "ResultColumns": 5, "Table": "`user`" } @@ -1072,9 +1072,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", "ResultColumns": 5, "Table": "`user`" } @@ -1100,9 +1100,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", "ResultColumns": 5, "Table": "`user`" } @@ -1128,9 +1128,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", "ResultColumns": 5, "Table": "`user`" } @@ -1156,9 +1156,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", "ResultColumns": 4, "Table": "`user`" } @@ -1192,9 +1192,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", "ResultColumns": 2, "Table": "`user`" } @@ -1319,9 +1319,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", "ResultColumns": 2, "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 5b256260111..7aa3b665160 100644 --- a/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/memory_sort_cases.txt @@ -22,9 +22,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", "ResultColumns": 4, "Table": "`user`" } @@ -57,9 +57,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", "ResultColumns": 3, "Table": "`user`" } @@ -92,9 +92,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", "ResultColumns": 5, "Table": "`user`" } @@ -131,9 +131,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", "ResultColumns": 3, "Table": "`user`" } @@ -168,9 +168,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", "ResultColumns": 4, "Table": "`user`" } @@ -204,9 +204,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", "ResultColumns": 3, "Table": "`user`" } diff --git a/go/vt/vtgate/planbuilder/vindex_func.go b/go/vt/vtgate/planbuilder/vindex_func.go index 217c0fc8c46..e3c5f19319a 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"} }