Skip to content

Commit 8a5f582

Browse files
committed
Ensure that references to an outer subquery in the top scope of a subquery are correctly handled.
1 parent 00ca308 commit 8a5f582

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

enginetest/queries/queries.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8178,6 +8178,12 @@ ORDER BY 1;`,
81788178
{3},
81798179
},
81808180
},
8181+
{
8182+
Query: "SELECT * FROM xy JOIN LATERAL (SELECT * FROM uv WHERE xy.x+1 = uv.u) uv2",
8183+
Expected: []sql.Row{
8184+
{0, 2, 1, 1}, {1, 0, 2, 2}, {2, 1, 3, 2},
8185+
},
8186+
},
81818187
{
81828188
Query: `
81838189
select * from mytable,

sql/planbuilder/scope.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ func (s *scope) resolveColumn(db, table, col string, checkParent, chooseFirst bo
147147
return scopeColumn{}, false
148148
}
149149

150-
if s.parent.activeSubquery != nil {
151-
s.parent.activeSubquery.addOutOfScope(c.id)
150+
if s.activeSubquery != nil {
151+
s.activeSubquery.addOutOfScope(c.id)
152152
}
153153
return c, true
154154
}

0 commit comments

Comments
 (0)