From 7be439eff960a99779511379841f75f1a23e6391 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Wed, 16 Oct 2024 16:01:31 +0200 Subject: [PATCH] bugfix: don't add columns to derived table definition Signed-off-by: Andres Taylor --- .../planbuilder/operators/query_planning.go | 5 ---- .../planbuilder/testdata/from_cases.json | 12 +++++----- .../planbuilder/testdata/tpch_cases.json | 24 +++++++++---------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/go/vt/vtgate/planbuilder/operators/query_planning.go b/go/vt/vtgate/planbuilder/operators/query_planning.go index adff05e55cb..b531c23b877 100644 --- a/go/vt/vtgate/planbuilder/operators/query_planning.go +++ b/go/vt/vtgate/planbuilder/operators/query_planning.go @@ -22,8 +22,6 @@ import ( "slices" "strconv" - "vitess.io/vitess/go/slice" - "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/vtgate/planbuilder/operators/ops" "vitess.io/vitess/go/vt/vtgate/planbuilder/operators/rewrite" @@ -560,9 +558,6 @@ func createProjectionWithTheseColumns( proj.Columns = AliasedProjections(p.columns) if dt != nil { kopy := *dt - kopy.Columns = slice.Map(p.columnAliases, func(s string) sqlparser.IdentifierCI { - return sqlparser.NewIdentifierCI(s) - }) proj.DT = &kopy } diff --git a/go/vt/vtgate/planbuilder/testdata/from_cases.json b/go/vt/vtgate/planbuilder/testdata/from_cases.json index b5efdb18eae..9e668bd68a2 100644 --- a/go/vt/vtgate/planbuilder/testdata/from_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/from_cases.json @@ -1989,8 +1989,8 @@ "Name": "user", "Sharded": true }, - "FieldQuery": "select t.id, t.`user.col` from (select `user`.id, `user`.col1, `user`.col as `user.col` from `user` where 1 != 1) as t(`user.col`) where 1 != 1", - "Query": "select t.id, t.`user.col` from (select `user`.id, `user`.col1, `user`.col as `user.col` from `user`) as t(`user.col`)", + "FieldQuery": "select t.id, t.`user.col` from (select `user`.id, `user`.col1, `user`.col as `user.col` from `user` where 1 != 1) as t where 1 != 1", + "Query": "select t.id, t.`user.col` from (select `user`.id, `user`.col1, `user`.col as `user.col` from `user`) as t", "Table": "`user`" }, { @@ -2000,8 +2000,8 @@ "Name": "user", "Sharded": true }, - "FieldQuery": "select 1 from (select user_extra.col as `user_extra.col` from user_extra where 1 != 1) as t(`user_extra.col`) where 1 != 1", - "Query": "select 1 from (select user_extra.col as `user_extra.col` from user_extra where user_extra.col = :user_col) as t(`user_extra.col`)", + "FieldQuery": "select 1 from (select user_extra.col as `user_extra.col` from user_extra where 1 != 1) as t where 1 != 1", + "Query": "select 1 from (select user_extra.col as `user_extra.col` from user_extra where user_extra.col = :user_col) as t", "Table": "user_extra" } ] @@ -3187,8 +3187,8 @@ "Name": "user", "Sharded": true }, - "FieldQuery": "select i + 1 from (select `user`.id from `user` where 1 != 1) as t where 1 != 1", - "Query": "select i + 1 from (select `user`.id from `user`) as t", + "FieldQuery": "select i + 1 from (select `user`.id from `user` where 1 != 1) as t(i) where 1 != 1", + "Query": "select i + 1 from (select `user`.id from `user`) as t(i)", "Table": "`user`" }, { diff --git a/go/vt/vtgate/planbuilder/testdata/tpch_cases.json b/go/vt/vtgate/planbuilder/testdata/tpch_cases.json index 107b26cc055..f1d0ba7dfcc 100644 --- a/go/vt/vtgate/planbuilder/testdata/tpch_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/tpch_cases.json @@ -588,9 +588,9 @@ "Name": "main", "Sharded": true }, - "FieldQuery": "select sum(volume) as revenue, l_year, shipping.l_suppkey, shipping.l_orderkey, weight_string(l_year), shipping.supp_nation, weight_string(shipping.supp_nation), shipping.cust_nation, weight_string(shipping.cust_nation) from (select extract(year from l_shipdate) as l_year, l_extendedprice * (1 - l_discount) as volume, l_suppkey as l_suppkey, l_orderkey as l_orderkey from lineitem where 1 != 1) as shipping(l_orderkey) where 1 != 1 group by l_year, shipping.l_suppkey, shipping.l_orderkey, weight_string(l_year)", + "FieldQuery": "select sum(volume) as revenue, l_year, shipping.l_suppkey, shipping.l_orderkey, weight_string(l_year), shipping.supp_nation, weight_string(shipping.supp_nation), shipping.cust_nation, weight_string(shipping.cust_nation) from (select extract(year from l_shipdate) as l_year, l_extendedprice * (1 - l_discount) as volume, l_suppkey as l_suppkey, l_orderkey as l_orderkey from lineitem where 1 != 1) as shipping where 1 != 1 group by l_year, shipping.l_suppkey, shipping.l_orderkey, weight_string(l_year)", "OrderBy": "(5|6) ASC, (7|8) ASC, (1|4) ASC", - "Query": "select sum(volume) as revenue, l_year, shipping.l_suppkey, shipping.l_orderkey, weight_string(l_year), shipping.supp_nation, weight_string(shipping.supp_nation), shipping.cust_nation, weight_string(shipping.cust_nation) from (select extract(year from l_shipdate) as l_year, l_extendedprice * (1 - l_discount) as volume, l_suppkey as l_suppkey, l_orderkey as l_orderkey from lineitem where l_shipdate between date('1995-01-01') and date('1996-12-31')) as shipping(l_orderkey) group by l_year, shipping.l_suppkey, shipping.l_orderkey, weight_string(l_year) order by shipping.supp_nation asc, shipping.cust_nation asc, shipping.l_year asc", + "Query": "select sum(volume) as revenue, l_year, shipping.l_suppkey, shipping.l_orderkey, weight_string(l_year), shipping.supp_nation, weight_string(shipping.supp_nation), shipping.cust_nation, weight_string(shipping.cust_nation) from (select extract(year from l_shipdate) as l_year, l_extendedprice * (1 - l_discount) as volume, l_suppkey as l_suppkey, l_orderkey as l_orderkey from lineitem where l_shipdate between date('1995-01-01') and date('1996-12-31')) as shipping group by l_year, shipping.l_suppkey, shipping.l_orderkey, weight_string(l_year) order by shipping.supp_nation asc, shipping.cust_nation asc, shipping.l_year asc", "Table": "lineitem" }, { @@ -600,8 +600,8 @@ "Name": "main", "Sharded": true }, - "FieldQuery": "select count(*), shipping.o_custkey from (select o_custkey as o_custkey, o_orderkey as o_orderkey from orders where 1 != 1) as shipping(o_orderkey) where 1 != 1 group by shipping.o_custkey", - "Query": "select count(*), shipping.o_custkey from (select o_custkey as o_custkey, o_orderkey as o_orderkey from orders where o_orderkey = :l_orderkey) as shipping(o_orderkey) group by shipping.o_custkey", + "FieldQuery": "select count(*), shipping.o_custkey from (select o_custkey as o_custkey, o_orderkey as o_orderkey from orders where 1 != 1) as shipping where 1 != 1 group by shipping.o_custkey", + "Query": "select count(*), shipping.o_custkey from (select o_custkey as o_custkey, o_orderkey as o_orderkey from orders where o_orderkey = :l_orderkey) as shipping group by shipping.o_custkey", "Table": "orders", "Values": [ ":l_orderkey" @@ -636,8 +636,8 @@ "Name": "main", "Sharded": true }, - "FieldQuery": "select count(*), shipping.s_nationkey from (select s_suppkey as s_suppkey, s_nationkey as s_nationkey from supplier where 1 != 1) as shipping(s_nationkey) where 1 != 1 group by shipping.s_nationkey", - "Query": "select count(*), shipping.s_nationkey from (select s_suppkey as s_suppkey, s_nationkey as s_nationkey from supplier where s_suppkey = :l_suppkey) as shipping(s_nationkey) group by shipping.s_nationkey", + "FieldQuery": "select count(*), shipping.s_nationkey from (select s_suppkey as s_suppkey, s_nationkey as s_nationkey from supplier where 1 != 1) as shipping where 1 != 1 group by shipping.s_nationkey", + "Query": "select count(*), shipping.s_nationkey from (select s_suppkey as s_suppkey, s_nationkey as s_nationkey from supplier where s_suppkey = :l_suppkey) as shipping group by shipping.s_nationkey", "Table": "supplier", "Values": [ ":l_suppkey" @@ -651,8 +651,8 @@ "Name": "main", "Sharded": true }, - "FieldQuery": "select count(*), supp_nation, weight_string(supp_nation), n1.n_nationkey as `n1.n_nationkey`, shipping.supp_nation as `shipping.supp_nation`, shipping.`n1.n_name = 'FRANCE'` as `shipping.n1.n_name = 'FRANCE'`, shipping.`n1.n_name = 'GERMANY'` as `shipping.n1.n_name = 'GERMANY'` from (select n1.n_name as supp_nation, n1.n_name = 'FRANCE' as `n1.n_name = 'FRANCE'`, n1.n_name = 'GERMANY' as `n1.n_name = 'GERMANY'`, n1.n_nationkey as `n1.n_nationkey`, shipping.supp_nation as `shipping.supp_nation`, shipping.`n1.n_name = 'FRANCE'` as `shipping.n1.n_name = 'FRANCE'`, shipping.`n1.n_name = 'GERMANY'` as `shipping.n1.n_name = 'GERMANY'` from nation as n1 where 1 != 1) as shipping(`n1.n_nationkey`, `shipping.supp_nation`, `shipping.n1.n_name = 'FRANCE'`, `shipping.n1.n_name = 'GERMANY'`) where 1 != 1 group by supp_nation, weight_string(supp_nation)", - "Query": "select count(*), supp_nation, weight_string(supp_nation), n1.n_nationkey as `n1.n_nationkey`, shipping.supp_nation as `shipping.supp_nation`, shipping.`n1.n_name = 'FRANCE'` as `shipping.n1.n_name = 'FRANCE'`, shipping.`n1.n_name = 'GERMANY'` as `shipping.n1.n_name = 'GERMANY'` from (select n1.n_name as supp_nation, n1.n_name = 'FRANCE' as `n1.n_name = 'FRANCE'`, n1.n_name = 'GERMANY' as `n1.n_name = 'GERMANY'`, n1.n_nationkey as `n1.n_nationkey`, shipping.supp_nation as `shipping.supp_nation`, shipping.`n1.n_name = 'FRANCE'` as `shipping.n1.n_name = 'FRANCE'`, shipping.`n1.n_name = 'GERMANY'` as `shipping.n1.n_name = 'GERMANY'` from nation as n1 where n1.n_nationkey = :s_nationkey) as shipping(`n1.n_nationkey`, `shipping.supp_nation`, `shipping.n1.n_name = 'FRANCE'`, `shipping.n1.n_name = 'GERMANY'`) group by supp_nation, weight_string(supp_nation)", + "FieldQuery": "select count(*), supp_nation, weight_string(supp_nation), n1.n_nationkey as `n1.n_nationkey`, shipping.supp_nation as `shipping.supp_nation`, shipping.`n1.n_name = 'FRANCE'` as `shipping.n1.n_name = 'FRANCE'`, shipping.`n1.n_name = 'GERMANY'` as `shipping.n1.n_name = 'GERMANY'` from (select n1.n_name as supp_nation, n1.n_name = 'FRANCE' as `n1.n_name = 'FRANCE'`, n1.n_name = 'GERMANY' as `n1.n_name = 'GERMANY'`, n1.n_nationkey as `n1.n_nationkey`, shipping.supp_nation as `shipping.supp_nation`, shipping.`n1.n_name = 'FRANCE'` as `shipping.n1.n_name = 'FRANCE'`, shipping.`n1.n_name = 'GERMANY'` as `shipping.n1.n_name = 'GERMANY'` from nation as n1 where 1 != 1) as shipping where 1 != 1 group by supp_nation, weight_string(supp_nation)", + "Query": "select count(*), supp_nation, weight_string(supp_nation), n1.n_nationkey as `n1.n_nationkey`, shipping.supp_nation as `shipping.supp_nation`, shipping.`n1.n_name = 'FRANCE'` as `shipping.n1.n_name = 'FRANCE'`, shipping.`n1.n_name = 'GERMANY'` as `shipping.n1.n_name = 'GERMANY'` from (select n1.n_name as supp_nation, n1.n_name = 'FRANCE' as `n1.n_name = 'FRANCE'`, n1.n_name = 'GERMANY' as `n1.n_name = 'GERMANY'`, n1.n_nationkey as `n1.n_nationkey`, shipping.supp_nation as `shipping.supp_nation`, shipping.`n1.n_name = 'FRANCE'` as `shipping.n1.n_name = 'FRANCE'`, shipping.`n1.n_name = 'GERMANY'` as `shipping.n1.n_name = 'GERMANY'` from nation as n1 where n1.n_nationkey = :s_nationkey) as shipping group by supp_nation, weight_string(supp_nation)", "Table": "nation", "Values": [ ":s_nationkey" @@ -691,8 +691,8 @@ "Name": "main", "Sharded": true }, - "FieldQuery": "select count(*), shipping.c_nationkey from (select c_custkey as c_custkey, c_nationkey as c_nationkey from customer where 1 != 1) as shipping(c_nationkey) where 1 != 1 group by shipping.c_nationkey", - "Query": "select count(*), shipping.c_nationkey from (select c_custkey as c_custkey, c_nationkey as c_nationkey from customer where c_custkey = :o_custkey) as shipping(c_nationkey) group by shipping.c_nationkey", + "FieldQuery": "select count(*), shipping.c_nationkey from (select c_custkey as c_custkey, c_nationkey as c_nationkey from customer where 1 != 1) as shipping where 1 != 1 group by shipping.c_nationkey", + "Query": "select count(*), shipping.c_nationkey from (select c_custkey as c_custkey, c_nationkey as c_nationkey from customer where c_custkey = :o_custkey) as shipping group by shipping.c_nationkey", "Table": "customer", "Values": [ ":o_custkey" @@ -706,8 +706,8 @@ "Name": "main", "Sharded": true }, - "FieldQuery": "select count(*), cust_nation, weight_string(cust_nation), n2.n_nationkey as `n2.n_nationkey`, shipping.cust_nation as `shipping.cust_nation` from (select n2.n_name as cust_nation, n2.n_name = 'GERMANY' as `n2.n_name = 'GERMANY'`, n2.n_name = 'FRANCE' as `n2.n_name = 'FRANCE'`, n2.n_nationkey as `n2.n_nationkey`, shipping.cust_nation as `shipping.cust_nation` from nation as n2 where 1 != 1) as shipping(`n2.n_nationkey`, `shipping.cust_nation`) where 1 != 1 group by cust_nation, weight_string(cust_nation)", - "Query": "select count(*), cust_nation, weight_string(cust_nation), n2.n_nationkey as `n2.n_nationkey`, shipping.cust_nation as `shipping.cust_nation` from (select n2.n_name as cust_nation, n2.n_name = 'GERMANY' as `n2.n_name = 'GERMANY'`, n2.n_name = 'FRANCE' as `n2.n_name = 'FRANCE'`, n2.n_nationkey as `n2.n_nationkey`, shipping.cust_nation as `shipping.cust_nation` from nation as n2 where (:n1_n_name = 'FRANCE' and n2.n_name = 'GERMANY' or :n1_n_name = 'GERMANY' and n2.n_name = 'FRANCE') and n2.n_nationkey = :c_nationkey) as shipping(`n2.n_nationkey`, `shipping.cust_nation`) group by cust_nation, weight_string(cust_nation)", + "FieldQuery": "select count(*), cust_nation, weight_string(cust_nation), n2.n_nationkey as `n2.n_nationkey`, shipping.cust_nation as `shipping.cust_nation` from (select n2.n_name as cust_nation, n2.n_name = 'GERMANY' as `n2.n_name = 'GERMANY'`, n2.n_name = 'FRANCE' as `n2.n_name = 'FRANCE'`, n2.n_nationkey as `n2.n_nationkey`, shipping.cust_nation as `shipping.cust_nation` from nation as n2 where 1 != 1) as shipping where 1 != 1 group by cust_nation, weight_string(cust_nation)", + "Query": "select count(*), cust_nation, weight_string(cust_nation), n2.n_nationkey as `n2.n_nationkey`, shipping.cust_nation as `shipping.cust_nation` from (select n2.n_name as cust_nation, n2.n_name = 'GERMANY' as `n2.n_name = 'GERMANY'`, n2.n_name = 'FRANCE' as `n2.n_name = 'FRANCE'`, n2.n_nationkey as `n2.n_nationkey`, shipping.cust_nation as `shipping.cust_nation` from nation as n2 where (:n1_n_name = 'FRANCE' and n2.n_name = 'GERMANY' or :n1_n_name = 'GERMANY' and n2.n_name = 'FRANCE') and n2.n_nationkey = :c_nationkey) as shipping group by cust_nation, weight_string(cust_nation)", "Table": "nation", "Values": [ ":c_nationkey"