39 const char *sourceText,
50 bool isTopLevel,
bool setHoldSnapshot,
53 bool isTopLevel,
bool setHoldSnapshot,
68 const char *sourceText,
74 int instrument_options)
137 const char *sourceText,
150 dest, params, queryEnv, 0);
228 if (query->canSetTag)
232 if (query->hasModifyingCTE)
286 if (query->canSetTag)
533 portal->
atEnd =
false;
558 portal->
atEnd =
false;
579 portal->
atEnd =
false;
634 natts *
sizeof(
int16));
638 if (nFormats != natts)
640 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
641 errmsg(
"bind message has %d result formats but query has %d columns",
643 memcpy(portal->
formats, formats, natts *
sizeof(
int16));
645 else if (nFormats > 0)
648 int16 format1 = formats[0];
650 for (
i = 0;
i < natts;
i++)
656 for (
i = 0;
i < natts;
i++)
699 TRACE_POSTGRESQL_QUERY_EXECUTE_START();
787 result = portal->
atEnd;
802 elog(
ERROR,
"unrecognized portal strategy: %d",
814 if (saveMemoryContext == saveTopTransactionContext)
819 if (saveResourceOwner == saveTopTransactionResourceOwner)
829 if (saveMemoryContext == saveTopTransactionContext)
834 if (saveResourceOwner == saveTopTransactionResourceOwner)
843 TRACE_POSTGRESQL_QUERY_EXECUTE_DONE();
907 if (portal->
atEnd || count <= 0)
934 if (count == 0 || nprocessed < (uint64) count)
935 portal->
atEnd =
true;
943 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
944 errmsg(
"cursor can only scan forward"),
945 errhint(
"Declare it with SCROLL option to enable backward scan.")));
947 if (portal->
atStart || count <= 0)
972 if (nprocessed > 0 && portal->
atEnd)
974 portal->
atEnd =
false;
977 if (count == 0 || nprocessed < (uint64) count)
1032 isTopLevel,
true, treceiver, &qc);
1036 elog(
ERROR,
"unsupported portal strategy: %d",
1064 uint64 current_tuple_count = 0;
1099 if (!
dest->receiveSlot(slot,
dest))
1109 current_tuple_count++;
1110 if (count && count == current_tuple_count)
1119 return current_tuple_count;
1128 bool isTopLevel,
bool setHoldSnapshot,
1139 if (setHoldSnapshot)
1160 (portal->
cplan != NULL),
1192 bool isTopLevel,
bool setHoldSnapshot,
1196 bool active_snapshot_set =
false;
1218 foreach(stmtlist_item, portal->
stmts)
1232 TRACE_POSTGRESQL_QUERY_EXECUTE_START();
1243 if (!active_snapshot_set)
1248 if (setHoldSnapshot)
1270 active_snapshot_set =
true;
1297 TRACE_POSTGRESQL_QUERY_EXECUTE_DONE();
1314 Assert(!active_snapshot_set);
1350 if (
lnext(portal->
stmts, stmtlist_item) != NULL)
1355 if (active_snapshot_set)
1452 elog(
ERROR,
"unsupported portal strategy");
1550 if ((uint64) (count - 1) <= portal->
portalPos / 2 ||
1567 else if (count > pos + 1)
1646 return on_row ? 1 : 0;
1674 if (result > 0 && !portal->
atEnd)
1701 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1702 errmsg(
"cursor can only scan forward"),
1703 errhint(
"Declare it with SCROLL option to enable backward scan.")));
1725 portal->
atEnd =
false;
1738 if (utilityStmt == NULL)
1796 elog(
ERROR,
"cannot execute SQL without an outer snapshot or portal");
PreparedStatement * FetchPreparedStatement(const char *stmt_name, bool throwError)
List * FetchPreparedStatementTargetList(PreparedStatement *stmt)
#define Assert(condition)
void InitializeQueryCompletion(QueryCompletion *qc)
static void SetQueryCompletion(QueryCompletion *qc, CommandTag commandTag, uint64 nprocessed)
static void CopyQueryCompletion(QueryCompletion *dst, const QueryCompletion *src)
DestReceiver * None_Receiver
DestReceiver * CreateDestReceiver(CommandDest dest)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void ExecutorEnd(QueryDesc *queryDesc)
void ExecutorFinish(QueryDesc *queryDesc)
void ExecutorRewind(QueryDesc *queryDesc)
void ExecutorStart(QueryDesc *queryDesc, int eflags)
void ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 count, bool execute_once)
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
TupleDesc ExecCleanTypeFromTL(List *targetList)
const TupleTableSlotOps TTSOpsMinimalTuple
TupleTableSlot * MakeSingleTupleTableSlot(TupleDesc tupdesc, const TupleTableSlotOps *tts_ops)
#define EXEC_FLAG_BACKWARD
if(TABLE==NULL||TABLE_index==NULL)
MemoryContext TopTransactionContext
void pfree(void *pointer)
void MemoryContextDeleteChildren(MemoryContext context)
MemoryContext CurrentMemoryContext
void * MemoryContextAlloc(MemoryContext context, Size size)
MemoryContext PortalContext
#define CHECK_FOR_INTERRUPTS()
#define IsA(nodeptr, _type_)
#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)
void MarkPortalActive(Portal portal)
Portal GetPortalByName(const char *name)
PlannedStmt * PortalGetPrimaryStmt(Portal portal)
void PortalCreateHoldStore(Portal portal)
void ShowUsage(const char *title)
void FreeQueryDesc(QueryDesc *qdesc)
PortalStrategy ChoosePortalStrategy(List *stmts)
List * FetchStatementTargetList(Node *stmt)
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)
QueryDesc * CreateQueryDesc(PlannedStmt *plannedstmt, const char *sourceText, Snapshot snapshot, Snapshot crosscheck_snapshot, DestReceiver *dest, ParamListInfo params, QueryEnvironment *queryEnv, int instrument_options)
static uint64 RunFromStore(Portal portal, ScanDirection direction, uint64 count, DestReceiver *dest)
uint64 PortalRunFetch(Portal portal, FetchDirection fdirection, long count, DestReceiver *dest)
static void ProcessQuery(PlannedStmt *plan, const char *sourceText, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc)
bool PortalRun(Portal portal, long count, bool isTopLevel, bool run_once, DestReceiver *dest, DestReceiver *altdest, QueryCompletion *qc)
static uint64 DoPortalRunFetch(Portal portal, FetchDirection fdirection, long count, DestReceiver *dest)
List * FetchPortalTargetList(Portal portal)
static void DoPortalRewind(Portal portal)
static void PortalRunUtility(Portal portal, PlannedStmt *pstmt, bool isTopLevel, bool setHoldSnapshot, DestReceiver *dest, QueryCompletion *qc)
MemoryContextSwitchTo(old_ctx)
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)
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)