2018-01-12 22:39 GMT+01:00 Julian Hyde <[email protected]>:

> > As far as I can understand RexCorrelVariable is like a reference to the
> > "current row”
>
> Yes, that’s correct.
>
> Also, think of a join, say
>
>   select * from Depts as d, Emps as e where e.deptno = d.deptno
>
> implemented as nested loops, reading from an index. Then the pseudo-code is
>
>   for (Dept d in Depts) {
>     for (Emp e in Emps.getByDeptno(d.deptno)) {
>       // output row (d, e)
>     }
>   }
>
> You can think of “d” as several things: in SQL it is a table alias; in
> RelNode/RexNode terms it is a correlating variable, and in the pseudo-code
> it is a loop iteration variable.
>
> “e” is all of those things too, but we don’t bother creating a correlating
> variable because it is never accessed out of its scope; it is always the
> current row read from a particular input RelNode.
>

Thank you Julian, it is clear
I will play with joins in order to understand deeply this concept.

Enrico


>
> Julian
>
>
> > On Jan 12, 2018, at 7:49 AM, Enrico Olivelli <[email protected]>
> wrote:
> >
> > Hi,
> > I am trying to understand the meaning of RexCorrelVariable
> >
> > With this query I get a Plan like this:
> >
> > Query: UPDATE tblspace1.tsql set n2=n2+n2,n3=n3+n2 WHERE k1=?
> >
> > -- Best  Plan
> > EnumerableTableModify(table=[[tblspace1, tsql]], operation=[UPDATE],
> > updateColumnList=[[n2, n3]], sourceExpressionList=[[+($cor0.n2,
> $cor1.n2),
> > +($cor2.n3, $cor3.n2)]], flattened=[true]): rowcount = 1.0, cumulative
> cost
> > = {2.5 rows, 8.5 cpu, 0.0 io}, id = 157
> >  EnumerableProject(k1=[$0], n1=[$1], s1=[$2], t1=[$3], n2=[$4], n3=[$5],
> > EXPR$0=[+($4, $4)], EXPR$1=[+($5, $4)]): rowcount = 1.0, cumulative cost
> =
> > {1.5 rows, 8.5 cpu, 0.0 io}, id = 156
> >    EnumerableInterpreter: rowcount = 1.0, cumulative cost = {0.5 rows,
> 0.5
> > cpu, 0.0 io}, id = 155
> >      BindableTableScan(table=[[tblspace1, tsql]], filters=[[=($0,
> ?0)]]):
> > rowcount = 1.0, cumulative cost = {0.005 rows, 0.01 cpu, 0.0 io}, id =
> 148
> >
> > here we have 4 RexCorrelVariable:
> >
> > sourceExpressionList=[[+($cor0.n2, $cor1.n2), +($cor2.n3, $cor3.n2)]]
> >
> > As far as I can understand RexCorrelVariable is like a reference to the
> > "current row"
> >
> > Is it correct my understanding ?
> >
> > Thank you
> >
> > Enrico
>
>

Reply via email to