1996-07-09 02:22:35 -04:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
*
|
1999-02-13 18:22:53 -05:00
|
|
|
* execdesc.h
|
1996-07-09 02:22:35 -04:00
|
|
|
* plan and query descriptor accessor macros used by the executor
|
|
|
|
|
* and related modules.
|
|
|
|
|
*
|
|
|
|
|
*
|
2026-01-01 13:24:10 -05:00
|
|
|
* Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
|
2000-01-26 00:58:53 -05:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 02:22:35 -04:00
|
|
|
*
|
2010-09-20 16:08:53 -04:00
|
|
|
* src/include/executor/execdesc.h
|
1996-07-09 02:22:35 -04:00
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
#ifndef EXECDESC_H
|
|
|
|
|
#define EXECDESC_H
|
|
|
|
|
|
2002-12-05 10:50:39 -05:00
|
|
|
#include "nodes/execnodes.h"
|
2011-09-04 01:13:16 -04:00
|
|
|
#include "tcop/dest.h"
|
1996-07-09 02:22:35 -04:00
|
|
|
|
2002-02-27 14:36:13 -05:00
|
|
|
|
1996-07-09 02:22:35 -04:00
|
|
|
/* ----------------
|
|
|
|
|
* query descriptor:
|
2002-12-05 10:50:39 -05:00
|
|
|
*
|
1996-07-09 02:22:35 -04:00
|
|
|
* a QueryDesc encapsulates everything that the executor
|
2007-02-20 12:32:18 -05:00
|
|
|
* needs to execute the query.
|
|
|
|
|
*
|
|
|
|
|
* For the convenience of SQL-language functions, we also support QueryDescs
|
|
|
|
|
* containing utility statements; these must not be passed to the executor
|
|
|
|
|
* however.
|
1996-07-09 02:22:35 -04:00
|
|
|
* ---------------------
|
|
|
|
|
*/
|
|
|
|
|
typedef struct QueryDesc
|
|
|
|
|
{
|
2002-12-05 10:50:39 -05:00
|
|
|
/* These fields are provided by CreateQueryDesc */
|
1996-07-09 02:22:35 -04:00
|
|
|
CmdType operation; /* CMD_SELECT, CMD_UPDATE, etc. */
|
Change representation of statement lists, and add statement location info.
This patch makes several changes that improve the consistency of
representation of lists of statements. It's always been the case
that the output of parse analysis is a list of Query nodes, whatever
the types of the individual statements in the list. This patch brings
similar consistency to the outputs of raw parsing and planning steps:
* The output of raw parsing is now always a list of RawStmt nodes;
the statement-type-dependent nodes are one level down from that.
* The output of pg_plan_queries() is now always a list of PlannedStmt
nodes, even for utility statements. In the case of a utility statement,
"planning" just consists of wrapping a CMD_UTILITY PlannedStmt around
the utility node. This list representation is now used in Portal and
CachedPlan plan lists, replacing the former convention of intermixing
PlannedStmts with bare utility-statement nodes.
Now, every list of statements has a consistent head-node type depending
on how far along it is in processing. This allows changing many places
that formerly used generic "Node *" pointers to use a more specific
pointer type, thus reducing the number of IsA() tests and casts needed,
as well as improving code clarity.
Also, the post-parse-analysis representation of DECLARE CURSOR is changed
so that it looks more like EXPLAIN, PREPARE, etc. That is, the contained
SELECT remains a child of the DeclareCursorStmt rather than getting flipped
around to be the other way. It's now true for both Query and PlannedStmt
that utilityStmt is non-null if and only if commandType is CMD_UTILITY.
That allows simplifying a lot of places that were testing both fields.
(I think some of those were just defensive programming, but in many places,
it was actually necessary to avoid confusing DECLARE CURSOR with SELECT.)
Because PlannedStmt carries a canSetTag field, we're also able to get rid
of some ad-hoc rules about how to reconstruct canSetTag for a bare utility
statement; specifically, the assumption that a utility is canSetTag if and
only if it's the only one in its list. While I see no near-term need for
relaxing that restriction, it's nice to get rid of the ad-hocery.
The API of ProcessUtility() is changed so that what it's passed is the
wrapper PlannedStmt not just the bare utility statement. This will affect
all users of ProcessUtility_hook, but the changes are pretty trivial; see
the affected contrib modules for examples of the minimum change needed.
(Most compilers should give pointer-type-mismatch warnings for uncorrected
code.)
There's also a change in the API of ExplainOneQuery_hook, to pass through
cursorOptions instead of expecting hook functions to know what to pick.
This is needed because of the DECLARE CURSOR changes, but really should
have been done in 9.6; it's unlikely that any extant hook functions
know about using CURSOR_OPT_PARALLEL_OK.
Finally, teach gram.y to save statement boundary locations in RawStmt
nodes, and pass those through to Query and PlannedStmt nodes. This allows
more intelligent handling of cases where a source query string contains
multiple statements. This patch doesn't actually do anything with the
information, but a follow-on patch will. (Passing this information through
cleanly is the true motivation for these changes; while I think this is all
good cleanup, it's unlikely we'd have bothered without this end goal.)
catversion bump because addition of location fields to struct Query
affects stored rules.
This patch is by me, but it owes a good deal to Fabien Coelho who did
a lot of preliminary work on the problem, and also reviewed the patch.
Discussion: https://postgr.es/m/alpine.DEB.2.20.1612200926310.29821@lancre
2017-01-14 16:02:35 -05:00
|
|
|
PlannedStmt *plannedstmt; /* planner's output (could be utility, too) */
|
2009-01-02 15:42:00 -05:00
|
|
|
const char *sourceText; /* source text of the query */
|
2004-09-13 16:10:13 -04:00
|
|
|
Snapshot snapshot; /* snapshot to use for query */
|
|
|
|
|
Snapshot crosscheck_snapshot; /* crosscheck for RI update/delete */
|
2003-05-06 16:26:28 -04:00
|
|
|
DestReceiver *dest; /* the destination for tuple output */
|
2002-12-05 10:50:39 -05:00
|
|
|
ParamListInfo params; /* param values being passed in */
|
2017-04-01 00:17:18 -04:00
|
|
|
QueryEnvironment *queryEnv; /* query environment passed in */
|
2009-12-14 23:57:48 -05:00
|
|
|
int instrument_options; /* OR of InstrumentOption flags */
|
instrumentation: Allocate query level instrumentation in ExecutorStart
Until now extensions that wanted to measure overall query execution could
create QueryDesc->totaltime, which the core executor would then start and
stop. That's a bit odd and composes badly, e.g. extensions always had to use
INSTRUMENT_ALL, because otherwise another extension might not get what they
need.
Instead this introduces a new field, QueryDesc->query_instr_options, that
extensions can use to indicate whether they need query level instrumentation
populated, and with which instrumentation options. Extensions should take care
to only add options they need, instead of replacing the options of others.
The prior name of the field, totaltime, sounded like it would only measure
time, but these days the instrumentation infrastructure can track more
resources. The secondary benefit is that this will make it obvious to
extensions that they may not create the Instrumentation struct themselves
anymore (often extensions build only against a postgres build without
assertions).
Adjust pg_stat_statements and auto_explain to match, and lower the
requested instrumentation level for auto_explain to INSTRUMENT_TIMER,
since the summary instrumentation it needs is only runtime.
The reason to push this now, rather in the PG 20 cycle, is that 5a79e78501f
already required extensions using query level instrumentations to adjust their
code, and it seemed undesirable to require them to do so again for 20.
Author: Lukas Fittl <lukas@fittl.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/CAP53Pkyqsht+exJQYRsjhSWYKu+vFGHhPub7m6PmFD6Or0=p1g@mail.gmail.com
2026-04-08 00:02:26 -04:00
|
|
|
int query_instr_options; /* OR of InstrumentOption flags for
|
|
|
|
|
* query_instr */
|
2002-02-27 14:36:13 -05:00
|
|
|
|
2002-12-05 10:50:39 -05:00
|
|
|
/* These fields are set by ExecutorStart */
|
|
|
|
|
TupleDesc tupDesc; /* descriptor for result tuples */
|
|
|
|
|
EState *estate; /* executor's query-wide state */
|
|
|
|
|
PlanState *planstate; /* tree of per-plan-node state */
|
2008-11-18 20:10:24 -05:00
|
|
|
|
2024-12-09 14:38:19 -05:00
|
|
|
/* This field is set by ExecutePlan */
|
2017-03-23 13:05:48 -04:00
|
|
|
bool already_executed; /* true if previously executed */
|
|
|
|
|
|
instrumentation: Allocate query level instrumentation in ExecutorStart
Until now extensions that wanted to measure overall query execution could
create QueryDesc->totaltime, which the core executor would then start and
stop. That's a bit odd and composes badly, e.g. extensions always had to use
INSTRUMENT_ALL, because otherwise another extension might not get what they
need.
Instead this introduces a new field, QueryDesc->query_instr_options, that
extensions can use to indicate whether they need query level instrumentation
populated, and with which instrumentation options. Extensions should take care
to only add options they need, instead of replacing the options of others.
The prior name of the field, totaltime, sounded like it would only measure
time, but these days the instrumentation infrastructure can track more
resources. The secondary benefit is that this will make it obvious to
extensions that they may not create the Instrumentation struct themselves
anymore (often extensions build only against a postgres build without
assertions).
Adjust pg_stat_statements and auto_explain to match, and lower the
requested instrumentation level for auto_explain to INSTRUMENT_TIMER,
since the summary instrumentation it needs is only runtime.
The reason to push this now, rather in the PG 20 cycle, is that 5a79e78501f
already required extensions using query level instrumentations to adjust their
code, and it seemed undesirable to require them to do so again for 20.
Author: Lukas Fittl <lukas@fittl.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/CAP53Pkyqsht+exJQYRsjhSWYKu+vFGHhPub7m6PmFD6Or0=p1g@mail.gmail.com
2026-04-08 00:02:26 -04:00
|
|
|
/* This field is allocated by ExecutorStart if needed */
|
|
|
|
|
struct Instrumentation *query_instr; /* query level instrumentation */
|
1996-07-09 02:22:35 -04:00
|
|
|
} QueryDesc;
|
|
|
|
|
|
|
|
|
|
/* in pquery.c */
|
2007-02-20 12:32:18 -05:00
|
|
|
extern QueryDesc *CreateQueryDesc(PlannedStmt *plannedstmt,
|
2009-01-02 15:42:00 -05:00
|
|
|
const char *sourceText,
|
2004-09-13 16:10:13 -04:00
|
|
|
Snapshot snapshot,
|
|
|
|
|
Snapshot crosscheck_snapshot,
|
2003-05-08 14:16:37 -04:00
|
|
|
DestReceiver *dest,
|
2002-12-05 10:50:39 -05:00
|
|
|
ParamListInfo params,
|
2017-04-01 00:17:18 -04:00
|
|
|
QueryEnvironment *queryEnv,
|
2009-12-14 23:57:48 -05:00
|
|
|
int instrument_options);
|
2001-10-28 01:26:15 -05:00
|
|
|
|
2002-12-15 11:17:59 -05:00
|
|
|
extern void FreeQueryDesc(QueryDesc *qdesc);
|
|
|
|
|
|
1996-07-09 02:22:35 -04:00
|
|
|
#endif /* EXECDESC_H */
|