From 529c16be8a836d42afe2b6b1b4872cb40f8489f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Taylor?= Date: Wed, 27 Mar 2024 14:42:42 +0100 Subject: [PATCH 01/18] chore: use interface instead of struct for tests (#15581) --- go/test/endtoend/utils/cmp.go | 13 +++++++++++-- go/test/endtoend/utils/mysql.go | 8 +++----- go/test/endtoend/utils/utils.go | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) 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..b8ac2b9680c 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,7 +131,7 @@ 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 } @@ -188,10 +187,9 @@ func compareVitessAndMySQLResults(t *testing.T, query string, vtQr, mysqlQr *sql t.Error(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) } From 4ac62784cfeaf7648fe6999753148c5b1b87c521 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 19 Jun 2024 16:08:27 +0200 Subject: [PATCH 02/18] Fix bad conflict fix Signed-off-by: Tim Vaillancourt --- go/test/endtoend/utils/mysql.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/go/test/endtoend/utils/mysql.go b/go/test/endtoend/utils/mysql.go index b8ac2b9680c..bae8bcac042 100644 --- a/go/test/endtoend/utils/mysql.go +++ b/go/test/endtoend/utils/mysql.go @@ -136,11 +136,11 @@ func compareVitessAndMySQLResults(t TestingT, query string, vtQr, mysqlQr *sqlty 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 { @@ -162,7 +162,7 @@ func compareVitessAndMySQLResults(t TestingT, query string, vtQr, mysqlQr *sqlty } stmt, err := sqlparser.Parse(query) if err != nil { - t.Error(err) + t.Errorf(err.Error()) return } orderBy := false From 3ee6f07db268749a1a367d38bb87ae1680f21656 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 19 Jun 2024 16:19:22 +0200 Subject: [PATCH 03/18] Fix bad conflict fix again Signed-off-by: Tim Vaillancourt --- go/test/endtoend/utils/mysql.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/test/endtoend/utils/mysql.go b/go/test/endtoend/utils/mysql.go index bae8bcac042..2310a2ea194 100644 --- a/go/test/endtoend/utils/mysql.go +++ b/go/test/endtoend/utils/mysql.go @@ -184,7 +184,7 @@ func compareVitessAndMySQLResults(t TestingT, query string, vtQr, mysqlQr *sqlty for _, row := range mysqlQr.Rows { errStr += fmt.Sprintf("%s\n", row) } - t.Error(errStr) + t.Errorf(errStr) } func compareVitessAndMySQLErrors(t TestingT, vtErr, mysqlErr error) { From 31bee011996edb8200e7c11d866e56f68cbafcff Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Thu, 13 Jun 2024 14:48:00 +0530 Subject: [PATCH 04/18] feat: add benchmark for count(*) Signed-off-by: Manan Gupta --- go/test/endtoend/vtgate/gen4/gen4_test.go | 12 ++++++++++++ go/test/endtoend/vtgate/gen4/main_test.go | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) 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() { From 748d9c2888668222a4e478d4f4e6162e78ceaca3 Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Thu, 13 Jun 2024 15:51:37 +0530 Subject: [PATCH 05/18] feat: fix the Count(*) function printing Signed-off-by: Manan Gupta --- go/vt/sqlparser/ast.go | 28 +++++++++++++++++++ go/vt/sqlparser/ast_equals.go | 2 +- go/vt/sqlparser/ast_format.go | 3 +- go/vt/sqlparser/ast_format_fast.go | 5 ++-- go/vt/sqlparser/parse_test.go | 4 +-- go/vt/sqlparser/sql.go | 2 +- go/vt/sqlparser/sql.y | 2 +- .../vtgate/planbuilder/testdata/onecase.json | 26 +++++++++++++++-- 8 files changed, 60 insertions(+), 12 deletions(-) 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_format.go b/go/vt/sqlparser/ast_format.go index e94a1b24ab4..1212f9c0e90 100644 --- a/go/vt/sqlparser/ast_format.go +++ b/go/vt/sqlparser/ast_format.go @@ -2656,8 +2656,7 @@ func (node *Count) Format(buf *TrackedBuffer) { } func (node *CountStar) Format(buf *TrackedBuffer) { - buf.astPrintf(node, "%s(", node.AggrName()) - buf.WriteString("*)") + buf.astPrintf(node, "%s(*)", node.Name) } func (node *Avg) Format(buf *TrackedBuffer) { diff --git a/go/vt/sqlparser/ast_format_fast.go b/go/vt/sqlparser/ast_format_fast.go index f8483506e9f..4d4e033733f 100644 --- a/go/vt/sqlparser/ast_format_fast.go +++ b/go/vt/sqlparser/ast_format_fast.go @@ -3482,9 +3482,8 @@ func (node *Count) formatFast(buf *TrackedBuffer) { } func (node *CountStar) formatFast(buf *TrackedBuffer) { - buf.WriteString(node.AggrName()) - buf.WriteByte('(') - buf.WriteString("*)") + buf.WriteString(node.Name) + buf.WriteString("(*)") } func (node *Avg) formatFast(buf *TrackedBuffer) { 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/vtgate/planbuilder/testdata/onecase.json b/go/vt/vtgate/planbuilder/testdata/onecase.json index da7543f706a..683d1da2830 100644 --- a/go/vt/vtgate/planbuilder/testdata/onecase.json +++ b/go/vt/vtgate/planbuilder/testdata/onecase.json @@ -1,9 +1,31 @@ [ { "comment": "Add your test case here for debugging and run go test -run=One.", - "query": "", + "query": "select Count(*) from user", "plan": { - + "QueryType": "SELECT", + "Original": "select Count(*) from user", + "Instructions": { + "OperatorType": "Aggregate", + "Variant": "Scalar", + "Aggregates": "sum_count_star(0) AS Count(*)", + "Inputs": [ + { + "OperatorType": "Route", + "Variant": "Scatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select Count(*) from `user` where 1 != 1", + "Query": "select Count(*) from `user`", + "Table": "`user`" + } + ] + }, + "TablesUsed": [ + "user.user" + ] } } ] \ No newline at end of file From 6de3492cfb097349cee5025d3ab95905230e51db Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Thu, 13 Jun 2024 18:05:13 +0530 Subject: [PATCH 06/18] feat: fix count star creations from the planner Signed-off-by: Manan Gupta --- go/vt/sqlparser/cached_size.go | 12 ++++ go/vt/vtgate/planbuilder/select.go | 2 +- .../vtgate/planbuilder/testdata/onecase.json | 67 ++++++++++++++----- 3 files changed, 65 insertions(+), 16 deletions(-) diff --git a/go/vt/sqlparser/cached_size.go b/go/vt/sqlparser/cached_size.go index e818a18e8ab..f34dda2c0c2 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(32) + } + // 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/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/onecase.json b/go/vt/vtgate/planbuilder/testdata/onecase.json index 683d1da2830..04475d9497a 100644 --- a/go/vt/vtgate/planbuilder/testdata/onecase.json +++ b/go/vt/vtgate/planbuilder/testdata/onecase.json @@ -1,30 +1,67 @@ [ { "comment": "Add your test case here for debugging and run go test -run=One.", - "query": "select Count(*) from user", + "query": "select Count(*) from user join user_extra where user.intcol + user_extra.incol < 5 limit 5", "plan": { "QueryType": "SELECT", - "Original": "select Count(*) from user", + "Original": "select Count(*) from user join user_extra where user.intcol + user_extra.incol < 5 limit 5", "Instructions": { - "OperatorType": "Aggregate", - "Variant": "Scalar", - "Aggregates": "sum_count_star(0) AS Count(*)", + "OperatorType": "Limit", + "Count": "5", "Inputs": [ { - "OperatorType": "Route", - "Variant": "Scatter", - "Keyspace": { - "Name": "user", - "Sharded": true - }, - "FieldQuery": "select Count(*) from `user` where 1 != 1", - "Query": "select Count(*) from `user`", - "Table": "`user`" + "OperatorType": "Aggregate", + "Variant": "Scalar", + "Aggregates": "sum_count_star(0) AS Count(*)", + "Inputs": [ + { + "OperatorType": "Projection", + "Expressions": [ + "count(*) * count(*) as Count(*)" + ], + "Inputs": [ + { + "OperatorType": "Join", + "Variant": "Join", + "JoinColumnIndexes": "L:0,R:0", + "JoinVars": { + "user_intcol": 1 + }, + "TableName": "`user`_user_extra", + "Inputs": [ + { + "OperatorType": "Route", + "Variant": "Scatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select count(*), `user`.intcol from `user` where 1 != 1 group by `user`.intcol", + "Query": "select count(*), `user`.intcol from `user` group by `user`.intcol", + "Table": "`user`" + }, + { + "OperatorType": "Route", + "Variant": "Scatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select count(*) from user_extra where 1 != 1 group by .0", + "Query": "select count(*) from user_extra where :user_intcol + user_extra.incol < 5 group by .0", + "Table": "user_extra" + } + ] + } + ] + } + ] } ] }, "TablesUsed": [ - "user.user" + "user.user", + "user.user_extra" ] } } From 75f552bff51d2b50712370f400598971ebc57b42 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 19 Jun 2024 17:30:02 +0200 Subject: [PATCH 07/18] make sizegen Signed-off-by: Tim Vaillancourt --- go/vt/sqlparser/cached_size.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/vt/sqlparser/cached_size.go b/go/vt/sqlparser/cached_size.go index f34dda2c0c2..7f729276aa8 100644 --- a/go/vt/sqlparser/cached_size.go +++ b/go/vt/sqlparser/cached_size.go @@ -884,7 +884,7 @@ func (cached *CountStar) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(32) + size += int64(24) } // field Name string size += hack.RuntimeAllocSize(int64(len(cached.Name))) From 4ab096b1f13a480563117aac8431164ade130301 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 19 Jun 2024 17:49:35 +0200 Subject: [PATCH 08/18] update cluster.PanicHandler(...) Signed-off-by: Tim Vaillancourt --- go/test/endtoend/cluster/cluster_util.go | 2 +- go/vt/vtgate/engine/cached_size.go | 40 +++++++++---------- go/vt/vtgate/evalengine/cached_size.go | 2 +- .../tabletserver/rules/cached_size.go | 4 +- 4 files changed, 24 insertions(+), 24 deletions(-) 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/vt/vtgate/engine/cached_size.go b/go/vt/vtgate/engine/cached_size.go index 14962bc86d7..c884a41dc49 100644 --- a/go/vt/vtgate/engine/cached_size.go +++ b/go/vt/vtgate/engine/cached_size.go @@ -53,7 +53,7 @@ func (cached *AlterVSchema) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(16) + size += int64(24) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true) @@ -111,7 +111,7 @@ func (cached *DBDDL) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(32) + size += int64(48) } // field name string size += hack.RuntimeAllocSize(int64(len(cached.name))) @@ -172,7 +172,7 @@ func (cached *Delete) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(8) + size += int64(16) } // field DML *vitess.io/vitess/go/vt/vtgate/engine.DML size += cached.DML.CachedSize(true) @@ -192,7 +192,7 @@ func (cached *Distinct) CachedSize(alloc bool) int64 { } // field CheckCols []vitess.io/vitess/go/vt/vtgate/engine.CheckCol { - size += hack.RuntimeAllocSize(int64(cap(cached.CheckCols)) * int64(18)) + size += hack.RuntimeAllocSize(int64(cap(cached.CheckCols)) * int64(24)) for _, elem := range cached.CheckCols { size += elem.CachedSize(false) } @@ -219,7 +219,7 @@ func (cached *Filter) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(48) + size += int64(64) } // field Predicate vitess.io/vitess/go/vt/vtgate/evalengine.Expr if cc, ok := cached.Predicate.(cachedObject); ok { @@ -445,7 +445,7 @@ func (cached *Lock) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(64) + size += int64(80) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true) @@ -512,7 +512,7 @@ func (cached *MemorySort) CachedSize(alloc bool) int64 { } // field OrderBy []vitess.io/vitess/go/vt/vtgate/engine.OrderByParams { - size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(36)) + size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(40)) } // field Input vitess.io/vitess/go/vt/vtgate/engine.Primitive if cc, ok := cached.Input.(cachedObject); ok { @@ -539,7 +539,7 @@ func (cached *MergeSort) CachedSize(alloc bool) int64 { } // field OrderBy []vitess.io/vitess/go/vt/vtgate/engine.OrderByParams { - size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(36)) + size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(40)) } return size } @@ -549,7 +549,7 @@ func (cached *OnlineDDL) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(64) + size += int64(80) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true) @@ -646,7 +646,7 @@ func (cached *Projection) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(64) + size += int64(80) } // field Cols []string { @@ -698,7 +698,7 @@ func (cached *RenameFields) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(64) + size += int64(80) } // field Cols []string { @@ -723,7 +723,7 @@ func (cached *ReplaceVariables) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(16) + size += int64(24) } // field Input vitess.io/vitess/go/vt/vtgate/engine.Primitive if cc, ok := cached.Input.(cachedObject); ok { @@ -737,7 +737,7 @@ func (cached *RevertMigration) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(48) + size += int64(64) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true) @@ -767,7 +767,7 @@ func (cached *Route) CachedSize(alloc bool) int64 { size += hack.RuntimeAllocSize(int64(len(cached.FieldQuery))) // field OrderBy []vitess.io/vitess/go/vt/vtgate/engine.OrderByParams { - size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(36)) + size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(40)) } // field RoutingParameters *vitess.io/vitess/go/vt/vtgate/engine.RoutingParameters size += cached.RoutingParameters.CachedSize(true) @@ -836,7 +836,7 @@ func (cached *Rows) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(48) + size += int64(64) } // field rows [][]vitess.io/vitess/go/sqltypes.Value { @@ -973,7 +973,7 @@ func (cached *SessionPrimitive) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(24) + size += int64(32) } // field name string size += hack.RuntimeAllocSize(int64(len(cached.name))) @@ -1008,7 +1008,7 @@ func (cached *ShowExec) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(16) + size += int64(24) } // field ShowFilter *vitess.io/vitess/go/vt/sqlparser.ShowFilter size += cached.ShowFilter.CachedSize(true) @@ -1110,7 +1110,7 @@ func (cached *Update) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(16) + size += int64(24) } // field DML *vitess.io/vitess/go/vt/vtgate/engine.DML size += cached.DML.CachedSize(true) @@ -1137,7 +1137,7 @@ func (cached *UpdateTarget) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(16) + size += int64(24) } // field Target string size += hack.RuntimeAllocSize(int64(len(cached.Target))) @@ -1165,7 +1165,7 @@ func (cached *VStream) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(64) + size += int64(80) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true) diff --git a/go/vt/vtgate/evalengine/cached_size.go b/go/vt/vtgate/evalengine/cached_size.go index a2a26bafe1e..a5c69e616fb 100644 --- a/go/vt/vtgate/evalengine/cached_size.go +++ b/go/vt/vtgate/evalengine/cached_size.go @@ -241,7 +241,7 @@ func (cached *EvalResult) CachedSize(alloc bool) int64 { // field tuple_ *[]vitess.io/vitess/go/vt/vtgate/evalengine.EvalResult if cached.tuple_ != nil { size += int64(24) - size += hack.RuntimeAllocSize(int64(cap(*cached.tuple_)) * int64(88)) + size += hack.RuntimeAllocSize(int64(cap(*cached.tuple_)) * int64(96)) for _, elem := range *cached.tuple_ { size += elem.CachedSize(false) } diff --git a/go/vt/vttablet/tabletserver/rules/cached_size.go b/go/vt/vttablet/tabletserver/rules/cached_size.go index acfd199f1f2..1375ef2cb7b 100644 --- a/go/vt/vttablet/tabletserver/rules/cached_size.go +++ b/go/vt/vttablet/tabletserver/rules/cached_size.go @@ -108,7 +108,7 @@ func (cached *bvcre) CachedSize(alloc bool) int64 { } // field re *regexp.Regexp if cached.re != nil { - size += hack.RuntimeAllocSize(int64(153)) + size += hack.RuntimeAllocSize(int64(160)) } return size } @@ -124,7 +124,7 @@ func (cached *namedRegexp) CachedSize(alloc bool) int64 { size += hack.RuntimeAllocSize(int64(len(cached.name))) // field Regexp *regexp.Regexp if cached.Regexp != nil { - size += hack.RuntimeAllocSize(int64(153)) + size += hack.RuntimeAllocSize(int64(160)) } return size } From 20ee454d5666b77587e73bb63159ae282add299b Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 19 Jun 2024 18:13:16 +0200 Subject: [PATCH 09/18] make sizegen again Signed-off-by: Tim Vaillancourt --- go/vt/vtgate/engine/cached_size.go | 40 +++++++++---------- go/vt/vtgate/evalengine/cached_size.go | 2 +- .../tabletserver/rules/cached_size.go | 4 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/go/vt/vtgate/engine/cached_size.go b/go/vt/vtgate/engine/cached_size.go index c884a41dc49..14962bc86d7 100644 --- a/go/vt/vtgate/engine/cached_size.go +++ b/go/vt/vtgate/engine/cached_size.go @@ -53,7 +53,7 @@ func (cached *AlterVSchema) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(24) + size += int64(16) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true) @@ -111,7 +111,7 @@ func (cached *DBDDL) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(48) + size += int64(32) } // field name string size += hack.RuntimeAllocSize(int64(len(cached.name))) @@ -172,7 +172,7 @@ func (cached *Delete) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(16) + size += int64(8) } // field DML *vitess.io/vitess/go/vt/vtgate/engine.DML size += cached.DML.CachedSize(true) @@ -192,7 +192,7 @@ func (cached *Distinct) CachedSize(alloc bool) int64 { } // field CheckCols []vitess.io/vitess/go/vt/vtgate/engine.CheckCol { - size += hack.RuntimeAllocSize(int64(cap(cached.CheckCols)) * int64(24)) + size += hack.RuntimeAllocSize(int64(cap(cached.CheckCols)) * int64(18)) for _, elem := range cached.CheckCols { size += elem.CachedSize(false) } @@ -219,7 +219,7 @@ func (cached *Filter) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(64) + size += int64(48) } // field Predicate vitess.io/vitess/go/vt/vtgate/evalengine.Expr if cc, ok := cached.Predicate.(cachedObject); ok { @@ -445,7 +445,7 @@ func (cached *Lock) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(80) + size += int64(64) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true) @@ -512,7 +512,7 @@ func (cached *MemorySort) CachedSize(alloc bool) int64 { } // field OrderBy []vitess.io/vitess/go/vt/vtgate/engine.OrderByParams { - size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(40)) + size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(36)) } // field Input vitess.io/vitess/go/vt/vtgate/engine.Primitive if cc, ok := cached.Input.(cachedObject); ok { @@ -539,7 +539,7 @@ func (cached *MergeSort) CachedSize(alloc bool) int64 { } // field OrderBy []vitess.io/vitess/go/vt/vtgate/engine.OrderByParams { - size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(40)) + size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(36)) } return size } @@ -549,7 +549,7 @@ func (cached *OnlineDDL) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(80) + size += int64(64) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true) @@ -646,7 +646,7 @@ func (cached *Projection) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(80) + size += int64(64) } // field Cols []string { @@ -698,7 +698,7 @@ func (cached *RenameFields) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(80) + size += int64(64) } // field Cols []string { @@ -723,7 +723,7 @@ func (cached *ReplaceVariables) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(24) + size += int64(16) } // field Input vitess.io/vitess/go/vt/vtgate/engine.Primitive if cc, ok := cached.Input.(cachedObject); ok { @@ -737,7 +737,7 @@ func (cached *RevertMigration) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(64) + size += int64(48) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true) @@ -767,7 +767,7 @@ func (cached *Route) CachedSize(alloc bool) int64 { size += hack.RuntimeAllocSize(int64(len(cached.FieldQuery))) // field OrderBy []vitess.io/vitess/go/vt/vtgate/engine.OrderByParams { - size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(40)) + size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(36)) } // field RoutingParameters *vitess.io/vitess/go/vt/vtgate/engine.RoutingParameters size += cached.RoutingParameters.CachedSize(true) @@ -836,7 +836,7 @@ func (cached *Rows) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(64) + size += int64(48) } // field rows [][]vitess.io/vitess/go/sqltypes.Value { @@ -973,7 +973,7 @@ func (cached *SessionPrimitive) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(32) + size += int64(24) } // field name string size += hack.RuntimeAllocSize(int64(len(cached.name))) @@ -1008,7 +1008,7 @@ func (cached *ShowExec) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(24) + size += int64(16) } // field ShowFilter *vitess.io/vitess/go/vt/sqlparser.ShowFilter size += cached.ShowFilter.CachedSize(true) @@ -1110,7 +1110,7 @@ func (cached *Update) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(24) + size += int64(16) } // field DML *vitess.io/vitess/go/vt/vtgate/engine.DML size += cached.DML.CachedSize(true) @@ -1137,7 +1137,7 @@ func (cached *UpdateTarget) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(24) + size += int64(16) } // field Target string size += hack.RuntimeAllocSize(int64(len(cached.Target))) @@ -1165,7 +1165,7 @@ func (cached *VStream) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(80) + size += int64(64) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true) diff --git a/go/vt/vtgate/evalengine/cached_size.go b/go/vt/vtgate/evalengine/cached_size.go index a5c69e616fb..a2a26bafe1e 100644 --- a/go/vt/vtgate/evalengine/cached_size.go +++ b/go/vt/vtgate/evalengine/cached_size.go @@ -241,7 +241,7 @@ func (cached *EvalResult) CachedSize(alloc bool) int64 { // field tuple_ *[]vitess.io/vitess/go/vt/vtgate/evalengine.EvalResult if cached.tuple_ != nil { size += int64(24) - size += hack.RuntimeAllocSize(int64(cap(*cached.tuple_)) * int64(96)) + size += hack.RuntimeAllocSize(int64(cap(*cached.tuple_)) * int64(88)) for _, elem := range *cached.tuple_ { size += elem.CachedSize(false) } diff --git a/go/vt/vttablet/tabletserver/rules/cached_size.go b/go/vt/vttablet/tabletserver/rules/cached_size.go index 1375ef2cb7b..acfd199f1f2 100644 --- a/go/vt/vttablet/tabletserver/rules/cached_size.go +++ b/go/vt/vttablet/tabletserver/rules/cached_size.go @@ -108,7 +108,7 @@ func (cached *bvcre) CachedSize(alloc bool) int64 { } // field re *regexp.Regexp if cached.re != nil { - size += hack.RuntimeAllocSize(int64(160)) + size += hack.RuntimeAllocSize(int64(153)) } return size } @@ -124,7 +124,7 @@ func (cached *namedRegexp) CachedSize(alloc bool) int64 { size += hack.RuntimeAllocSize(int64(len(cached.name))) // field Regexp *regexp.Regexp if cached.Regexp != nil { - size += hack.RuntimeAllocSize(int64(160)) + size += hack.RuntimeAllocSize(int64(153)) } return size } From cb6e9ad407d447f0ea9102af1d8b6e3bbf15b9d7 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 19 Jun 2024 20:16:56 +0200 Subject: [PATCH 10/18] Use `node.Name` only if set Signed-off-by: Tim Vaillancourt --- go/vt/sqlparser/ast_format.go | 7 ++++++- go/vt/sqlparser/ast_format_fast.go | 10 ++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/go/vt/sqlparser/ast_format.go b/go/vt/sqlparser/ast_format.go index 1212f9c0e90..830420e610d 100644 --- a/go/vt/sqlparser/ast_format.go +++ b/go/vt/sqlparser/ast_format.go @@ -2656,7 +2656,12 @@ func (node *Count) Format(buf *TrackedBuffer) { } func (node *CountStar) Format(buf *TrackedBuffer) { - buf.astPrintf(node, "%s(*)", node.Name) + if node.Name != "" { + buf.astPrintf(node, "%s(*)", node.Name) + } else { + buf.astPrintf(node, "%s(", node.AggrName()) + buf.WriteString("*)") + } } func (node *Avg) Format(buf *TrackedBuffer) { diff --git a/go/vt/sqlparser/ast_format_fast.go b/go/vt/sqlparser/ast_format_fast.go index 4d4e033733f..8115288278e 100644 --- a/go/vt/sqlparser/ast_format_fast.go +++ b/go/vt/sqlparser/ast_format_fast.go @@ -3482,8 +3482,14 @@ func (node *Count) formatFast(buf *TrackedBuffer) { } func (node *CountStar) formatFast(buf *TrackedBuffer) { - buf.WriteString(node.Name) - buf.WriteString("(*)") + if node.Name != "" { + buf.WriteString(node.Name) + buf.WriteString("(*)") + } else { + buf.WriteString(node.AggrName()) + buf.WriteByte('(') + buf.WriteString("*)") + } } func (node *Avg) formatFast(buf *TrackedBuffer) { From 2f10041e2d04dd947a9e56ee4de82692ce85d5c4 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 19 Jun 2024 20:18:18 +0200 Subject: [PATCH 11/18] make sizegen again Signed-off-by: Tim Vaillancourt --- go/vt/vtgate/engine/cached_size.go | 40 +++++++++---------- go/vt/vtgate/evalengine/cached_size.go | 2 +- .../tabletserver/rules/cached_size.go | 4 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/go/vt/vtgate/engine/cached_size.go b/go/vt/vtgate/engine/cached_size.go index 14962bc86d7..c884a41dc49 100644 --- a/go/vt/vtgate/engine/cached_size.go +++ b/go/vt/vtgate/engine/cached_size.go @@ -53,7 +53,7 @@ func (cached *AlterVSchema) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(16) + size += int64(24) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true) @@ -111,7 +111,7 @@ func (cached *DBDDL) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(32) + size += int64(48) } // field name string size += hack.RuntimeAllocSize(int64(len(cached.name))) @@ -172,7 +172,7 @@ func (cached *Delete) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(8) + size += int64(16) } // field DML *vitess.io/vitess/go/vt/vtgate/engine.DML size += cached.DML.CachedSize(true) @@ -192,7 +192,7 @@ func (cached *Distinct) CachedSize(alloc bool) int64 { } // field CheckCols []vitess.io/vitess/go/vt/vtgate/engine.CheckCol { - size += hack.RuntimeAllocSize(int64(cap(cached.CheckCols)) * int64(18)) + size += hack.RuntimeAllocSize(int64(cap(cached.CheckCols)) * int64(24)) for _, elem := range cached.CheckCols { size += elem.CachedSize(false) } @@ -219,7 +219,7 @@ func (cached *Filter) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(48) + size += int64(64) } // field Predicate vitess.io/vitess/go/vt/vtgate/evalengine.Expr if cc, ok := cached.Predicate.(cachedObject); ok { @@ -445,7 +445,7 @@ func (cached *Lock) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(64) + size += int64(80) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true) @@ -512,7 +512,7 @@ func (cached *MemorySort) CachedSize(alloc bool) int64 { } // field OrderBy []vitess.io/vitess/go/vt/vtgate/engine.OrderByParams { - size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(36)) + size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(40)) } // field Input vitess.io/vitess/go/vt/vtgate/engine.Primitive if cc, ok := cached.Input.(cachedObject); ok { @@ -539,7 +539,7 @@ func (cached *MergeSort) CachedSize(alloc bool) int64 { } // field OrderBy []vitess.io/vitess/go/vt/vtgate/engine.OrderByParams { - size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(36)) + size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(40)) } return size } @@ -549,7 +549,7 @@ func (cached *OnlineDDL) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(64) + size += int64(80) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true) @@ -646,7 +646,7 @@ func (cached *Projection) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(64) + size += int64(80) } // field Cols []string { @@ -698,7 +698,7 @@ func (cached *RenameFields) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(64) + size += int64(80) } // field Cols []string { @@ -723,7 +723,7 @@ func (cached *ReplaceVariables) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(16) + size += int64(24) } // field Input vitess.io/vitess/go/vt/vtgate/engine.Primitive if cc, ok := cached.Input.(cachedObject); ok { @@ -737,7 +737,7 @@ func (cached *RevertMigration) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(48) + size += int64(64) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true) @@ -767,7 +767,7 @@ func (cached *Route) CachedSize(alloc bool) int64 { size += hack.RuntimeAllocSize(int64(len(cached.FieldQuery))) // field OrderBy []vitess.io/vitess/go/vt/vtgate/engine.OrderByParams { - size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(36)) + size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(40)) } // field RoutingParameters *vitess.io/vitess/go/vt/vtgate/engine.RoutingParameters size += cached.RoutingParameters.CachedSize(true) @@ -836,7 +836,7 @@ func (cached *Rows) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(48) + size += int64(64) } // field rows [][]vitess.io/vitess/go/sqltypes.Value { @@ -973,7 +973,7 @@ func (cached *SessionPrimitive) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(24) + size += int64(32) } // field name string size += hack.RuntimeAllocSize(int64(len(cached.name))) @@ -1008,7 +1008,7 @@ func (cached *ShowExec) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(16) + size += int64(24) } // field ShowFilter *vitess.io/vitess/go/vt/sqlparser.ShowFilter size += cached.ShowFilter.CachedSize(true) @@ -1110,7 +1110,7 @@ func (cached *Update) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(16) + size += int64(24) } // field DML *vitess.io/vitess/go/vt/vtgate/engine.DML size += cached.DML.CachedSize(true) @@ -1137,7 +1137,7 @@ func (cached *UpdateTarget) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(16) + size += int64(24) } // field Target string size += hack.RuntimeAllocSize(int64(len(cached.Target))) @@ -1165,7 +1165,7 @@ func (cached *VStream) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(64) + size += int64(80) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true) diff --git a/go/vt/vtgate/evalengine/cached_size.go b/go/vt/vtgate/evalengine/cached_size.go index a2a26bafe1e..a5c69e616fb 100644 --- a/go/vt/vtgate/evalengine/cached_size.go +++ b/go/vt/vtgate/evalengine/cached_size.go @@ -241,7 +241,7 @@ func (cached *EvalResult) CachedSize(alloc bool) int64 { // field tuple_ *[]vitess.io/vitess/go/vt/vtgate/evalengine.EvalResult if cached.tuple_ != nil { size += int64(24) - size += hack.RuntimeAllocSize(int64(cap(*cached.tuple_)) * int64(88)) + size += hack.RuntimeAllocSize(int64(cap(*cached.tuple_)) * int64(96)) for _, elem := range *cached.tuple_ { size += elem.CachedSize(false) } diff --git a/go/vt/vttablet/tabletserver/rules/cached_size.go b/go/vt/vttablet/tabletserver/rules/cached_size.go index acfd199f1f2..1375ef2cb7b 100644 --- a/go/vt/vttablet/tabletserver/rules/cached_size.go +++ b/go/vt/vttablet/tabletserver/rules/cached_size.go @@ -108,7 +108,7 @@ func (cached *bvcre) CachedSize(alloc bool) int64 { } // field re *regexp.Regexp if cached.re != nil { - size += hack.RuntimeAllocSize(int64(153)) + size += hack.RuntimeAllocSize(int64(160)) } return size } @@ -124,7 +124,7 @@ func (cached *namedRegexp) CachedSize(alloc bool) int64 { size += hack.RuntimeAllocSize(int64(len(cached.name))) // field Regexp *regexp.Regexp if cached.Regexp != nil { - size += hack.RuntimeAllocSize(int64(153)) + size += hack.RuntimeAllocSize(int64(160)) } return size } From 261f9c5065f1b04a0d98e78e301df22bc684bf64 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 19 Jun 2024 20:25:56 +0200 Subject: [PATCH 12/18] make sizegen from golang:1.21 container Signed-off-by: Tim Vaillancourt --- go/vt/vtgate/engine/cached_size.go | 40 +++++++++---------- go/vt/vtgate/evalengine/cached_size.go | 2 +- .../tabletserver/rules/cached_size.go | 4 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/go/vt/vtgate/engine/cached_size.go b/go/vt/vtgate/engine/cached_size.go index c884a41dc49..14962bc86d7 100644 --- a/go/vt/vtgate/engine/cached_size.go +++ b/go/vt/vtgate/engine/cached_size.go @@ -53,7 +53,7 @@ func (cached *AlterVSchema) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(24) + size += int64(16) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true) @@ -111,7 +111,7 @@ func (cached *DBDDL) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(48) + size += int64(32) } // field name string size += hack.RuntimeAllocSize(int64(len(cached.name))) @@ -172,7 +172,7 @@ func (cached *Delete) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(16) + size += int64(8) } // field DML *vitess.io/vitess/go/vt/vtgate/engine.DML size += cached.DML.CachedSize(true) @@ -192,7 +192,7 @@ func (cached *Distinct) CachedSize(alloc bool) int64 { } // field CheckCols []vitess.io/vitess/go/vt/vtgate/engine.CheckCol { - size += hack.RuntimeAllocSize(int64(cap(cached.CheckCols)) * int64(24)) + size += hack.RuntimeAllocSize(int64(cap(cached.CheckCols)) * int64(18)) for _, elem := range cached.CheckCols { size += elem.CachedSize(false) } @@ -219,7 +219,7 @@ func (cached *Filter) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(64) + size += int64(48) } // field Predicate vitess.io/vitess/go/vt/vtgate/evalengine.Expr if cc, ok := cached.Predicate.(cachedObject); ok { @@ -445,7 +445,7 @@ func (cached *Lock) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(80) + size += int64(64) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true) @@ -512,7 +512,7 @@ func (cached *MemorySort) CachedSize(alloc bool) int64 { } // field OrderBy []vitess.io/vitess/go/vt/vtgate/engine.OrderByParams { - size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(40)) + size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(36)) } // field Input vitess.io/vitess/go/vt/vtgate/engine.Primitive if cc, ok := cached.Input.(cachedObject); ok { @@ -539,7 +539,7 @@ func (cached *MergeSort) CachedSize(alloc bool) int64 { } // field OrderBy []vitess.io/vitess/go/vt/vtgate/engine.OrderByParams { - size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(40)) + size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(36)) } return size } @@ -549,7 +549,7 @@ func (cached *OnlineDDL) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(80) + size += int64(64) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true) @@ -646,7 +646,7 @@ func (cached *Projection) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(80) + size += int64(64) } // field Cols []string { @@ -698,7 +698,7 @@ func (cached *RenameFields) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(80) + size += int64(64) } // field Cols []string { @@ -723,7 +723,7 @@ func (cached *ReplaceVariables) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(24) + size += int64(16) } // field Input vitess.io/vitess/go/vt/vtgate/engine.Primitive if cc, ok := cached.Input.(cachedObject); ok { @@ -737,7 +737,7 @@ func (cached *RevertMigration) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(64) + size += int64(48) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true) @@ -767,7 +767,7 @@ func (cached *Route) CachedSize(alloc bool) int64 { size += hack.RuntimeAllocSize(int64(len(cached.FieldQuery))) // field OrderBy []vitess.io/vitess/go/vt/vtgate/engine.OrderByParams { - size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(40)) + size += hack.RuntimeAllocSize(int64(cap(cached.OrderBy)) * int64(36)) } // field RoutingParameters *vitess.io/vitess/go/vt/vtgate/engine.RoutingParameters size += cached.RoutingParameters.CachedSize(true) @@ -836,7 +836,7 @@ func (cached *Rows) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(64) + size += int64(48) } // field rows [][]vitess.io/vitess/go/sqltypes.Value { @@ -973,7 +973,7 @@ func (cached *SessionPrimitive) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(32) + size += int64(24) } // field name string size += hack.RuntimeAllocSize(int64(len(cached.name))) @@ -1008,7 +1008,7 @@ func (cached *ShowExec) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(24) + size += int64(16) } // field ShowFilter *vitess.io/vitess/go/vt/sqlparser.ShowFilter size += cached.ShowFilter.CachedSize(true) @@ -1110,7 +1110,7 @@ func (cached *Update) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(24) + size += int64(16) } // field DML *vitess.io/vitess/go/vt/vtgate/engine.DML size += cached.DML.CachedSize(true) @@ -1137,7 +1137,7 @@ func (cached *UpdateTarget) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(24) + size += int64(16) } // field Target string size += hack.RuntimeAllocSize(int64(len(cached.Target))) @@ -1165,7 +1165,7 @@ func (cached *VStream) CachedSize(alloc bool) int64 { } size := int64(0) if alloc { - size += int64(80) + size += int64(64) } // field Keyspace *vitess.io/vitess/go/vt/vtgate/vindexes.Keyspace size += cached.Keyspace.CachedSize(true) diff --git a/go/vt/vtgate/evalengine/cached_size.go b/go/vt/vtgate/evalengine/cached_size.go index a5c69e616fb..a2a26bafe1e 100644 --- a/go/vt/vtgate/evalengine/cached_size.go +++ b/go/vt/vtgate/evalengine/cached_size.go @@ -241,7 +241,7 @@ func (cached *EvalResult) CachedSize(alloc bool) int64 { // field tuple_ *[]vitess.io/vitess/go/vt/vtgate/evalengine.EvalResult if cached.tuple_ != nil { size += int64(24) - size += hack.RuntimeAllocSize(int64(cap(*cached.tuple_)) * int64(96)) + size += hack.RuntimeAllocSize(int64(cap(*cached.tuple_)) * int64(88)) for _, elem := range *cached.tuple_ { size += elem.CachedSize(false) } diff --git a/go/vt/vttablet/tabletserver/rules/cached_size.go b/go/vt/vttablet/tabletserver/rules/cached_size.go index 1375ef2cb7b..acfd199f1f2 100644 --- a/go/vt/vttablet/tabletserver/rules/cached_size.go +++ b/go/vt/vttablet/tabletserver/rules/cached_size.go @@ -108,7 +108,7 @@ func (cached *bvcre) CachedSize(alloc bool) int64 { } // field re *regexp.Regexp if cached.re != nil { - size += hack.RuntimeAllocSize(int64(160)) + size += hack.RuntimeAllocSize(int64(153)) } return size } @@ -124,7 +124,7 @@ func (cached *namedRegexp) CachedSize(alloc bool) int64 { size += hack.RuntimeAllocSize(int64(len(cached.name))) // field Regexp *regexp.Regexp if cached.Regexp != nil { - size += hack.RuntimeAllocSize(int64(160)) + size += hack.RuntimeAllocSize(int64(153)) } return size } From b978f6392910fa12c01668f7f455ebe2e67833bd Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 19 Jun 2024 21:18:19 +0200 Subject: [PATCH 13/18] Fix some planner expectations Signed-off-by: Tim Vaillancourt --- go/vt/vtgate/planbuilder/testdata/onecase.json | 10 +++++----- .../planbuilder/testdata/systemtables_cases57.json | 8 ++++---- .../planbuilder/testdata/systemtables_cases80.json | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/go/vt/vtgate/planbuilder/testdata/onecase.json b/go/vt/vtgate/planbuilder/testdata/onecase.json index 04475d9497a..4ec3963e977 100644 --- a/go/vt/vtgate/planbuilder/testdata/onecase.json +++ b/go/vt/vtgate/planbuilder/testdata/onecase.json @@ -36,8 +36,8 @@ "Name": "user", "Sharded": true }, - "FieldQuery": "select count(*), `user`.intcol from `user` where 1 != 1 group by `user`.intcol", - "Query": "select count(*), `user`.intcol from `user` group by `user`.intcol", + "FieldQuery": "select `user`.intcol, Count(*) from `user` where 1 != 1 group by `user`.intcol", + "Query": "select `user`.intcol, Count(*) from `user` group by `user`.intcol", "Table": "`user`" }, { @@ -47,8 +47,8 @@ "Name": "user", "Sharded": true }, - "FieldQuery": "select count(*) from user_extra where 1 != 1 group by .0", - "Query": "select count(*) from user_extra where :user_intcol + user_extra.incol < 5 group by .0", + "FieldQuery": "select 1, Count(*) from user_extra where 1 != 1 group by .0", + "Query": "select 1, Count(*) from user_extra where :user_intcol + user_extra.incol < 5 group by .0", "Table": "user_extra" } ] @@ -65,4 +65,4 @@ ] } } -] \ No newline at end of file +] 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`" From 35353c5d7441818db633fdf48e365e95721558ae Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 19 Jun 2024 21:42:33 +0200 Subject: [PATCH 14/18] Update `TestValidUnionCases` and `TestValidSelectCases` Signed-off-by: Tim Vaillancourt --- go/vt/sqlparser/testdata/select_cases.txt | 4 ++-- go/vt/sqlparser/testdata/union_cases.txt | 24 +++++++++---------- .../vtgate/planbuilder/testdata/onecase.json | 3 ++- 3 files changed, 16 insertions(+), 15 deletions(-) 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/planbuilder/testdata/onecase.json b/go/vt/vtgate/planbuilder/testdata/onecase.json index 4ec3963e977..da1f6fbf0a6 100644 --- a/go/vt/vtgate/planbuilder/testdata/onecase.json +++ b/go/vt/vtgate/planbuilder/testdata/onecase.json @@ -2,7 +2,8 @@ { "comment": "Add your test case here for debugging and run go test -run=One.", "query": "select Count(*) from user join user_extra where user.intcol + user_extra.incol < 5 limit 5", - "plan": { + "v3-plan": "table user not found", + "gen4-plan": { "QueryType": "SELECT", "Original": "select Count(*) from user join user_extra where user.intcol + user_extra.incol < 5 limit 5", "Instructions": { From 121d127809ff7b308ea1e6e5e127efe792d86796 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 19 Jun 2024 21:44:35 +0200 Subject: [PATCH 15/18] revert onecase.json Signed-off-by: Tim Vaillancourt --- .../vtgate/planbuilder/testdata/onecase.json | 68 ++----------------- 1 file changed, 4 insertions(+), 64 deletions(-) diff --git a/go/vt/vtgate/planbuilder/testdata/onecase.json b/go/vt/vtgate/planbuilder/testdata/onecase.json index da1f6fbf0a6..da7543f706a 100644 --- a/go/vt/vtgate/planbuilder/testdata/onecase.json +++ b/go/vt/vtgate/planbuilder/testdata/onecase.json @@ -1,69 +1,9 @@ [ { "comment": "Add your test case here for debugging and run go test -run=One.", - "query": "select Count(*) from user join user_extra where user.intcol + user_extra.incol < 5 limit 5", - "v3-plan": "table user not found", - "gen4-plan": { - "QueryType": "SELECT", - "Original": "select Count(*) from user join user_extra where user.intcol + user_extra.incol < 5 limit 5", - "Instructions": { - "OperatorType": "Limit", - "Count": "5", - "Inputs": [ - { - "OperatorType": "Aggregate", - "Variant": "Scalar", - "Aggregates": "sum_count_star(0) AS Count(*)", - "Inputs": [ - { - "OperatorType": "Projection", - "Expressions": [ - "count(*) * count(*) as Count(*)" - ], - "Inputs": [ - { - "OperatorType": "Join", - "Variant": "Join", - "JoinColumnIndexes": "L:0,R:0", - "JoinVars": { - "user_intcol": 1 - }, - "TableName": "`user`_user_extra", - "Inputs": [ - { - "OperatorType": "Route", - "Variant": "Scatter", - "Keyspace": { - "Name": "user", - "Sharded": true - }, - "FieldQuery": "select `user`.intcol, Count(*) from `user` where 1 != 1 group by `user`.intcol", - "Query": "select `user`.intcol, Count(*) from `user` group by `user`.intcol", - "Table": "`user`" - }, - { - "OperatorType": "Route", - "Variant": "Scatter", - "Keyspace": { - "Name": "user", - "Sharded": true - }, - "FieldQuery": "select 1, Count(*) from user_extra where 1 != 1 group by .0", - "Query": "select 1, Count(*) from user_extra where :user_intcol + user_extra.incol < 5 group by .0", - "Table": "user_extra" - } - ] - } - ] - } - ] - } - ] - }, - "TablesUsed": [ - "user.user", - "user.user_extra" - ] + "query": "", + "plan": { + } } -] +] \ No newline at end of file From ae6c966236fe8bb66cb352df3eb7e6f4f29d17f0 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 19 Jun 2024 22:27:09 +0200 Subject: [PATCH 16/18] Update `TestSelectDBA` Signed-off-by: Tim Vaillancourt --- go/vt/vtgate/executor_select_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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"), From 92cd5293cf3668f7ae6d114d4592fbafd6894496 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Thu, 20 Jun 2024 01:24:44 +0200 Subject: [PATCH 17/18] Add further testing to CountStar formatting Signed-off-by: Tim Vaillancourt --- go/vt/sqlparser/ast_format.go | 8 +++---- go/vt/sqlparser/ast_format_fast.go | 11 +++++----- go/vt/sqlparser/ast_format_fast_test.go | 28 +++++++++++++++++++++++++ go/vt/sqlparser/ast_format_test.go | 28 +++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 go/vt/sqlparser/ast_format_fast_test.go create mode 100644 go/vt/sqlparser/ast_format_test.go diff --git a/go/vt/sqlparser/ast_format.go b/go/vt/sqlparser/ast_format.go index 830420e610d..f2d35169419 100644 --- a/go/vt/sqlparser/ast_format.go +++ b/go/vt/sqlparser/ast_format.go @@ -2656,12 +2656,12 @@ func (node *Count) Format(buf *TrackedBuffer) { } func (node *CountStar) Format(buf *TrackedBuffer) { + name := node.AggrName() if node.Name != "" { - buf.astPrintf(node, "%s(*)", node.Name) - } else { - buf.astPrintf(node, "%s(", node.AggrName()) - buf.WriteString("*)") + name = node.Name } + buf.astPrintf(node, "%s(", name) + buf.WriteString("*)") } func (node *Avg) Format(buf *TrackedBuffer) { diff --git a/go/vt/sqlparser/ast_format_fast.go b/go/vt/sqlparser/ast_format_fast.go index 8115288278e..636be927129 100644 --- a/go/vt/sqlparser/ast_format_fast.go +++ b/go/vt/sqlparser/ast_format_fast.go @@ -3482,14 +3482,13 @@ func (node *Count) formatFast(buf *TrackedBuffer) { } func (node *CountStar) formatFast(buf *TrackedBuffer) { + name := node.AggrName() if node.Name != "" { - buf.WriteString(node.Name) - buf.WriteString("(*)") - } else { - buf.WriteString(node.AggrName()) - buf.WriteByte('(') - buf.WriteString("*)") + name = node.Name } + buf.WriteString(name) + buf.WriteByte('(') + buf.WriteString("*)") } func (node *Avg) formatFast(buf *TrackedBuffer) { 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()) + } +} From 7a5457e3aa14bed31f04cff56a3741576b71266c Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Thu, 20 Jun 2024 01:39:20 +0200 Subject: [PATCH 18/18] one more test Signed-off-by: Tim Vaillancourt --- go/vt/sqlparser/ast_equals_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 go/vt/sqlparser/ast_equals_test.go 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)) + } +}