Обсуждение: Doubt about boundParams

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

Doubt about boundParams

От
Ashutosh Bapat
Дата:
Hi All,<br />I am looking at usage of bound parameters.<br /><br />In functions SPI_cursor_open_with_args() and
SPI_cursor_open_with_args()parameters are flagged as constants and passed to the planner in following manner,<br
/>paramLI= _SPI_convert_params(nargs, argtypes,<br />                                    Values, Nulls,<br
/>                                  PARAM_FLAG_CONST);<br /><br /> _SPI_prepare_plan(src, &plan, paramLI);<br /><br
/>Thebound params "paramLI" are then passed to the planner as boundParams. Before actually planning the query, these
parametersare evaluated duing constant evaluation (eval_const_expressions_mutator()), and the Param nodes are replaced
withConstant nodes.<br /> Further, while executing such queries we pass the paramLI structure to the execution routine
e.g._SPI_execute_plan(). These parameter values are stored in "EState" structure. But, since these parameters are
alreadyfolded into queries, it looks like parameter values stored in EState are never used.<br /><br />Is this correct?
Orsomewhere we use those parameter values?<br /><br clear="all" /><br />-- <br />Best Wishes,<br />Ashutosh Bapat<br
/>EntepriseDBCorporation<br />The Enterprise Postgres Company<br /><br /> 

Re: Doubt about boundParams

От
Heikki Linnakangas
Дата:
On 02.08.2011 12:54, Ashutosh Bapat wrote:
> Hi All,
> I am looking at usage of bound parameters.
>
> In functions SPI_cursor_open_with_args() and SPI_cursor_open_with_args()
> parameters are flagged as constants and passed to the planner in following
> manner,
> paramLI = _SPI_convert_params(nargs, argtypes,
>                                     Values, Nulls,
>                                     PARAM_FLAG_CONST);
>
>   _SPI_prepare_plan(src,&plan, paramLI);
>
> The bound params "paramLI" are then passed to the planner as boundParams.
> Before actually planning the query, these parameters are evaluated duing
> constant evaluation (eval_const_expressions_mutator()), and the Param nodes
> are replaced with Constant nodes.
> Further, while executing such queries we pass the paramLI structure to the
> execution routine e.g. _SPI_execute_plan(). These parameter values are
> stored in "EState" structure. But, since these parameters are already folded
> into queries, it looks like parameter values stored in EState are never
> used.
>
> Is this correct? Or somewhere we use those parameter values?

That is correct, at the moment. PARAM_FLAG_CONST means that the planner 
is free evaluate the params during planning, but it doesn't have to. You 
still need to pass the params in _SPI_execute_plan() in case the planner 
decided to not convert some params to Consts, even though as the code 
stands today it always will.

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


Re: Doubt about boundParams

От
Ashutosh Bapat
Дата:


On Tue, Aug 2, 2011 at 3:45 PM, Heikki Linnakangas <heikki.linnakangas@enterprisedb.com> wrote:
On 02.08.2011 12:54, Ashutosh Bapat wrote:
Hi All,
I am looking at usage of bound parameters.

In functions SPI_cursor_open_with_args() and SPI_cursor_open_with_args()
parameters are flagged as constants and passed to the planner in following
manner,
paramLI = _SPI_convert_params(nargs, argtypes,
                                   Values, Nulls,
                                   PARAM_FLAG_CONST);

 _SPI_prepare_plan(src,&plan, paramLI);

The bound params "paramLI" are then passed to the planner as boundParams.
Before actually planning the query, these parameters are evaluated duing
constant evaluation (eval_const_expressions_mutator()), and the Param nodes
are replaced with Constant nodes.
Further, while executing such queries we pass the paramLI structure to the
execution routine e.g. _SPI_execute_plan(). These parameter values are
stored in "EState" structure. But, since these parameters are already folded
into queries, it looks like parameter values stored in EState are never
used.

Is this correct? Or somewhere we use those parameter values?

That is correct, at the moment. PARAM_FLAG_CONST means that the planner is free evaluate the params during planning, but it doesn't have to. You still need to pass the params in _SPI_execute_plan() in case the planner decided to not convert some params to Consts, even though as the code stands today it always will.

Ok, thanks.
 

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



--
Best Wishes,
Ashutosh Bapat
EntepriseDB Corporation
The Enterprise Postgres Company