From 26ebbb829fa2e58e26db50668cf2f9ee466e3a87 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Thu, 17 Oct 2024 09:48:41 +0200 Subject: [PATCH] bugfix: don't use derived table twice Signed-off-by: Andres Taylor --- .../planbuilder/operators/horizon_expanding.go | 1 + .../vtgate/planbuilder/testdata/aggr_cases.json | 17 ++++++++--------- .../vtgate/planbuilder/testdata/cte_cases.json | 5 ++--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/go/vt/vtgate/planbuilder/operators/horizon_expanding.go b/go/vt/vtgate/planbuilder/operators/horizon_expanding.go index 873fb575155..9549822274e 100644 --- a/go/vt/vtgate/planbuilder/operators/horizon_expanding.go +++ b/go/vt/vtgate/planbuilder/operators/horizon_expanding.go @@ -300,6 +300,7 @@ outer: func createProjectionForComplexAggregation(a *Aggregator, qp *QueryProjection) Operator { p := newAliasedProjection(a) p.DT = a.DT + a.DT = nil // we don't need the derived table twice for _, expr := range qp.SelectExprs { ae, err := expr.GetAliasedExpr() if err != nil { diff --git a/go/vt/vtgate/planbuilder/testdata/aggr_cases.json b/go/vt/vtgate/planbuilder/testdata/aggr_cases.json index 51a40b831f3..8a703d8a620 100644 --- a/go/vt/vtgate/planbuilder/testdata/aggr_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/aggr_cases.json @@ -590,7 +590,7 @@ "Sharded": true }, "FieldQuery": "select id from (select id, count(`user`.id) = 2 from `user` where 1 != 1 group by id) as subquery_for_limit where 1 != 1", - "Query": "select id from (select id, count(`user`.id) = 2 from `user` group by id having count(`user`.id) = 2) as subquery_for_limit limit 2", + "Query": "select id from (select id, count(`user`.id) = 2 from `user` group by id having count(`user`.id) = 2) as subquery_for_limit limit :__upper_limit", "Table": "`user`" } ] @@ -3644,10 +3644,9 @@ "Original": "select * from (select id from user having count(*) = 1) s", "Instructions": { "OperatorType": "SimpleProjection", - "ColumnNames": [ - "0:id" + "Columns": [ + 0 ], - "Columns": "0", "Inputs": [ { "OperatorType": "Projection", @@ -6594,11 +6593,11 @@ { "OperatorType": "SimpleProjection", "Columns": [ - 2, - 0, - 1, - 3 - ], + 2, + 0, + 1, + 3 + ], "Inputs": [ { "OperatorType": "Sort", diff --git a/go/vt/vtgate/planbuilder/testdata/cte_cases.json b/go/vt/vtgate/planbuilder/testdata/cte_cases.json index 517524dedcd..2fd8d573fe0 100644 --- a/go/vt/vtgate/planbuilder/testdata/cte_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/cte_cases.json @@ -370,10 +370,9 @@ "Original": "with s as (select id from user having count(*) = 1) select * from s", "Instructions": { "OperatorType": "SimpleProjection", - "ColumnNames": [ - "0:id" + "Columns": [ + 0 ], - "Columns": "0", "Inputs": [ { "OperatorType": "Projection",