44 const char *sourceText,
55 bool isTopLevel,
bool setHoldSnapshot,
58 bool isTopLevel,
bool setHoldSnapshot,
74 const char *sourceText,
80 int instrument_options)
150 const char *sourceText,
163 dest, params, queryEnv, 0);
168 if (queryDesc->
cplan)
176 elog(
ERROR,
"ExecutorStart() failed unexpectedly");
250 if (query->canSetTag)
254 if (query->hasModifyingCTE)
308 if (query->canSetTag)
549 elog(
ERROR,
"ExecutorStart() failed unexpectedly");
566 portal->
atEnd =
false;
591 portal->
atEnd =
false;
612 portal->
atEnd =
false;
667 natts *
sizeof(
int16));
671 if (nFormats != natts)
673 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
674 errmsg(
"bind message has %d result formats but query has %d columns",
676 memcpy(portal->
formats, formats, natts *
sizeof(
int16));
678 else if (nFormats > 0)
681 int16 format1 = formats[0];
683 for (
i = 0;
i < natts;
i++)
689 for (
i = 0;
i < natts;
i++)
732 TRACE_POSTGRESQL_QUERY_EXECUTE_START();
816 result = portal->
atEnd;
831 elog(
ERROR,
"unrecognized portal strategy: %d",
843 if (saveMemoryContext == saveTopTransactionContext)
848 if (saveResourceOwner == saveTopTransactionResourceOwner)
858 if (saveMemoryContext == saveTopTransactionContext)
863 if (saveResourceOwner == saveTopTransactionResourceOwner)
872 TRACE_POSTGRESQL_QUERY_EXECUTE_DONE();
936 if (portal->
atEnd || count <= 0)
962 if (count == 0 || nprocessed < (
uint64) count)
963 portal->
atEnd =
true;
971 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
972 errmsg(
"cursor can only scan forward"),
973 errhint(
"Declare it with SCROLL option to enable backward scan.")));
975 if (portal->
atStart || count <= 0)
999 if (nprocessed > 0 && portal->
atEnd)
1001 portal->
atEnd =
false;
1004 if (count == 0 || nprocessed < (
uint64) count)
1059 isTopLevel,
true, treceiver, &qc);
1063 elog(
ERROR,
"unsupported portal strategy: %d",
1091 uint64 current_tuple_count = 0;
1126 if (!
dest->receiveSlot(slot,
dest))
1136 current_tuple_count++;
1137 if (count && count == current_tuple_count)
1146 return current_tuple_count;
1155 bool isTopLevel,
bool setHoldSnapshot,
1166 if (setHoldSnapshot)
1187 (portal->
cplan != NULL),
1218 bool isTopLevel,
bool setHoldSnapshot,
1222 bool active_snapshot_set =
false;
1224 int query_index = 0;
1245 foreach(stmtlist_item, portal->
stmts)
1259 TRACE_POSTGRESQL_QUERY_EXECUTE_START();
1270 if (!active_snapshot_set)
1275 if (setHoldSnapshot)
1297 active_snapshot_set =
true;
1330 TRACE_POSTGRESQL_QUERY_EXECUTE_DONE();
1347 Assert(!active_snapshot_set);
1383 if (
lnext(portal->
stmts, stmtlist_item) != NULL)
1390 if (active_snapshot_set)
1484 elog(
ERROR,
"unsupported portal strategy");
1599 else if (count > pos + 1)
1678 return on_row ? 1 : 0;
1706 if (result > 0 && !portal->
atEnd)
1733 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1734 errmsg(
"cursor can only scan forward"),
1735 errhint(
"Declare it with SCROLL option to enable backward scan.")));
1757 portal->
atEnd =
false;
1770 if (utilityStmt == NULL)
1828 elog(
ERROR,
"cannot execute SQL without an outer snapshot or portal");
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
List * FetchPreparedStatementTargetList(PreparedStatement *stmt)
void InitializeQueryCompletion(QueryCompletion *qc)
static void SetQueryCompletion(QueryCompletion *qc, CommandTag commandTag, uint64 nprocessed)
static void CopyQueryCompletion(QueryCompletion *dst, const QueryCompletion *src)
DestReceiver * CreateDestReceiver(CommandDest dest)
DestReceiver * None_Receiver
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
bool ExecutorStart(QueryDesc *queryDesc, int eflags)
void ExecutorStartCachedPlan(QueryDesc *queryDesc, int eflags, CachedPlanSource *plansource, int query_index)
void ExecutorEnd(QueryDesc *queryDesc)
void ExecutorFinish(QueryDesc *queryDesc)
void ExecutorRewind(QueryDesc *queryDesc)
void ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 count)
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
TupleDesc ExecCleanTypeFromTL(List *targetList)
const TupleTableSlotOps TTSOpsMinimalTuple
#define EXEC_FLAG_BACKWARD
Assert(PointerIsAligned(start, uint64))
if(TABLE==NULL||TABLE_index==NULL)
void * MemoryContextAlloc(MemoryContext context, Size size)
MemoryContext TopTransactionContext
void pfree(void *pointer)
void MemoryContextDeleteChildren(MemoryContext context)
MemoryContext CurrentMemoryContext
MemoryContext PortalContext
#define CHECK_FOR_INTERRUPTS()
#define IsA(nodeptr, _type_)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
#define CURSOR_OPT_SCROLL
#define CURSOR_OPT_NO_SCROLL
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define linitial_node(type, l)
static ListCell * lnext(const List *l, const ListCell *c)
void MarkPortalDone(Portal portal)
void MarkPortalFailed(Portal portal)
PlannedStmt * PortalGetPrimaryStmt(Portal portal)
void MarkPortalActive(Portal portal)
Portal GetPortalByName(const char *name)
void PortalCreateHoldStore(Portal portal)
void ShowUsage(const char *title)
void FreeQueryDesc(QueryDesc *qdesc)
PortalStrategy ChoosePortalStrategy(List *stmts)
static void PortalRunMulti(Portal portal, bool isTopLevel, bool setHoldSnapshot, DestReceiver *dest, DestReceiver *altdest, QueryCompletion *qc)
static void FillPortalStore(Portal portal, bool isTopLevel)
bool PlannedStmtRequiresSnapshot(PlannedStmt *pstmt)
void EnsurePortalSnapshotExists(void)
void PortalSetResultFormat(Portal portal, int nFormats, int16 *formats)
void PortalStart(Portal portal, ParamListInfo params, int eflags, Snapshot snapshot)
static uint64 PortalRunSelect(Portal portal, bool forward, long count, DestReceiver *dest)
static uint64 RunFromStore(Portal portal, ScanDirection direction, uint64 count, DestReceiver *dest)
List * FetchStatementTargetList(Node *stmt)
uint64 PortalRunFetch(Portal portal, FetchDirection fdirection, long count, DestReceiver *dest)
QueryDesc * CreateQueryDesc(PlannedStmt *plannedstmt, CachedPlan *cplan, const char *sourceText, Snapshot snapshot, Snapshot crosscheck_snapshot, DestReceiver *dest, ParamListInfo params, QueryEnvironment *queryEnv, int instrument_options)
static void ProcessQuery(PlannedStmt *plan, CachedPlan *cplan, CachedPlanSource *plansource, int query_index, const char *sourceText, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
List * FetchPortalTargetList(Portal portal)
bool PortalRun(Portal portal, long count, bool isTopLevel, DestReceiver *dest, DestReceiver *altdest, QueryCompletion *qc)
static uint64 DoPortalRunFetch(Portal portal, FetchDirection fdirection, long count, DestReceiver *dest)
static void DoPortalRewind(Portal portal)
static void PortalRunUtility(Portal portal, PlannedStmt *pstmt, bool isTopLevel, bool setHoldSnapshot, DestReceiver *dest, QueryCompletion *qc)
ResourceOwner TopTransactionResourceOwner
ResourceOwner CurrentResourceOwner
#define ScanDirectionIsForward(direction)
#define ScanDirectionIsNoMovement(direction)
@ NoMovementScanDirection
Snapshot GetTransactionSnapshot(void)
void UnregisterSnapshot(Snapshot snapshot)
void PushActiveSnapshot(Snapshot snapshot)
void UpdateActiveSnapshotCommandId(void)
bool ActiveSnapshotSet(void)
Snapshot RegisterSnapshot(Snapshot snapshot)
void PopActiveSnapshot(void)
void PushCopiedSnapshot(Snapshot snapshot)
void PushActiveSnapshotWithLevel(Snapshot snapshot, int snap_level)
Snapshot GetActiveSnapshot(void)
CachedPlanSource * plansource
MemoryContext holdContext
QueryEnvironment * queryEnv
MemoryContext portalContext
ParamListInfo portalParams
Tuplestorestate * holdStore
PlannedStmt * plannedstmt
struct Instrumentation * totaltime
QueryEnvironment * queryEnv
Snapshot crosscheck_snapshot
void(* rDestroy)(DestReceiver *self)
void SetTuplestoreDestReceiverParams(DestReceiver *self, Tuplestorestate *tStore, MemoryContext tContext, bool detoast, TupleDesc target_tupdesc, const char *map_failure_msg)
bool tuplestore_gettupleslot(Tuplestorestate *state, bool forward, bool copy, TupleTableSlot *slot)
void tuplestore_rescan(Tuplestorestate *state)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
void ProcessUtility(PlannedStmt *pstmt, const char *queryString, bool readOnlyTree, ProcessUtilityContext context, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
bool UtilityReturnsTuples(Node *parsetree)
TupleDesc UtilityTupleDescriptor(Node *parsetree)
@ PROCESS_UTILITY_TOPLEVEL
void CommandCounterIncrement(void)