PostgreSQL Source Code git master
|
#include "postgres.h"
#include <limits.h>
#include "access/xact.h"
#include "commands/prepare.h"
#include "executor/tstoreReceiver.h"
#include "miscadmin.h"
#include "pg_trace.h"
#include "tcop/pquery.h"
#include "tcop/utility.h"
#include "utils/memutils.h"
#include "utils/snapmgr.h"
Go to the source code of this file.
Functions | |
static void | ProcessQuery (PlannedStmt *plan, const char *sourceText, ParamListInfo params, QueryEnvironment *queryEnv, DestReceiver *dest, QueryCompletion *qc) |
static void | FillPortalStore (Portal portal, bool isTopLevel) |
static uint64 | RunFromStore (Portal portal, ScanDirection direction, uint64 count, DestReceiver *dest) |
static uint64 | PortalRunSelect (Portal portal, bool forward, long count, DestReceiver *dest) |
static void | PortalRunUtility (Portal portal, PlannedStmt *pstmt, bool isTopLevel, bool setHoldSnapshot, DestReceiver *dest, QueryCompletion *qc) |
static void | PortalRunMulti (Portal portal, bool isTopLevel, bool setHoldSnapshot, DestReceiver *dest, DestReceiver *altdest, QueryCompletion *qc) |
static uint64 | DoPortalRunFetch (Portal portal, FetchDirection fdirection, long count, DestReceiver *dest) |
static void | DoPortalRewind (Portal portal) |
QueryDesc * | CreateQueryDesc (PlannedStmt *plannedstmt, const char *sourceText, Snapshot snapshot, Snapshot crosscheck_snapshot, DestReceiver *dest, ParamListInfo params, QueryEnvironment *queryEnv, int instrument_options) |
void | FreeQueryDesc (QueryDesc *qdesc) |
PortalStrategy | ChoosePortalStrategy (List *stmts) |
List * | FetchPortalTargetList (Portal portal) |
List * | FetchStatementTargetList (Node *stmt) |
void | PortalStart (Portal portal, ParamListInfo params, int eflags, Snapshot snapshot) |
void | PortalSetResultFormat (Portal portal, int nFormats, int16 *formats) |
bool | PortalRun (Portal portal, long count, bool isTopLevel, DestReceiver *dest, DestReceiver *altdest, QueryCompletion *qc) |
uint64 | PortalRunFetch (Portal portal, FetchDirection fdirection, long count, DestReceiver *dest) |
bool | PlannedStmtRequiresSnapshot (PlannedStmt *pstmt) |
void | EnsurePortalSnapshotExists (void) |
Variables | |
Portal | ActivePortal = NULL |
PortalStrategy ChoosePortalStrategy | ( | List * | stmts | ) |
Definition at line 209 of file pquery.c.
References PlannedStmt::canSetTag, CMD_SELECT, CMD_UTILITY, Query::commandType, PlannedStmt::commandType, elog, ERROR, PlannedStmt::hasModifyingCTE, PlannedStmt::hasReturning, IsA, lfirst, linitial, list_length(), NIL, nodeTag, PORTAL_MULTI_QUERY, PORTAL_ONE_MOD_WITH, PORTAL_ONE_RETURNING, PORTAL_ONE_SELECT, PORTAL_UTIL_SELECT, Query::returningList, stmt, UtilityReturnsTuples(), Query::utilityStmt, and PlannedStmt::utilityStmt.
Referenced by PlanCacheComputeResultDesc(), and PortalStart().
QueryDesc * CreateQueryDesc | ( | PlannedStmt * | plannedstmt, |
const char * | sourceText, | ||
Snapshot | snapshot, | ||
Snapshot | crosscheck_snapshot, | ||
DestReceiver * | dest, | ||
ParamListInfo | params, | ||
QueryEnvironment * | queryEnv, | ||
int | instrument_options | ||
) |
Definition at line 67 of file pquery.c.
References QueryDesc::already_executed, PlannedStmt::commandType, QueryDesc::crosscheck_snapshot, generate_unaccent_rules::dest, QueryDesc::dest, QueryDesc::estate, QueryDesc::instrument_options, QueryDesc::operation, palloc(), QueryDesc::params, QueryDesc::plannedstmt, QueryDesc::planstate, QueryDesc::queryEnv, RegisterSnapshot(), QueryDesc::snapshot, QueryDesc::sourceText, QueryDesc::totaltime, and QueryDesc::tupDesc.
Referenced by _SPI_execute_plan(), BeginCopyTo(), ExecCreateTableAs(), ExecParallelGetQueryDesc(), execute_sql_string(), ExplainOnePlan(), PortalStart(), postquel_start(), ProcessQuery(), and refresh_matview_datafill().
|
static |
Definition at line 1677 of file pquery.c.
References PortalData::atEnd, PortalData::atStart, CURSOR_OPT_NO_SCROLL, PortalData::cursorOptions, ereport, errcode(), errhint(), errmsg(), ERROR, ExecutorRewind(), PortalData::holdContext, PortalData::holdStore, MemoryContextSwitchTo(), PopActiveSnapshot(), PortalData::portalPos, PushActiveSnapshot(), PortalData::queryDesc, QueryDesc::snapshot, and tuplestore_rescan().
Referenced by DoPortalRunFetch().
|
static |
Definition at line 1483 of file pquery.c.
References Assert, PortalData::atEnd, PortalData::atStart, generate_unaccent_rules::dest, DestNone, DoPortalRewind(), elog, ERROR, FETCH_ABSOLUTE, FETCH_ALL, FETCH_BACKWARD, FETCH_FORWARD, FETCH_RELATIVE, if(), None_Receiver, PORTAL_ONE_MOD_WITH, PORTAL_ONE_RETURNING, PORTAL_ONE_SELECT, PORTAL_UTIL_SELECT, PortalData::portalPos, PortalRunSelect(), and PortalData::strategy.
Referenced by PortalRunFetch().
void EnsurePortalSnapshotExists | ( | void | ) |
Definition at line 1771 of file pquery.c.
References ActivePortal, ActiveSnapshotSet(), Assert, PortalData::createLevel, elog, ERROR, GetActiveSnapshot(), GetTransactionSnapshot(), PortalData::portalSnapshot, PushActiveSnapshotWithLevel(), and unlikely.
Referenced by _SPI_execute_plan(), exec_eval_simple_expr(), and ExecuteCallStmt().
Definition at line 326 of file pquery.c.
References FetchStatementTargetList(), NIL, PORTAL_MULTI_QUERY, PortalGetPrimaryStmt(), and PortalData::strategy.
Referenced by exec_describe_portal_message(), FetchStatementTargetList(), and printtup_startup().
Definition at line 348 of file pquery.c.
References Assert, CMD_SELECT, CMD_UTILITY, Query::commandType, PlannedStmt::commandType, FetchPortalTargetList(), FetchPreparedStatement(), FetchPreparedStatementTargetList(), GetPortalByName(), PlannedStmt::hasReturning, IsA, FetchStmt::ismove, ExecuteStmt::name, NIL, PlannedStmt::planTree, PortalIsValid, FetchStmt::portalname, Query::returningList, stmt, Query::targetList, Plan::targetlist, Query::utilityStmt, and PlannedStmt::utilityStmt.
Referenced by CachedPlanGetTargetList(), and FetchPortalTargetList().
|
static |
Definition at line 994 of file pquery.c.
References QueryCompletion::commandTag, CopyQueryCompletion(), CreateDestReceiver(), DestTuplestore, elog, ERROR, PortalData::holdContext, PortalData::holdStore, InitializeQueryCompletion(), linitial_node, None_Receiver, PORTAL_ONE_MOD_WITH, PORTAL_ONE_RETURNING, PORTAL_UTIL_SELECT, PortalCreateHoldStore(), PortalRunMulti(), PortalRunUtility(), PortalData::qc, _DestReceiver::rDestroy, SetTuplestoreDestReceiverParams(), PortalData::stmts, and PortalData::strategy.
Referenced by PortalRun(), and PortalRunFetch().
void FreeQueryDesc | ( | QueryDesc * | qdesc | ) |
Definition at line 105 of file pquery.c.
References Assert, QueryDesc::crosscheck_snapshot, QueryDesc::estate, pfree(), QueryDesc::snapshot, and UnregisterSnapshot().
Referenced by _SPI_execute_plan(), EndCopyTo(), ExecCreateTableAs(), execute_sql_string(), ExplainOnePlan(), ParallelQueryMain(), PersistHoldablePortal(), PortalCleanup(), postquel_end(), ProcessQuery(), and refresh_matview_datafill().
bool PlannedStmtRequiresSnapshot | ( | PlannedStmt * | pstmt | ) |
Definition at line 1723 of file pquery.c.
References IsA, and PlannedStmt::utilityStmt.
Referenced by _SPI_execute_plan(), and PortalRunUtility().
bool PortalRun | ( | Portal | portal, |
long | count, | ||
bool | isTopLevel, | ||
DestReceiver * | dest, | ||
DestReceiver * | altdest, | ||
QueryCompletion * | qc | ||
) |
Definition at line 684 of file pquery.c.
References ActivePortal, Assert, PortalData::atEnd, QueryCompletion::commandTag, CopyQueryCompletion(), CurrentMemoryContext, CurrentResourceOwner, DEBUG3, generate_unaccent_rules::dest, elog, ERROR, FillPortalStore(), PortalData::holdStore, InitializeQueryCompletion(), log_executor_stats, MarkPortalActive(), MarkPortalDone(), MarkPortalFailed(), MemoryContextSwitchTo(), QueryCompletion::nprocessed, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, PORTAL_MULTI_QUERY, PORTAL_ONE_MOD_WITH, PORTAL_ONE_RETURNING, PORTAL_ONE_SELECT, PORTAL_READY, PORTAL_UTIL_SELECT, PortalContext, PortalData::portalContext, PortalIsValid, PortalRunMulti(), PortalRunSelect(), PortalData::qc, ResetUsage(), PortalData::resowner, ShowUsage(), PortalData::status, PortalData::strategy, TopTransactionContext, and TopTransactionResourceOwner.
Referenced by exec_execute_message(), exec_simple_query(), and ExecuteQuery().
uint64 PortalRunFetch | ( | Portal | portal, |
FetchDirection | fdirection, | ||
long | count, | ||
DestReceiver * | dest | ||
) |
Definition at line 1385 of file pquery.c.
References ActivePortal, Assert, CurrentResourceOwner, generate_unaccent_rules::dest, DoPortalRunFetch(), elog, ERROR, FillPortalStore(), PortalData::holdStore, MarkPortalActive(), MarkPortalFailed(), MemoryContextSwitchTo(), PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, PORTAL_ONE_MOD_WITH, PORTAL_ONE_RETURNING, PORTAL_ONE_SELECT, PORTAL_READY, PORTAL_UTIL_SELECT, PortalContext, PortalData::portalContext, PortalIsValid, PortalData::resowner, PortalData::status, and PortalData::strategy.
Referenced by _SPI_cursor_operation(), and PerformPortalFetch().
|
static |
Definition at line 1184 of file pquery.c.
References Assert, PlannedStmt::canSetTag, CHECK_FOR_INTERRUPTS, CommandCounterIncrement(), QueryCompletion::commandTag, CopyQueryCompletion(), CurrentMemoryContext, generate_unaccent_rules::dest, DestRemoteExecute, GetTransactionSnapshot(), PortalData::holdSnapshot, IsA, lfirst_node, lnext(), log_executor_stats, MemoryContextDeleteChildren(), _DestReceiver::mydest, NIL, None_Receiver, PopActiveSnapshot(), PortalData::portalContext, PortalData::portalParams, PortalRunUtility(), ProcessQuery(), PushCopiedSnapshot(), PortalData::qc, PortalData::queryEnv, RegisterSnapshot(), ResetUsage(), ShowUsage(), PortalData::sourceText, PortalData::stmts, UpdateActiveSnapshotCommandId(), and PlannedStmt::utilityStmt.
Referenced by FillPortalStore(), and PortalRun().
|
static |
Definition at line 863 of file pquery.c.
References Assert, PortalData::atEnd, PortalData::atStart, BackwardScanDirection, CURSOR_OPT_NO_SCROLL, PortalData::cursorOptions, generate_unaccent_rules::dest, QueryDesc::dest, ereport, errcode(), errhint(), errmsg(), ERROR, EState::es_processed, QueryDesc::estate, ExecutorRun(), FETCH_ALL, ForwardScanDirection, PortalData::holdStore, NoMovementScanDirection, PopActiveSnapshot(), PortalData::portalPos, PushActiveSnapshot(), PortalData::queryDesc, RunFromStore(), ScanDirectionIsNoMovement, and QueryDesc::snapshot.
Referenced by DoPortalRunFetch(), and PortalRun().
|
static |
Definition at line 1121 of file pquery.c.
References ActiveSnapshotSet(), Assert, PortalData::cplan, PortalData::createLevel, generate_unaccent_rules::dest, GetActiveSnapshot(), GetTransactionSnapshot(), PortalData::holdSnapshot, MemoryContextSwitchTo(), PlannedStmtRequiresSnapshot(), PopActiveSnapshot(), PortalData::portalContext, PortalData::portalParams, PortalData::portalSnapshot, PROCESS_UTILITY_QUERY, PROCESS_UTILITY_TOPLEVEL, ProcessUtility(), PushActiveSnapshotWithLevel(), PortalData::queryEnv, RegisterSnapshot(), and PortalData::sourceText.
Referenced by FillPortalStore(), and PortalRunMulti().
Definition at line 623 of file pquery.c.
References ereport, errcode(), errmsg(), ERROR, PortalData::formats, i, MemoryContextAlloc(), TupleDescData::natts, PortalData::portalContext, and PortalData::tupDesc.
Referenced by exec_bind_message(), and exec_simple_query().
void PortalStart | ( | Portal | portal, |
ParamListInfo | params, | ||
int | eflags, | ||
Snapshot | snapshot | ||
) |
Definition at line 433 of file pquery.c.
References ActivePortal, Assert, PortalData::atEnd, PortalData::atStart, ChoosePortalStrategy(), CMD_UTILITY, PlannedStmt::commandType, CreateQueryDesc(), CurrentResourceOwner, CURSOR_OPT_SCROLL, PortalData::cursorOptions, EXEC_FLAG_BACKWARD, EXEC_FLAG_REWIND, ExecCleanTypeFromTL(), ExecutorStart(), GetActiveSnapshot(), GetTransactionSnapshot(), InvalidSnapshot, linitial_node, MarkPortalFailed(), MemoryContextSwitchTo(), None_Receiver, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, PlannedStmt::planTree, PopActiveSnapshot(), PORTAL_DEFINED, PORTAL_MULTI_QUERY, PORTAL_ONE_MOD_WITH, PORTAL_ONE_RETURNING, PORTAL_ONE_SELECT, PORTAL_READY, PORTAL_UTIL_SELECT, PortalContext, PortalData::portalContext, PortalGetPrimaryStmt(), PortalIsValid, PortalData::portalParams, PortalData::portalPos, PushActiveSnapshot(), PortalData::queryDesc, PortalData::queryEnv, PortalData::resowner, PortalData::sourceText, PortalData::status, PortalData::stmts, PortalData::strategy, Plan::targetlist, QueryDesc::tupDesc, PortalData::tupDesc, PlannedStmt::utilityStmt, and UtilityTupleDescriptor().
Referenced by exec_bind_message(), exec_simple_query(), ExecuteQuery(), PerformCursorOpen(), and SPI_cursor_open_internal().
|
static |
Definition at line 136 of file pquery.c.
References CMD_DELETE, CMD_INSERT, CMD_MERGE, CMD_SELECT, CMD_UPDATE, CreateQueryDesc(), generate_unaccent_rules::dest, EState::es_processed, QueryDesc::estate, ExecutorEnd(), ExecutorFinish(), ExecutorRun(), ExecutorStart(), ForwardScanDirection, FreeQueryDesc(), GetActiveSnapshot(), InvalidSnapshot, QueryDesc::operation, plan, and SetQueryCompletion().
Referenced by PortalRunMulti().
|
static |
Definition at line 1055 of file pquery.c.
References CMD_SELECT, generate_unaccent_rules::dest, ExecClearTuple(), ExecDropSingleTupleTableSlot(), PortalData::holdContext, PortalData::holdStore, MakeSingleTupleTableSlot(), MemoryContextSwitchTo(), ScanDirectionIsForward, ScanDirectionIsNoMovement, TTSOpsMinimalTuple, PortalData::tupDesc, and tuplestore_gettupleslot().
Referenced by PortalRunSelect().
Portal ActivePortal = NULL |
Definition at line 35 of file pquery.c.
Referenced by EnsurePortalSnapshotExists(), function_parse_error_transpose(), PersistHoldablePortal(), PortalRun(), PortalRunFetch(), and PortalStart().