From f1b01eaf603078a3506a349c9c8acb98d4efeaca Mon Sep 17 00:00:00 2001 From: wangweicugw Date: Wed, 31 Jan 2024 15:50:26 +0800 Subject: [PATCH] remove else Signed-off-by: wangweicugw --- .../vtgate/queries/union/union_test.go | 4 -- .../planbuilder/operators/union_merging.go | 3 -- .../planbuilder/testdata/union_cases.json | 44 +++++++++++-------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/go/test/endtoend/vtgate/queries/union/union_test.go b/go/test/endtoend/vtgate/queries/union/union_test.go index 8d21de01426..898f8b1d659 100644 --- a/go/test/endtoend/vtgate/queries/union/union_test.go +++ b/go/test/endtoend/vtgate/queries/union/union_test.go @@ -81,10 +81,6 @@ func TestUnionDistinct(t *testing.T) { mcmp.AssertMatchesNoOrder(`SELECT 5 from t1 UNION SELECT id2 from t1`, `[[INT64(5)] [INT64(1)] [INT64(2)] [INT64(3)] [INT64(4)]]`) mcmp.AssertMatchesNoOrder(`SELECT id1 from t1 UNION SELECT 2 from t1`, `[[INT64(1)] [INT64(2)] [INT64(3)] [INT64(4)]]`) mcmp.AssertMatchesNoOrder(`SELECT id1 from t1 UNION SELECT 5 from t1`, `[[INT64(1)] [INT64(2)] [INT64(3)] [INT64(4)] [INT64(5)]]`) - mcmp.AssertMatchesNoOrder(`select 3 from t1 union select DAY("2024-01-31") from t1`, `[[INT64(3)] [INT64(31)]]`) - mcmp.AssertMatchesNoOrder(`select DAY("2024-01-31") from t1 union select 3 from t1`, `[[INT64(31)] [INT64(3)]]`) - mcmp.AssertMatchesNoOrder(`select DAY("2024-01-31") from t1 union select id1 from t1`, `[[INT64(31)] [INT64(1)] [INT64(2)] [INT64(3)] [INT64(4)]]`) - mcmp.Exec(`select 3 from t1 union select curdate() from t1`) mcmp.Exec(`select curdate() from t1 union select 3 from t1`) mcmp.Exec(`select curdate() from t1 union select id1 from t1`) } diff --git a/go/vt/vtgate/planbuilder/operators/union_merging.go b/go/vt/vtgate/planbuilder/operators/union_merging.go index a53ff388aef..1fb7d4fb454 100644 --- a/go/vt/vtgate/planbuilder/operators/union_merging.go +++ b/go/vt/vtgate/planbuilder/operators/union_merging.go @@ -208,9 +208,6 @@ func createMergedUnion( types := []sqltypes.Type{rt.Type(), lt.Type()} t := evalengine.AggregateTypes(types) ctx.SemTable.ExprTypes[col] = evalengine.NewType(t, collations.Unknown) - } else { - ctx.SemTable.CopySemanticInfo(rae.Expr, col) - ctx.SemTable.CopySemanticInfo(lae.Expr, col) } ctx.SemTable.Recursive[col] = deps } diff --git a/go/vt/vtgate/planbuilder/testdata/union_cases.json b/go/vt/vtgate/planbuilder/testdata/union_cases.json index 68ebebf4e4f..3f25b60556b 100644 --- a/go/vt/vtgate/planbuilder/testdata/union_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/union_cases.json @@ -373,8 +373,9 @@ "Instructions": { "OperatorType": "Distinct", "Collations": [ - "0" + "(0:1)" ], + "ResultColumns": 1, "Inputs": [ { "OperatorType": "Route", @@ -383,8 +384,8 @@ "Name": "user", "Sharded": true }, - "FieldQuery": "select id from `user` where 1 != 1 union select id from music where 1 != 1 union select 1 from dual where 1 != 1", - "Query": "select id from `user` union select id from music union select 1 from dual", + "FieldQuery": "select id, weight_string(id) from (select id from `user` where 1 != 1 union select id from music where 1 != 1 union select 1 from dual where 1 != 1) as dt where 1 != 1", + "Query": "select id, weight_string(id) from (select id from `user` union select id from music union select 1 from dual) as dt", "Table": "`user`, dual, music" } ] @@ -834,8 +835,9 @@ { "OperatorType": "Distinct", "Collations": [ - "0" + "(0:1)" ], + "ResultColumns": 1, "Inputs": [ { "OperatorType": "Route", @@ -844,8 +846,8 @@ "Name": "user", "Sharded": true }, - "FieldQuery": "select id from `user` where 1 != 1 union select 3 from dual where 1 != 1", - "Query": "select id from `user` union select 3 from dual limit :__upper_limit", + "FieldQuery": "select id, weight_string(id) from (select id from `user` where 1 != 1 union select 3 from dual where 1 != 1) as dt where 1 != 1", + "Query": "select id, weight_string(id) from (select id from `user` union select 3 from dual limit :__upper_limit) as dt", "Table": "`user`, dual" } ] @@ -1042,7 +1044,7 @@ { "OperatorType": "Distinct", "Collations": [ - "0", + "(0:1)", "1" ], "Inputs": [ @@ -1572,8 +1574,9 @@ "Instructions": { "OperatorType": "Distinct", "Collations": [ - "0" + "(0:1)" ], + "ResultColumns": 1, "Inputs": [ { "OperatorType": "Route", @@ -1582,8 +1585,8 @@ "Name": "user", "Sharded": true }, - "FieldQuery": "select col1 from `user` where 1 != 1 union select 3 from `user` where 1 != 1", - "Query": "select col1 from `user` union select 3 from `user`", + "FieldQuery": "select col1, weight_string(col1) from (select col1 from `user` where 1 != 1 union select 3 from `user` where 1 != 1) as dt where 1 != 1", + "Query": "select col1, weight_string(col1) from (select col1 from `user` union select 3 from `user`) as dt", "Table": "`user`" } ] @@ -1602,8 +1605,9 @@ "Instructions": { "OperatorType": "Distinct", "Collations": [ - "0" + "(0:1)" ], + "ResultColumns": 1, "Inputs": [ { "OperatorType": "Route", @@ -1612,8 +1616,8 @@ "Name": "user", "Sharded": true }, - "FieldQuery": "select 3 from `user` where 1 != 1 union select col1 from `user` where 1 != 1", - "Query": "select 3 from `user` union select col1 from `user`", + "FieldQuery": "select `3`, weight_string(`3`) from (select 3 from `user` where 1 != 1 union select col1 from `user` where 1 != 1) as dt where 1 != 1", + "Query": "select `3`, weight_string(`3`) from (select 3 from `user` union select col1 from `user`) as dt", "Table": "`user`" } ] @@ -1632,8 +1636,9 @@ "Instructions": { "OperatorType": "Distinct", "Collations": [ - "0" + "(0:1)" ], + "ResultColumns": 1, "Inputs": [ { "OperatorType": "Route", @@ -1642,8 +1647,8 @@ "Name": "user", "Sharded": true }, - "FieldQuery": "select 3 from `user` where 1 != 1 union select now() from `user` where 1 != 1", - "Query": "select 3 from `user` union select now() from `user`", + "FieldQuery": "select `3`, weight_string(`3`) from (select 3 from `user` where 1 != 1 union select now() from `user` where 1 != 1) as dt where 1 != 1", + "Query": "select `3`, weight_string(`3`) from (select 3 from `user` union select now() from `user`) as dt", "Table": "`user`" } ] @@ -1662,8 +1667,9 @@ "Instructions": { "OperatorType": "Distinct", "Collations": [ - "0" + "(0:1)" ], + "ResultColumns": 1, "Inputs": [ { "OperatorType": "Route", @@ -1672,8 +1678,8 @@ "Name": "user", "Sharded": true }, - "FieldQuery": "select now() from `user` where 1 != 1 union select 3 from `user` where 1 != 1", - "Query": "select now() from `user` union select 3 from `user`", + "FieldQuery": "select `now()`, weight_string(`now()`) from (select now() from `user` where 1 != 1 union select 3 from `user` where 1 != 1) as dt where 1 != 1", + "Query": "select `now()`, weight_string(`now()`) from (select now() from `user` union select 3 from `user`) as dt", "Table": "`user`" } ]