diff --git a/go/test/endtoend/cluster/cluster_util.go b/go/test/endtoend/cluster/cluster_util.go index 1134e51d40d..e6863de19ff 100644 --- a/go/test/endtoend/cluster/cluster_util.go +++ b/go/test/endtoend/cluster/cluster_util.go @@ -113,7 +113,7 @@ func VerifyRowsInTablet(t *testing.T, vttablet *Vttablet, ksName string, expecte } // PanicHandler handles the panic in the testcase. -func PanicHandler(t *testing.T) { +func PanicHandler(t testing.TB) { err := recover() if t == nil { return diff --git a/go/test/endtoend/utils/cmp.go b/go/test/endtoend/utils/cmp.go index a377ed777c8..3811dcc0e41 100644 --- a/go/test/endtoend/utils/cmp.go +++ b/go/test/endtoend/utils/cmp.go @@ -30,12 +30,17 @@ import ( "vitess.io/vitess/go/test/utils" ) +type TestingT interface { + require.TestingT + Helper() +} + type MySQLCompare struct { - t *testing.T + t TestingT MySQLConn, VtConn *mysql.Conn } -func NewMySQLCompare(t *testing.T, vtParams, mysqlParams mysql.ConnParams) (MySQLCompare, error) { +func NewMySQLCompare(t TestingT, vtParams, mysqlParams mysql.ConnParams) (MySQLCompare, error) { ctx := context.Background() vtConn, err := mysql.Connect(ctx, &vtParams) if err != nil { @@ -54,6 +59,10 @@ func NewMySQLCompare(t *testing.T, vtParams, mysqlParams mysql.ConnParams) (MySQ }, nil } +func (mcmp *MySQLCompare) AsT() *testing.T { + return mcmp.t.(*testing.T) +} + func (mcmp *MySQLCompare) Close() { mcmp.VtConn.Close() mcmp.MySQLConn.Close() diff --git a/go/test/endtoend/utils/mysql.go b/go/test/endtoend/utils/mysql.go index 5b6b226f131..2310a2ea194 100644 --- a/go/test/endtoend/utils/mysql.go +++ b/go/test/endtoend/utils/mysql.go @@ -21,7 +21,6 @@ import ( "fmt" "os" "path" - "testing" "github.com/stretchr/testify/assert" @@ -132,16 +131,16 @@ func prepareMySQLWithSchema(params mysql.ConnParams, sql string) error { return nil } -func compareVitessAndMySQLResults(t *testing.T, query string, vtQr, mysqlQr *sqltypes.Result, compareColumns bool) { +func compareVitessAndMySQLResults(t TestingT, query string, vtQr, mysqlQr *sqltypes.Result, compareColumns bool) { if vtQr == nil && mysqlQr == nil { return } if vtQr == nil { - t.Error("Vitess result is 'nil' while MySQL's is not.") + t.Errorf("Vitess result is 'nil' while MySQL's is not.") return } if mysqlQr == nil { - t.Error("MySQL result is 'nil' while Vitess' is not.") + t.Errorf("MySQL result is 'nil' while Vitess' is not.") return } if compareColumns { @@ -163,7 +162,7 @@ func compareVitessAndMySQLResults(t *testing.T, query string, vtQr, mysqlQr *sql } stmt, err := sqlparser.Parse(query) if err != nil { - t.Error(err) + t.Errorf(err.Error()) return } orderBy := false @@ -185,13 +184,12 @@ func compareVitessAndMySQLResults(t *testing.T, query string, vtQr, mysqlQr *sql for _, row := range mysqlQr.Rows { errStr += fmt.Sprintf("%s\n", row) } - t.Error(errStr) + t.Errorf(errStr) } -func compareVitessAndMySQLErrors(t *testing.T, vtErr, mysqlErr error) { +func compareVitessAndMySQLErrors(t TestingT, vtErr, mysqlErr error) { if vtErr != nil && mysqlErr != nil || vtErr == nil && mysqlErr == nil { return } - out := fmt.Sprintf("Vitess and MySQL are not erroring the same way.\nVitess error: %v\nMySQL error: %v", vtErr, mysqlErr) - t.Error(out) + t.Errorf("Vitess and MySQL are not erroring the same way.\nVitess error: %v\nMySQL error: %v", vtErr, mysqlErr) } diff --git a/go/test/endtoend/utils/utils.go b/go/test/endtoend/utils/utils.go index ce10c723c15..bd1e7af64bd 100644 --- a/go/test/endtoend/utils/utils.go +++ b/go/test/endtoend/utils/utils.go @@ -138,7 +138,7 @@ func ExecCompareMySQL(t *testing.T, vtConn, mysqlConn *mysql.Conn, query string) // ExecAllowError executes the given query without failing the test if it produces // an error. The error is returned to the client, along with the result set. -func ExecAllowError(t *testing.T, conn *mysql.Conn, query string) (*sqltypes.Result, error) { +func ExecAllowError(t TestingT, conn *mysql.Conn, query string) (*sqltypes.Result, error) { t.Helper() return conn.ExecuteFetch(query, 1000, true) } diff --git a/go/test/endtoend/vtgate/gen4/gen4_test.go b/go/test/endtoend/vtgate/gen4/gen4_test.go index fc1e53c9a37..89b38bf6ce5 100644 --- a/go/test/endtoend/vtgate/gen4/gen4_test.go +++ b/go/test/endtoend/vtgate/gen4/gen4_test.go @@ -495,3 +495,15 @@ func TestFilterOnLeftOuterJoin(t *testing.T) { mcmp.AssertMatches(query, "[[INT32(22)] [INT32(33)]]") } + +func BenchmarkCountStar(b *testing.B) { + mcmp, closer := start(b) + defer closer() + + // insert some data. + mcmp.Exec(`insert into t2(id, tcol1, tcol2) values (1, 'A%B', 'A%B'),(2, 'C_D', 'E'),(3, 'AB', 'C1D'),(4, 'E', 'A%B'),(5, 'A%B', 'AB'),(6, 'C1D', 'E'),(7, 'C_D', 'A%B'),(8, 'E', 'C_D')`) + + for i := 0; i < b.N; i++ { + mcmp.Exec(`select Count(*) from t2`) + } +} diff --git a/go/test/endtoend/vtgate/gen4/main_test.go b/go/test/endtoend/vtgate/gen4/main_test.go index cc50cbba40a..0f26e257ba0 100644 --- a/go/test/endtoend/vtgate/gen4/main_test.go +++ b/go/test/endtoend/vtgate/gen4/main_test.go @@ -135,7 +135,7 @@ func TestMain(m *testing.M) { os.Exit(exitCode) } -func start(t *testing.T) (utils.MySQLCompare, func()) { +func start(t testing.TB) (utils.MySQLCompare, func()) { mcmp, err := utils.NewMySQLCompare(t, vtParams, mysqlParams) require.NoError(t, err) deleteAll := func() { diff --git a/go/vt/sqlparser/ast.go b/go/vt/sqlparser/ast.go index 686aa4ea089..629f2d672dc 100644 --- a/go/vt/sqlparser/ast.go +++ b/go/vt/sqlparser/ast.go @@ -2707,6 +2707,34 @@ type ( } CountStar struct { + Name string + _ bool + // TL;DR; This makes sure that reference equality checks works as expected + // + // You're correct that this might seem a bit strange at first glance. + // It's a quirk of Go's handling of empty structs. In Go, two instances of an empty struct are considered + // identical, which can be problematic when using these as keys in maps. + // They would be treated as the same key and potentially lead to incorrect map behavior. + // + // Here's a brief example: + // + // ```golang + // func TestWeirdGo(t *testing.T) { + // type CountStar struct{} + // + // cs1 := &CountStar{} + // cs2 := &CountStar{} + // if cs1 == cs2 { + // panic("what the what!?") + // } + // } + // ``` + // + // In the above code, cs1 and cs2, despite being distinct variables, would be treated as the same object. + // + // The solution we employed was to add a dummy field `_ bool` to the otherwise empty struct `CountStar`. + // This ensures that each instance of `CountStar` is treated as a separate object, + // even in the context of out semantic state which uses these objects as map keys. } Avg struct { diff --git a/go/vt/sqlparser/ast_equals.go b/go/vt/sqlparser/ast_equals.go index c4631140588..51d414bcfef 100644 --- a/go/vt/sqlparser/ast_equals.go +++ b/go/vt/sqlparser/ast_equals.go @@ -2073,7 +2073,7 @@ func EqualsRefOfCountStar(a, b *CountStar) bool { if a == nil || b == nil { return false } - return true + return a.Name == b.Name } // EqualsRefOfCreateDatabase does deep equals between the two objects. diff --git a/go/vt/sqlparser/ast_equals_test.go b/go/vt/sqlparser/ast_equals_test.go new file mode 100644 index 00000000000..a13f22cb9bf --- /dev/null +++ b/go/vt/sqlparser/ast_equals_test.go @@ -0,0 +1,29 @@ +package sqlparser + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestCountStarEqualsRefOfCountStar(t *testing.T) { + { + a := &CountStar{} + b := &CountStar{} + assert.True(t, EqualsRefOfCountStar(a, b)) + } + { + a := &CountStar{Name: "a"} + b := &CountStar{Name: "a"} + assert.True(t, EqualsRefOfCountStar(a, b)) + } + { + a := &CountStar{Name: "a"} + b := &CountStar{Name: "b"} + assert.False(t, EqualsRefOfCountStar(a, b)) + } + { + a := &CountStar{Name: "a"} + assert.False(t, EqualsRefOfCountStar(a, nil)) + } +} diff --git a/go/vt/sqlparser/ast_format.go b/go/vt/sqlparser/ast_format.go index e94a1b24ab4..f2d35169419 100644 --- a/go/vt/sqlparser/ast_format.go +++ b/go/vt/sqlparser/ast_format.go @@ -2656,7 +2656,11 @@ func (node *Count) Format(buf *TrackedBuffer) { } func (node *CountStar) Format(buf *TrackedBuffer) { - buf.astPrintf(node, "%s(", node.AggrName()) + name := node.AggrName() + if node.Name != "" { + name = node.Name + } + buf.astPrintf(node, "%s(", name) buf.WriteString("*)") } diff --git a/go/vt/sqlparser/ast_format_fast.go b/go/vt/sqlparser/ast_format_fast.go index f8483506e9f..636be927129 100644 --- a/go/vt/sqlparser/ast_format_fast.go +++ b/go/vt/sqlparser/ast_format_fast.go @@ -3482,7 +3482,11 @@ func (node *Count) formatFast(buf *TrackedBuffer) { } func (node *CountStar) formatFast(buf *TrackedBuffer) { - buf.WriteString(node.AggrName()) + name := node.AggrName() + if node.Name != "" { + name = node.Name + } + buf.WriteString(name) buf.WriteByte('(') buf.WriteString("*)") } diff --git a/go/vt/sqlparser/ast_format_fast_test.go b/go/vt/sqlparser/ast_format_fast_test.go new file mode 100644 index 00000000000..365ceb3f8b5 --- /dev/null +++ b/go/vt/sqlparser/ast_format_fast_test.go @@ -0,0 +1,28 @@ +package sqlparser + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestCountStarFormatFast(t *testing.T) { + { + buf := NewTrackedBuffer(nil) + node := &CountStar{} + node.formatFast(buf) + assert.Equal(t, &ParsedQuery{Query: "count(*)"}, buf.ParsedQuery()) + } + { + buf := NewTrackedBuffer(nil) + node := &CountStar{Name: "Count"} + node.formatFast(buf) + assert.Equal(t, &ParsedQuery{Query: "Count(*)"}, buf.ParsedQuery()) + } + { + buf := NewTrackedBuffer(nil) + node := &CountStar{Name: "COUNT"} + node.formatFast(buf) + assert.Equal(t, &ParsedQuery{Query: "COUNT(*)"}, buf.ParsedQuery()) + } +} diff --git a/go/vt/sqlparser/ast_format_test.go b/go/vt/sqlparser/ast_format_test.go new file mode 100644 index 00000000000..e09ba7f4b5c --- /dev/null +++ b/go/vt/sqlparser/ast_format_test.go @@ -0,0 +1,28 @@ +package sqlparser + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestCountStarFormat(t *testing.T) { + { + buf := NewTrackedBuffer(nil) + node := &CountStar{} + node.Format(buf) + assert.Equal(t, &ParsedQuery{Query: "count(*)"}, buf.ParsedQuery()) + } + { + buf := NewTrackedBuffer(nil) + node := &CountStar{Name: "Count"} + node.Format(buf) + assert.Equal(t, &ParsedQuery{Query: "Count(*)"}, buf.ParsedQuery()) + } + { + buf := NewTrackedBuffer(nil) + node := &CountStar{Name: "COUNT"} + node.Format(buf) + assert.Equal(t, &ParsedQuery{Query: "COUNT(*)"}, buf.ParsedQuery()) + } +} diff --git a/go/vt/sqlparser/cached_size.go b/go/vt/sqlparser/cached_size.go index e818a18e8ab..7f729276aa8 100644 --- a/go/vt/sqlparser/cached_size.go +++ b/go/vt/sqlparser/cached_size.go @@ -878,6 +878,18 @@ func (cached *Count) CachedSize(alloc bool) int64 { } return size } +func (cached *CountStar) CachedSize(alloc bool) int64 { + if cached == nil { + return int64(0) + } + size := int64(0) + if alloc { + size += int64(24) + } + // field Name string + size += hack.RuntimeAllocSize(int64(len(cached.Name))) + return size +} func (cached *CreateDatabase) CachedSize(alloc bool) int64 { if cached == nil { return int64(0) diff --git a/go/vt/sqlparser/parse_test.go b/go/vt/sqlparser/parse_test.go index b1e660562eb..9cef77e3ca6 100644 --- a/go/vt/sqlparser/parse_test.go +++ b/go/vt/sqlparser/parse_test.go @@ -5294,8 +5294,8 @@ func TestOne(t *testing.T) { testOne := struct { input, output string }{ - input: "", - output: "", + input: "Select Count(*) from t", + output: "select Count(*) from t", } if testOne.input == "" { return diff --git a/go/vt/sqlparser/sql.go b/go/vt/sqlparser/sql.go index b110bc8a2fc..7548d89dcc4 100644 --- a/go/vt/sqlparser/sql.go +++ b/go/vt/sqlparser/sql.go @@ -17102,7 +17102,7 @@ yydefault: var yyLOCAL Expr //line sql.y:5757 { - yyLOCAL = &CountStar{} + yyLOCAL = &CountStar{Name: yyDollar[1].str} } yyVAL.union = yyLOCAL case 1116: diff --git a/go/vt/sqlparser/sql.y b/go/vt/sqlparser/sql.y index 345f3a0582d..89dba256c81 100644 --- a/go/vt/sqlparser/sql.y +++ b/go/vt/sqlparser/sql.y @@ -5755,7 +5755,7 @@ UTC_DATE func_paren_opt } | COUNT openb '*' closeb { - $$ = &CountStar{} + $$ = &CountStar{Name: $1} } | COUNT openb distinct_opt expression_list closeb { diff --git a/go/vt/sqlparser/testdata/select_cases.txt b/go/vt/sqlparser/testdata/select_cases.txt index 849dba354e4..dd3fa44e61d 100644 --- a/go/vt/sqlparser/testdata/select_cases.txt +++ b/go/vt/sqlparser/testdata/select_cases.txt @@ -2438,7 +2438,7 @@ INPUT select Case When Count(*) < MAX_REQ Then 1 Else 0 End from t1 where t1.USR_ID = 1 group by MAX_REQ; END OUTPUT -select case when count(*) < MAX_REQ then 1 else 0 end from t1 where t1.USR_ID = 1 group by MAX_REQ +select case when Count(*) < MAX_REQ then 1 else 0 end from t1 where t1.USR_ID = 1 group by MAX_REQ END INPUT select t1.*,t2.* from t1 inner join t2 using (a); @@ -7220,7 +7220,7 @@ INPUT select userid,count(*) from t1 group by userid having 3 IN (1,COUNT(*)) order by userid desc; END OUTPUT -select userid, count(*) from t1 group by userid having 3 in (1, count(*)) order by userid desc +select userid, count(*) from t1 group by userid having 3 in (1, COUNT(*)) order by userid desc END INPUT select count(distinct t) from t1; diff --git a/go/vt/sqlparser/testdata/union_cases.txt b/go/vt/sqlparser/testdata/union_cases.txt index 0f74e8a3cda..57a42cac2be 100644 --- a/go/vt/sqlparser/testdata/union_cases.txt +++ b/go/vt/sqlparser/testdata/union_cases.txt @@ -338,7 +338,7 @@ INPUT (SELECT a FROM t1 ORDER BY COUNT(*) LIMIT 1) UNION ALL SELECT a FROM t1; END OUTPUT -(select a from t1 order by count(*) asc limit 1) union all select a from t1 +(select a from t1 order by COUNT(*) asc limit 1) union all select a from t1 END INPUT SELECT ST_AsText(ST_Union(ST_GEOMFROMTEXT( 'GEOMETRYCOLLECTION(POLYGON((0 0, 3 0, 3 3, 0 3, 0 0)), LINESTRING(3 1, 4 1))'), ST_GEOMFROMTEXT('GEOMETRYCOLLECTION()'))) as result; @@ -452,7 +452,7 @@ INPUT (SELECT a FROM t1 ORDER BY COUNT(*)) UNION ALL SELECT a FROM t1; END OUTPUT -(select a from t1 order by count(*) asc) union all select a from t1 +(select a from t1 order by COUNT(*) asc) union all select a from t1 END INPUT (SELECT * FROM t1 LIMIT 5 OFFSET 4) UNION ALL (SELECT * FROM t2 LIMIT 4 OFFSET 2) LIMIT 7 OFFSET 1; @@ -524,7 +524,7 @@ INPUT SELECT a FROM t1 UNION (SELECT a FROM t1 ORDER BY COUNT(*)); END OUTPUT -select a from t1 union (select a from t1 order by count(*) asc) +select a from t1 union (select a from t1 order by COUNT(*) asc) END INPUT select min(`col002`) from t1 union select `col002` from t1; @@ -746,7 +746,7 @@ INPUT (SELECT a FROM t1 ORDER BY COUNT(*) LIMIT 1) UNION SELECT a FROM t1; END OUTPUT -(select a from t1 order by count(*) asc limit 1) union select a from t1 +(select a from t1 order by COUNT(*) asc limit 1) union select a from t1 END INPUT select * from t1 union select * from t2 order by 1 limit 1; @@ -794,7 +794,7 @@ INPUT (SELECT a FROM t1 ORDER BY COUNT(*)) UNION SELECT a FROM t1; END OUTPUT -(select a from t1 order by count(*) asc) union select a from t1 +(select a from t1 order by COUNT(*) asc) union select a from t1 END INPUT select 1 union select 1; @@ -836,7 +836,7 @@ INPUT SELECT a FROM t1 UNION (SELECT a FROM t1 ORDER BY COUNT(*) LIMIT 1 OFFSET 1); END OUTPUT -select a from t1 union (select a from t1 order by count(*) asc limit 1, 1) +select a from t1 union (select a from t1 order by COUNT(*) asc limit 1, 1) END INPUT (SELECT * FROM t1 LIMIT 5) UNION SELECT * FROM t2 LIMIT 8; @@ -908,7 +908,7 @@ INPUT (SELECT a FROM t1 ORDER BY COUNT(*) LIMIT 1) UNION (SELECT a FROM t1 ORDER BY COUNT(*) LIMIT 1 OFFSET 1); END OUTPUT -(select a from t1 order by count(*) asc limit 1) union (select a from t1 order by count(*) asc limit 1, 1) +(select a from t1 order by COUNT(*) asc limit 1) union (select a from t1 order by COUNT(*) asc limit 1, 1) END INPUT SELECT 2 as "my_col" UNION SELECT 1; @@ -974,7 +974,7 @@ INPUT SELECT a FROM t1 UNION ALL (SELECT a FROM t1 ORDER BY COUNT(*) LIMIT 1 OFFSET 1); END OUTPUT -select a from t1 union all (select a from t1 order by count(*) asc limit 1, 1) +select a from t1 union all (select a from t1 order by COUNT(*) asc limit 1, 1) END INPUT (SELECT p1 FROM v2 LEFT JOIN v1 ON b = a WHERE p2 = 1 GROUP BY p1 ORDER BY p1) UNION (SELECT NULL LIMIT 0); @@ -1106,7 +1106,7 @@ INPUT (SELECT a FROM t1 ORDER BY COUNT(*) LIMIT 1) UNION ALL (SELECT a FROM t1 ORDER BY COUNT(*) LIMIT 1 OFFSET 1); END OUTPUT -(select a from t1 order by count(*) asc limit 1) union all (select a from t1 order by count(*) asc limit 1, 1) +(select a from t1 order by COUNT(*) asc limit 1) union all (select a from t1 order by COUNT(*) asc limit 1, 1) END INPUT select 'a' union select concat('a', -(4 + 1)); @@ -1208,7 +1208,7 @@ INPUT (SELECT a FROM t1 ORDER BY COUNT(*)) UNION ALL (SELECT a FROM t1 ORDER BY COUNT(*)); END OUTPUT -(select a from t1 order by count(*) asc) union all (select a from t1 order by count(*) asc) +(select a from t1 order by COUNT(*) asc) union all (select a from t1 order by COUNT(*) asc) END INPUT select 1 as a union all select 1 union all select 2 union select 1 union all select 2; @@ -1280,7 +1280,7 @@ INPUT SELECT a FROM t1 UNION ALL (SELECT a FROM t1 ORDER BY COUNT(*)); END OUTPUT -select a from t1 union all (select a from t1 order by count(*) asc) +select a from t1 union all (select a from t1 order by COUNT(*) asc) END INPUT SELECT ST_ASTEXT(ST_UNION(ST_GEOMFROMTEXT('MULTIPOLYGON(((-7 -9,-3 7,0 -10,-6 5,10 10,-3 -4,7 9,2 -9)),((1 -10,-3 10,-2 5)))'), ST_GEOMFROMTEXT('POLYGON((6 10,-7 10,-1 -6,0 5,5 4,1 -9,1 3,-10 -7,-10 8))'))) as result; @@ -1418,7 +1418,7 @@ INPUT (SELECT a FROM t1 ORDER BY COUNT(*)) UNION (SELECT a FROM t1 ORDER BY COUNT(*)); END OUTPUT -(select a from t1 order by count(*) asc) union (select a from t1 order by count(*) asc) +(select a from t1 order by COUNT(*) asc) union (select a from t1 order by COUNT(*) asc) END INPUT SELECT GROUP_CONCAT(t.c) as c FROM t1 t UNION SELECT '' as c; diff --git a/go/vt/vtgate/executor_select_test.go b/go/vt/vtgate/executor_select_test.go index a44d85cc3da..497d2af57e0 100644 --- a/go/vt/vtgate/executor_select_test.go +++ b/go/vt/vtgate/executor_select_test.go @@ -122,7 +122,7 @@ func TestSelectDBA(t *testing.T) { query, map[string]*querypb.BindVariable{}, ) require.NoError(t, err) - wantQueries = []*querypb.BoundQuery{{Sql: "select count(*) from INFORMATION_SCHEMA.`TABLES` as ist where ist.table_schema = :__vtschemaname and ist.table_name = :ist_table_name", + wantQueries = []*querypb.BoundQuery{{Sql: "select COUNT(*) from INFORMATION_SCHEMA.`TABLES` as ist where ist.table_schema = :__vtschemaname and ist.table_name = :ist_table_name", BindVariables: map[string]*querypb.BindVariable{ "__vtschemaname": sqltypes.StringBindVariable("performance_schema"), "ist_table_name": sqltypes.StringBindVariable("foo"), @@ -475,7 +475,7 @@ func TestGen4SelectDBA(t *testing.T) { query, map[string]*querypb.BindVariable{}, ) require.NoError(t, err) - wantQueries = []*querypb.BoundQuery{{Sql: "select count(*) from INFORMATION_SCHEMA.`TABLES` as ist where ist.table_schema = :__vtschemaname and ist.table_name = :ist_table_name", + wantQueries = []*querypb.BoundQuery{{Sql: "select COUNT(*) from INFORMATION_SCHEMA.`TABLES` as ist where ist.table_schema = :__vtschemaname and ist.table_name = :ist_table_name", BindVariables: map[string]*querypb.BindVariable{ "vtg1": sqltypes.StringBindVariable("performance_schema"), "vtg2": sqltypes.StringBindVariable("foo"), diff --git a/go/vt/vtgate/planbuilder/select.go b/go/vt/vtgate/planbuilder/select.go index 77ecd41be07..ee63d977fad 100644 --- a/go/vt/vtgate/planbuilder/select.go +++ b/go/vt/vtgate/planbuilder/select.go @@ -301,7 +301,7 @@ func buildSQLCalcFoundRowsPlan( sel2.Limit = nil countStartExpr := []sqlparser.SelectExpr{&sqlparser.AliasedExpr{ - Expr: &sqlparser.CountStar{}, + Expr: &sqlparser.CountStar{Name: "count"}, }} if sel2.GroupBy == nil && sel2.Having == nil { // if there is no grouping, we can use the same query and diff --git a/go/vt/vtgate/planbuilder/testdata/systemtables_cases57.json b/go/vt/vtgate/planbuilder/testdata/systemtables_cases57.json index a056ca24fec..2df7d77661e 100644 --- a/go/vt/vtgate/planbuilder/testdata/systemtables_cases57.json +++ b/go/vt/vtgate/planbuilder/testdata/systemtables_cases57.json @@ -914,8 +914,8 @@ "Name": "main", "Sharded": false }, - "FieldQuery": "select count(*) from INFORMATION_SCHEMA.`TABLES` where 1 != 1", - "Query": "select count(*) from INFORMATION_SCHEMA.`TABLES` where table_schema = :__vtschemaname and table_name = :table_name", + "FieldQuery": "select COUNT(*) from INFORMATION_SCHEMA.`TABLES` where 1 != 1", + "Query": "select COUNT(*) from INFORMATION_SCHEMA.`TABLES` where table_schema = :__vtschemaname and table_name = :table_name", "SysTableTableName": "[table_name:VARCHAR(\"foo\")]", "SysTableTableSchema": "[VARCHAR(\"performance_schema\")]", "Table": "INFORMATION_SCHEMA.`TABLES`" @@ -931,8 +931,8 @@ "Name": "main", "Sharded": false }, - "FieldQuery": "select count(*) from INFORMATION_SCHEMA.`TABLES` where 1 != 1", - "Query": "select count(*) from INFORMATION_SCHEMA.`TABLES` where table_schema = :__vtschemaname and table_name = :table_name", + "FieldQuery": "select COUNT(*) from INFORMATION_SCHEMA.`TABLES` where 1 != 1", + "Query": "select COUNT(*) from INFORMATION_SCHEMA.`TABLES` where table_schema = :__vtschemaname and table_name = :table_name", "SysTableTableName": "[table_name:VARCHAR(\"foo\")]", "SysTableTableSchema": "[VARCHAR(\"performance_schema\")]", "Table": "INFORMATION_SCHEMA.`TABLES`" diff --git a/go/vt/vtgate/planbuilder/testdata/systemtables_cases80.json b/go/vt/vtgate/planbuilder/testdata/systemtables_cases80.json index 41b30d32151..bff63461f0b 100644 --- a/go/vt/vtgate/planbuilder/testdata/systemtables_cases80.json +++ b/go/vt/vtgate/planbuilder/testdata/systemtables_cases80.json @@ -938,8 +938,8 @@ "Name": "main", "Sharded": false }, - "FieldQuery": "select count(*) from INFORMATION_SCHEMA.`TABLES` where 1 != 1", - "Query": "select count(*) from INFORMATION_SCHEMA.`TABLES` where table_schema = :__vtschemaname and table_name = :table_name", + "FieldQuery": "select COUNT(*) from INFORMATION_SCHEMA.`TABLES` where 1 != 1", + "Query": "select COUNT(*) from INFORMATION_SCHEMA.`TABLES` where table_schema = :__vtschemaname and table_name = :table_name", "SysTableTableName": "[table_name:VARCHAR(\"foo\")]", "SysTableTableSchema": "[VARCHAR(\"performance_schema\")]", "Table": "INFORMATION_SCHEMA.`TABLES`" @@ -955,8 +955,8 @@ "Name": "main", "Sharded": false }, - "FieldQuery": "select count(*) from INFORMATION_SCHEMA.`TABLES` where 1 != 1", - "Query": "select count(*) from INFORMATION_SCHEMA.`TABLES` where table_schema = :__vtschemaname and table_name = :table_name", + "FieldQuery": "select COUNT(*) from INFORMATION_SCHEMA.`TABLES` where 1 != 1", + "Query": "select COUNT(*) from INFORMATION_SCHEMA.`TABLES` where table_schema = :__vtschemaname and table_name = :table_name", "SysTableTableName": "[table_name:VARCHAR(\"foo\")]", "SysTableTableSchema": "[VARCHAR(\"performance_schema\")]", "Table": "INFORMATION_SCHEMA.`TABLES`"