Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit 47cd1f8

Browse files
authored
Merge pull request #573 from erizocosmico/fix/prune-columns-subqueries
analyzer: correctly search for subquery used columns
2 parents 7beeb8d + 59528cf commit 47cd1f8

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

sql/analyzer/prune_columns.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func pruneSubqueryColumns(
7979
columns[table][col] = struct{}{}
8080
}
8181

82-
findUsedColumns(columns, n)
82+
findUsedColumns(columns, n.Child)
8383

8484
node, err := addSubqueryBarriers(n.Child)
8585
if err != nil {

sql/analyzer/prune_columns_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,70 @@ func TestPruneColumns(t *testing.T) {
206206
),
207207
),
208208
},
209+
210+
{
211+
"used inside subquery and not outside",
212+
plan.NewProject(
213+
[]sql.Expression{
214+
gf(0, "sq", "foo"),
215+
},
216+
plan.NewSubqueryAlias("sq",
217+
plan.NewProject(
218+
[]sql.Expression{gf(0, "t1", "foo")},
219+
plan.NewInnerJoin(
220+
plan.NewProject(
221+
[]sql.Expression{
222+
gf(0, "t1", "foo"),
223+
gf(1, "t1", "bar"),
224+
gf(2, "t1", "bax"),
225+
},
226+
t1,
227+
),
228+
plan.NewProject(
229+
[]sql.Expression{
230+
gf(0, "t2", "foo"),
231+
gf(1, "t2", "baz"),
232+
gf(2, "t2", "bux"),
233+
},
234+
t2,
235+
),
236+
expression.NewEquals(
237+
gf(0, "t1", "foo"),
238+
gf(3, "t2", "foo"),
239+
),
240+
),
241+
),
242+
),
243+
),
244+
plan.NewProject(
245+
[]sql.Expression{
246+
gf(0, "sq", "foo"),
247+
},
248+
plan.NewSubqueryAlias("sq",
249+
plan.NewProject(
250+
[]sql.Expression{gf(0, "t1", "foo")},
251+
plan.NewInnerJoin(
252+
plan.NewProject(
253+
[]sql.Expression{
254+
gf(0, "t1", "foo"),
255+
},
256+
t1,
257+
),
258+
plan.NewProject(
259+
[]sql.Expression{
260+
gf(0, "t2", "foo"),
261+
},
262+
t2,
263+
),
264+
expression.NewEquals(
265+
gf(0, "t1", "foo"),
266+
gf(3, "t2", "foo"),
267+
),
268+
),
269+
),
270+
),
271+
),
272+
},
209273
}
210274

211275
for _, tt := range testCases {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy