From 3c92aedca6600d3d38197ee14746bacbe6624303 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Tue, 6 Feb 2024 13:54:39 +0100 Subject: [PATCH] test: update test expectations Signed-off-by: Andres Taylor --- .../vtgate/queries/subquery/subquery_test.go | 3 ++ go/vt/sqlparser/normalizer.go | 2 +- go/vt/vtgate/executor_select_test.go | 28 +++++++++---------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/go/test/endtoend/vtgate/queries/subquery/subquery_test.go b/go/test/endtoend/vtgate/queries/subquery/subquery_test.go index ea2d644605c..8a5dea7ca20 100644 --- a/go/test/endtoend/vtgate/queries/subquery/subquery_test.go +++ b/go/test/endtoend/vtgate/queries/subquery/subquery_test.go @@ -170,7 +170,10 @@ func TestSubqueryInAggregation(t *testing.T) { mcmp.Exec("insert into t1(id1, id2) values(0,0),(1,1)") mcmp.Exec("insert into t2(id3, id4) values(1,2),(5,7)") mcmp.Exec(`SELECT max((select min(id2) from t1)) FROM t2`) + + // we need an alias for the subquery so that the id1 = 1 on the inside and the outside look the same and can be merged mcmp.Exec(`SELECT max((select group_concat(id1, id2) from t1 where id1 = 1)) as x FROM t1 where id1 = 1`) + mcmp.Exec(`SELECT max((select min(id2) from t1 where id2 = 1)) FROM dual`) mcmp.Exec(`SELECT max((select min(id2) from t1)) FROM t2 where id4 = 7`) diff --git a/go/vt/sqlparser/normalizer.go b/go/vt/sqlparser/normalizer.go index 89eee16064d..65f0601e08f 100644 --- a/go/vt/sqlparser/normalizer.go +++ b/go/vt/sqlparser/normalizer.go @@ -133,7 +133,7 @@ func (nz *normalizer) walkDownSelect(node, parent SQLNode) bool { // we should not rewrite the type description return false case *AliasedExpr: - // we don't want to rewrite literals in select expressions if the column is not aliased + // we only want to rewrite literals in select expressions if the column is aliased return node.As.NotEmpty() } return nz.err == nil // only continue if we haven't found any errors diff --git a/go/vt/vtgate/executor_select_test.go b/go/vt/vtgate/executor_select_test.go index dc4f1e0e726..b6635ebaa49 100644 --- a/go/vt/vtgate/executor_select_test.go +++ b/go/vt/vtgate/executor_select_test.go @@ -183,8 +183,8 @@ func TestSystemVariablesMySQLBelow80(t *testing.T) { wantQueries := []*querypb.BoundQuery{ {Sql: "select @@sql_mode orig, 'only_full_group_by' new"}, - {Sql: "set sql_mode = 'only_full_group_by'", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}}, - {Sql: "select :vtg1 /* INT64 */ from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}}, + {Sql: "set sql_mode = 'only_full_group_by'", BindVariables: map[string]*querypb.BindVariable{}}, + {Sql: "select 1 from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{}}, } utils.MustMatch(t, wantQueries, sbc1.Queries) @@ -220,8 +220,8 @@ func TestSystemVariablesWithSetVarDisabled(t *testing.T) { wantQueries := []*querypb.BoundQuery{ {Sql: "select @@sql_mode orig, 'only_full_group_by' new"}, - {Sql: "set sql_mode = 'only_full_group_by'", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}}, - {Sql: "select :vtg1 /* INT64 */ from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}}, + {Sql: "set sql_mode = 'only_full_group_by'", BindVariables: map[string]*querypb.BindVariable{}}, + {Sql: "select 1 from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{}}, } utils.MustMatch(t, wantQueries, sbc1.Queries) @@ -265,9 +265,9 @@ func TestSetSystemVariablesTx(t *testing.T) { require.Zero(t, session.ShardSessions) wantQueries := []*querypb.BoundQuery{ - {Sql: "select :vtg1 /* INT64 */ from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}}, + {Sql: "select 1 from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{}}, {Sql: "select @@sql_mode orig, 'only_full_group_by' new"}, - {Sql: "select /*+ SET_VAR(sql_mode = 'only_full_group_by') */ :vtg1 /* INT64 */ from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}}, + {Sql: "select /*+ SET_VAR(sql_mode = 'only_full_group_by') */ 1 from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{}}, } utils.MustMatch(t, wantQueries, sbc1.Queries) @@ -299,7 +299,7 @@ func TestSetSystemVariables(t *testing.T) { require.False(t, session.InReservedConn()) wantQueries := []*querypb.BoundQuery{ {Sql: "select @@sql_mode orig, 'only_full_group_by' new"}, - {Sql: "select /*+ SET_VAR(sql_mode = 'only_full_group_by') */ :vtg1 /* INT64 */ from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}}, + {Sql: "select /*+ SET_VAR(sql_mode = 'only_full_group_by') */ 1 from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{}}, } utils.MustMatch(t, wantQueries, lookup.Queries) lookup.Queries = nil @@ -310,7 +310,7 @@ func TestSetSystemVariables(t *testing.T) { require.NoError(t, err) require.False(t, session.InReservedConn()) wantQueries = []*querypb.BoundQuery{ - {Sql: "select /*+ SET_VAR(sql_mode = 'only_full_group_by') */ /* comment */ :vtg1 /* INT64 */ from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}}, + {Sql: "select /*+ SET_VAR(sql_mode = 'only_full_group_by') */ /* comment */ 1 from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{}}, } utils.MustMatch(t, wantQueries, lookup.Queries) lookup.Queries = nil @@ -378,8 +378,8 @@ func TestSetSystemVariables(t *testing.T) { wantQueries = []*querypb.BoundQuery{ {Sql: "select 1 from dual where @@max_tmp_tables != 1"}, - {Sql: "set max_tmp_tables = '1', sql_mode = 'only_full_group_by', sql_safe_updates = '0'", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}}, - {Sql: "select :vtg1 /* INT64 */ from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}}, + {Sql: "set max_tmp_tables = '1', sql_mode = 'only_full_group_by', sql_safe_updates = '0'", BindVariables: map[string]*querypb.BindVariable{}}, + {Sql: "select 1 from information_schema.`table`", BindVariables: map[string]*querypb.BindVariable{}}, } utils.MustMatch(t, wantQueries, lookup.Queries) } @@ -420,7 +420,7 @@ func TestSetSystemVariablesWithReservedConnection(t *testing.T) { {Sql: "select @@sql_mode orig, '' new"}, {Sql: "set sql_mode = ''"}, {Sql: "select age, city, weight_string(age) from `user` group by age, weight_string(age) order by age asc"}, - {Sql: "select age, city + :vtg1 /* INT64 */, weight_string(age) from `user` group by age, weight_string(age) order by age asc", BindVariables: map[string]*querypb.BindVariable{"vtg1": {Type: sqltypes.Int64, Value: []byte("1")}}}, + {Sql: "select age, city + 1, weight_string(age) from `user` group by age, weight_string(age) order by age asc", BindVariables: map[string]*querypb.BindVariable{}}, } utils.MustMatch(t, wantQueries, sbc1.Queries) require.Equal(t, "''", session.SystemVariables["sql_mode"]) @@ -484,9 +484,8 @@ func TestGen4SelectDBA(t *testing.T) { query, map[string]*querypb.BindVariable{}, ) require.NoError(t, err) - wantQueries = []*querypb.BoundQuery{{Sql: "select :vtg1 /* INT64 */ from information_schema.table_constraints where constraint_schema = :__vtschemaname /* VARCHAR */ and table_name = :table_name1 /* VARCHAR */", + wantQueries = []*querypb.BoundQuery{{Sql: "select 1 from information_schema.table_constraints where constraint_schema = :__vtschemaname /* VARCHAR */ and table_name = :table_name1 /* VARCHAR */", BindVariables: map[string]*querypb.BindVariable{ - "vtg1": sqltypes.Int64BindVariable(1), "constraint_schema": sqltypes.StringBindVariable("vt_ks"), "table_name": sqltypes.StringBindVariable("user"), "__vtschemaname": sqltypes.StringBindVariable("vt_ks"), @@ -498,9 +497,8 @@ func TestGen4SelectDBA(t *testing.T) { query = "select 1 from information_schema.table_constraints where constraint_schema = 'vt_ks'" _, err = executor.Execute(context.Background(), nil, "TestSelectDBA", NewSafeSession(&vtgatepb.Session{TargetString: "TestExecutor"}), query, map[string]*querypb.BindVariable{}) require.NoError(t, err) - wantQueries = []*querypb.BoundQuery{{Sql: "select :vtg1 /* INT64 */ from information_schema.table_constraints where constraint_schema = :__vtschemaname /* VARCHAR */", + wantQueries = []*querypb.BoundQuery{{Sql: "select 1 from information_schema.table_constraints where constraint_schema = :__vtschemaname /* VARCHAR */", BindVariables: map[string]*querypb.BindVariable{ - "vtg1": sqltypes.Int64BindVariable(1), "constraint_schema": sqltypes.StringBindVariable("vt_ks"), "__vtschemaname": sqltypes.StringBindVariable("vt_ks"), }}}