Skip to content

Commit

Permalink
Subquery row iter fix field indexes (#1350)
Browse files Browse the repository at this point in the history
Recent changes to subquery scope visibility use the scope to communicate
column definition availability; i.e., we do not pass the scope into
subqueries we have determined to not depend on the outer scope, marking
the same scope as cacheable. This analysis change needs a corresponding
runtime change to indicated whether the scope row s expected at
execution time.
  • Loading branch information
max-hoffman authored Oct 25, 2022
1 parent 7d1a405 commit c1ebe90
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
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

0 comments on commit c1ebe90

Please sign in to comment.