Обсуждение: ExecEvalVar does not have appropriate ExprState?

Поиск
Список
Период
Сортировка

ExecEvalVar does not have appropriate ExprState?

От
Vaibhav Kaushal
Дата:
Hi,

I see the ExecInitExpr says something like this:
------------
case T_Var:state = (ExprState *) makeNode(ExprState);state->evalfunc = ExecEvalVar;
---------------


But the ExecEvalVar function definition says:

------------------------
Var           *variable = (Var *) exprstate->expr;TupleTableSlot *slot;AttrNumber    attnum;
if (isDone)    *isDone = ExprSingleResult;
/* Get the input slot and attribute number we want */switch (variable->varno){    case INNER:                /* get the
tuplefrom the inner node */
 
-------------------------


Since ExprState -> expr in its final form would finally contain only:

NodeTag        type;

I think that the pointer being cast in the ExecEvalVar is actually
already a form of Var which is passed around as Expr for sake of
function call. 

So, was the node in the Expr tree for the corresponding ExprState node
of the ExprState tree actually a 'Var'? I think without this being the
reality, the function ExecEvalVar would crash! In my belief, the similar
fact would stand for a few other nodes, notably Const, Param,
CoerceToDomain and CaseTest.

Also, I have tried, but failed to fidn the exact place where the Expr
tree is created. Just pointing me to the file / function which does this
would be of great help. 

Kindly correct me if I am wrong.

Regards,
Vaibhav 



Re: ExecEvalVar does not have appropriate ExprState?

От
Heikki Linnakangas
Дата:
On 28.03.2011 10:02, Vaibhav Kaushal wrote:
> Hi,
>
> I see the ExecInitExpr says something like this:
> ------------
> case T_Var:
>     state = (ExprState *) makeNode(ExprState);
>     state->evalfunc = ExecEvalVar;
> ---------------
>
>
> But the ExecEvalVar function definition says:
>
> ------------------------
> Var           *variable = (Var *) exprstate->expr;
>     TupleTableSlot *slot;
>     AttrNumber    attnum;
>
>     if (isDone)
>         *isDone = ExprSingleResult;
>
>     /* Get the input slot and attribute number we want */
>     switch (variable->varno)
>     {
>         case INNER:                /* get the tuple from the inner node */
> -------------------------
>
>
> Since ExprState ->  expr in its final form would finally contain only:
>
> NodeTag        type;
>
> I think that the pointer being cast in the ExecEvalVar is actually
> already a form of Var which is passed around as Expr for sake of
> function call.

Right, exprstate->expr is a Var in ExecEvalVar.

> So, was the node in the Expr tree for the corresponding ExprState node
> of the ExprState tree actually a 'Var'?

Yes.

> Also, I have tried, but failed to fidn the exact place where the Expr
> tree is created. Just pointing me to the file / function which does this
> would be of great help.

A raw expression tree is created in the grammar, 
src/backend/parser/gram.y. It is then transformed in parse analysis 
phase to the form the planner accepts, in transformExpr(). The planner 
can do some further transformations, like replacing immutable function 
calls with Consts.

--   Heikki Linnakangas  EnterpriseDB   http://www.enterprisedb.com


Re: ExecEvalVar does not have appropriate ExprState?

От
Vaibhav Kaushal
Дата:
Thanks for the confirmation. I am happy to have understood some basics of PG. <br /><br />Also, I think the similar
standsfor the Const, Param,<br /> CoerceToDomain and CaseTest nodes, right? They too cast the pointer to another type.
<br/><br />Thanks for the help Heikki. (I could better call you HL, if you dont mind :P )<br /><br />Regards,<br
/>Vaibhav<br/><br /><br /><div class="gmail_quote">On Mon, Mar 28, 2011 at 1:05 PM, Heikki Linnakangas <span
dir="ltr"><<ahref="mailto:heikki.linnakangas@enterprisedb.com">heikki.linnakangas@enterprisedb.com</a>></span>
wrote:<br/><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div
class="im">On28.03.2011 10:02, Vaibhav Kaushal wrote:<br /><blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px#ccc solid;padding-left:1ex"> Hi,<br /><br /> I see the ExecInitExpr says something like this:<br
/>------------<br /> case T_Var:<br />        state = (ExprState *) makeNode(ExprState);<br />      
 state->evalfunc= ExecEvalVar;<br /> ---------------<br /><br /><br /> But the ExecEvalVar function definition
says:<br/><br /> ------------------------<br /> Var                *variable = (Var *) exprstate->expr;<br />      
 TupleTableSlot*slot;<br />        AttrNumber      attnum;<br /><br />        if (isDone)<br />                *isDone
=ExprSingleResult;<br /><br />        /* Get the input slot and attribute number we want */<br />        switch
(variable->varno)<br/>        {<br />                case INNER:                             /* get the tuple from
theinner node */<br /> -------------------------<br /><br /><br /> Since ExprState ->  expr in its final form would
finallycontain only:<br /><br /> NodeTag         type;<br /><br /> I think that the pointer being cast in the
ExecEvalVaris actually<br /> already a form of Var which is passed around as Expr for sake of<br /> function call.<br
/></blockquote><br/></div> Right, exprstate->expr is a Var in ExecEvalVar.<div class="im"><br /><br /><blockquote
class="gmail_quote"style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> So, was the node in the Expr
treefor the corresponding ExprState node<br /> of the ExprState tree actually a 'Var'?<br /></blockquote><br /></div>
Yes.<divclass="im"><br /><br /><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc
solid;padding-left:1ex">Also, I have tried, but failed to fidn the exact place where the Expr<br /> tree is created.
Justpointing me to the file / function which does this<br /> would be of great help.<br /></blockquote><br /></div> A
rawexpression tree is created in the grammar, src/backend/parser/gram.y. It is then transformed in parse analysis phase
tothe form the planner accepts, in transformExpr(). The planner can do some further transformations, like replacing
immutablefunction calls with Consts.<br /><font color="#888888"><br /> -- <br />  Heikki Linnakangas<br />
 EnterpriseDB  <a href="http://www.enterprisedb.com" target="_blank">http://www.enterprisedb.com</a><br
/></font></blockquote></div><br/> 

Re: ExecEvalVar does not have appropriate ExprState?

От
Heikki Linnakangas
Дата:
On 28.03.2011 10:44, Vaibhav Kaushal wrote:
> Also, I think the similar stands for the Const, Param,
> CoerceToDomain and CaseTest nodes, right? They too cast the pointer to
> another type.

Yep.

--   Heikki Linnakangas  EnterpriseDB   http://www.enterprisedb.com