Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subquery row iter fix field indexes #1350

Merged
merged 1 commit into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions enginetest/queries/join_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,15 @@ inner join pq on true order by 1,2,3,4,5,6,7,8 limit 5;`,
{3, 1, 3, 3, 3, 3},
},
},
{
Query: `select * from (select a,v from ab join uv on a=u) av join (select x,q from xy join pq on x = p) xq on av.v = xq.x`,
Expected: []sql.Row{
{0, 1, 1, 1},
{1, 1, 1, 1},
{2, 2, 2, 2},
{3, 2, 2, 2},
},
},
}

var SkippedJoinQueryTests = []QueryTest{
Expand Down
25 changes: 25 additions & 0 deletions enginetest/queries/query_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,31 @@ type QueryPlanTest struct {
// other features. These tests are fragile because they rely on string representations of query plans, but they're much
// easier to construct this way.
var PlanTests = []QueryPlanTest{
{
Query: "select * from (select a,v from ab join uv on a=u) av join (select x,q from xy join pq on x = p) xq on av.v = xq.x",
ExpectedPlan: "HashJoin(av.v = xq.x)\n" +
" ├─ SubqueryAlias(av)\n" +
" │ └─ Project\n" +
" │ ├─ columns: [ab.a, uv.v]\n" +
" │ └─ LookupJoin(ab.a = uv.u)\n" +
" │ ├─ Table(ab)\n" +
" │ │ └─ columns: [a]\n" +
" │ └─ IndexedTableAccess(uv)\n" +
" │ ├─ index: [uv.u]\n" +
" │ └─ columns: [u v]\n" +
" └─ HashLookup(child: (xq.x), lookup: (av.v))\n" +
" └─ CachedResults\n" +
" └─ SubqueryAlias(xq)\n" +
" └─ Project\n" +
" ├─ columns: [xy.x, pq.q]\n" +
" └─ LookupJoin(xy.x = pq.p)\n" +
" ├─ Table(xy)\n" +
" │ └─ columns: [x]\n" +
" └─ IndexedTableAccess(pq)\n" +
" ├─ index: [pq.p]\n" +
" └─ columns: [p q]\n" +
"",
},
{
Query: `select * from mytable t1 natural join mytable t2 join othertable t3 on t2.i = t3.i2;`,
ExpectedPlan: "InnerJoin(t1.i = t3.i2)\n" +
Expand Down
4 changes: 4 additions & 0 deletions sql/plan/subqueryalias.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ func (sq *SubqueryAlias) Schema() sql.Schema {
func (sq *SubqueryAlias) RowIter(ctx *sql.Context, row sql.Row) (sql.RowIter, error) {
span, ctx := ctx.Span("plan.SubqueryAlias")

if !sq.OuterScopeVisibility {
row = nil
}
iter, err := sq.Child.RowIter(ctx, row)

if err != nil {
span.End()
return nil, err
Expand Down