Postgresql 中文操作指南
SPI_execute_plan_extended
SPI_execute_plan_extended — 执行由 SPI_prepare 准备的语句
SPI_execute_plan_extended — execute a statement prepared by SPI_prepare
Description
SPI_execute_plan_extended 执行由 SPI_prepare 或其同级准备的语句。该函数等效于 SPI_execute_plan ,不同的是,以不同的方式呈现要传递到该查询的参数值的详细信息,并且可以传递额外的执行控制选项。
SPI_execute_plan_extended executes a statement prepared by SPI_prepare or one of its siblings. This function is equivalent to SPI_execute_plan, except that information about the parameter values to be passed to the query is presented differently, and additional execution-controlling options can be passed.
查询参数值由一个 ParamListInfo 结构表示,这对于传递该格式中已有的值非常方便。还可以通过在 ParamListInfo 中指定挂钩函数来使用动态参数集。
Query parameter values are represented by a ParamListInfo struct, which is convenient for passing down values that are already available in that format. Dynamic parameter sets can also be used, via hook functions specified in ParamListInfo.
此外,除了总是将结果元组累积到一个 SPI_tuptable 结构中之外,元组还可以被传递到调用者提供的 DestReceiver 对象中,就像它们由执行程序生成时一样。这对于可能生成众多元组的查询特别有用,因为可以动态地处理数据,而不是将数据累积到内存中。
Also, instead of always accumulating the result tuples into a SPI_tuptable structure, tuples can be passed to a caller-supplied DestReceiver object as they are generated by the executor. This is particularly helpful for queries that might generate many tuples, since the data can be processed on-the-fly instead of being accumulated in memory.
Arguments
-
SPIPlanPtr _plan_
-
prepared statement (returned by SPI_prepare)
-
-
const SPIExecuteOptions * _options_
-
struct containing optional arguments
-
调用者应始终将整个 options 结构清零,然后填写任何他们想要设置的字段。这样可以确保代码的前向兼容性,因为将来添加到结构中的任何字段都被定义为在为零时向后兼容地工作。当前可用的 options 字段为:
Callers should always zero out the entire options struct, then fill whichever fields they want to set. This ensures forward compatibility of code, since any fields that are added to the struct in future will be defined to behave backwards-compatibly if they are zero. The currently available options fields are:
-
ParamListInfo _params_
-
data structure containing query parameter types and values; NULL if none
-
-
bool _read_only_
-
true for read-only execution
-
-
bool _allow_nonatomic_
-
true allows non-atomic execution of CALL and DO statements
-
-
bool _must_return_tuples_
-
if true, raise error if the query is not of a kind that returns tuples (this does not forbid the case where it happens to return zero tuples)
-
-
uint64 _tcount_
-
maximum number of rows to return, or 0 for no limit
-
-
DestReceiver * _dest_
-
DestReceiver object that will receive any tuples emitted by the query; if NULL, result tuples are accumulated into a SPI_tuptable structure, as in SPI_execute_plan
-
-
ResourceOwner _owner_
-
The resource owner that will hold a reference count on the plan while it is executed. If NULL, CurrentResourceOwner is used. Ignored for non-saved plans, as SPI does not acquire reference counts on those.
-
Return Value
返回值同 SPI_execute_plan 。
The return value is the same as for SPI_execute_plan.
当 options→dest 为 NULL 时, SPI_processed 和 SPI_tuptable 设置为 SPI_execute_plan 中的值。当 options→dest 不为 NULL 时, SPI_processed 设置为 0, SPI_tuptable 设置为 NULL。如果需要元组计数,则调用方的 DestReceiver 对象必须计算它。
When options→dest is NULL, SPI_processed and SPI_tuptable are set as in SPI_execute_plan. When options→dest is not NULL, SPI_processed is set to zero and SPI_tuptable is set to NULL. If a tuple count is required, the caller’s DestReceiver object must calculate it.