1999-11-23 21:07:06 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* nodeTidscan.c
|
|
|
|
* Routines to support direct tid scans of relations
|
|
|
|
*
|
2018-01-03 05:30:12 +01:00
|
|
|
* Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1999-11-23 21:07:06 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/backend/executor/nodeTidscan.c
|
1999-11-23 21:07:06 +01:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* INTERFACE ROUTINES
|
|
|
|
*
|
2002-11-30 06:21:03 +01:00
|
|
|
* ExecTidScan scans a relation using tids
|
1999-11-23 21:07:06 +01:00
|
|
|
* ExecInitTidScan creates and initializes state info.
|
2010-07-12 19:01:06 +02:00
|
|
|
* ExecReScanTidScan rescans the tid relation.
|
1999-11-23 21:07:06 +01:00
|
|
|
* ExecEndTidScan releases all storage.
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
2008-05-12 02:00:54 +02:00
|
|
|
#include "access/sysattr.h"
|
2005-11-26 23:14:57 +01:00
|
|
|
#include "catalog/pg_type.h"
|
1999-11-23 21:07:06 +01:00
|
|
|
#include "executor/execdebug.h"
|
|
|
|
#include "executor/nodeTidscan.h"
|
2017-07-26 02:37:17 +02:00
|
|
|
#include "miscadmin.h"
|
2005-11-26 23:14:57 +01:00
|
|
|
#include "optimizer/clauses.h"
|
2008-05-12 02:00:54 +02:00
|
|
|
#include "storage/bufmgr.h"
|
2011-09-04 07:13:16 +02:00
|
|
|
#include "utils/array.h"
|
2011-02-23 18:18:09 +01:00
|
|
|
#include "utils/rel.h"
|
1999-11-23 21:07:06 +01:00
|
|
|
|
2003-09-26 03:17:01 +02:00
|
|
|
|
2005-11-26 23:14:57 +01:00
|
|
|
#define IsCTIDVar(node) \
|
|
|
|
((node) != NULL && \
|
|
|
|
IsA((node), Var) && \
|
|
|
|
((Var *) (node))->varattno == SelfItemPointerAttributeNumber && \
|
|
|
|
((Var *) (node))->varlevelsup == 0)
|
|
|
|
|
Faster expression evaluation and targetlist projection.
This replaces the old, recursive tree-walk based evaluation, with
non-recursive, opcode dispatch based, expression evaluation.
Projection is now implemented as part of expression evaluation.
This both leads to significant performance improvements, and makes
future just-in-time compilation of expressions easier.
The speed gains primarily come from:
- non-recursive implementation reduces stack usage / overhead
- simple sub-expressions are implemented with a single jump, without
function calls
- sharing some state between different sub-expressions
- reduced amount of indirect/hard to predict memory accesses by laying
out operation metadata sequentially; including the avoidance of
nearly all of the previously used linked lists
- more code has been moved to expression initialization, avoiding
constant re-checks at evaluation time
Future just-in-time compilation (JIT) has become easier, as
demonstrated by released patches intended to be merged in a later
release, for primarily two reasons: Firstly, due to a stricter split
between expression initialization and evaluation, less code has to be
handled by the JIT. Secondly, due to the non-recursive nature of the
generated "instructions", less performance-critical code-paths can
easily be shared between interpreted and compiled evaluation.
The new framework allows for significant future optimizations. E.g.:
- basic infrastructure for to later reduce the per executor-startup
overhead of expression evaluation, by caching state in prepared
statements. That'd be helpful in OLTPish scenarios where
initialization overhead is measurable.
- optimizing the generated "code". A number of proposals for potential
work has already been made.
- optimizing the interpreter. Similarly a number of proposals have
been made here too.
The move of logic into the expression initialization step leads to some
backward-incompatible changes:
- Function permission checks are now done during expression
initialization, whereas previously they were done during
execution. In edge cases this can lead to errors being raised that
previously wouldn't have been, e.g. a NULL array being coerced to a
different array type previously didn't perform checks.
- The set of domain constraints to be checked, is now evaluated once
during expression initialization, previously it was re-built
every time a domain check was evaluated. For normal queries this
doesn't change much, but e.g. for plpgsql functions, which caches
ExprStates, the old set could stick around longer. The behavior
around might still change.
Author: Andres Freund, with significant changes by Tom Lane,
changes by Heikki Linnakangas
Reviewed-By: Tom Lane, Heikki Linnakangas
Discussion: https://postgr.es/m/20161206034955.bh33paeralxbtluv@alap3.anarazel.de
2017-03-14 23:45:36 +01:00
|
|
|
/* one element in tss_tidexprs */
|
|
|
|
typedef struct TidExpr
|
|
|
|
{
|
|
|
|
ExprState *exprstate; /* ExprState for a TID-yielding subexpr */
|
|
|
|
bool isarray; /* if true, it yields tid[] not just tid */
|
|
|
|
CurrentOfExpr *cexpr; /* alternatively, we can have CURRENT OF */
|
|
|
|
} TidExpr;
|
|
|
|
|
|
|
|
static void TidExprListCreate(TidScanState *tidstate);
|
|
|
|
static void TidListEval(TidScanState *tidstate);
|
2005-11-26 23:14:57 +01:00
|
|
|
static int itemptr_comparator(const void *a, const void *b);
|
2002-12-05 16:50:39 +01:00
|
|
|
static TupleTableSlot *TidNext(TidScanState *node);
|
1999-11-23 21:07:06 +01:00
|
|
|
|
2003-09-26 03:17:01 +02:00
|
|
|
|
Faster expression evaluation and targetlist projection.
This replaces the old, recursive tree-walk based evaluation, with
non-recursive, opcode dispatch based, expression evaluation.
Projection is now implemented as part of expression evaluation.
This both leads to significant performance improvements, and makes
future just-in-time compilation of expressions easier.
The speed gains primarily come from:
- non-recursive implementation reduces stack usage / overhead
- simple sub-expressions are implemented with a single jump, without
function calls
- sharing some state between different sub-expressions
- reduced amount of indirect/hard to predict memory accesses by laying
out operation metadata sequentially; including the avoidance of
nearly all of the previously used linked lists
- more code has been moved to expression initialization, avoiding
constant re-checks at evaluation time
Future just-in-time compilation (JIT) has become easier, as
demonstrated by released patches intended to be merged in a later
release, for primarily two reasons: Firstly, due to a stricter split
between expression initialization and evaluation, less code has to be
handled by the JIT. Secondly, due to the non-recursive nature of the
generated "instructions", less performance-critical code-paths can
easily be shared between interpreted and compiled evaluation.
The new framework allows for significant future optimizations. E.g.:
- basic infrastructure for to later reduce the per executor-startup
overhead of expression evaluation, by caching state in prepared
statements. That'd be helpful in OLTPish scenarios where
initialization overhead is measurable.
- optimizing the generated "code". A number of proposals for potential
work has already been made.
- optimizing the interpreter. Similarly a number of proposals have
been made here too.
The move of logic into the expression initialization step leads to some
backward-incompatible changes:
- Function permission checks are now done during expression
initialization, whereas previously they were done during
execution. In edge cases this can lead to errors being raised that
previously wouldn't have been, e.g. a NULL array being coerced to a
different array type previously didn't perform checks.
- The set of domain constraints to be checked, is now evaluated once
during expression initialization, previously it was re-built
every time a domain check was evaluated. For normal queries this
doesn't change much, but e.g. for plpgsql functions, which caches
ExprStates, the old set could stick around longer. The behavior
around might still change.
Author: Andres Freund, with significant changes by Tom Lane,
changes by Heikki Linnakangas
Reviewed-By: Tom Lane, Heikki Linnakangas
Discussion: https://postgr.es/m/20161206034955.bh33paeralxbtluv@alap3.anarazel.de
2017-03-14 23:45:36 +01:00
|
|
|
/*
|
|
|
|
* Extract the qual subexpressions that yield TIDs to search for,
|
|
|
|
* and compile them into ExprStates if they're ordinary expressions.
|
|
|
|
*
|
|
|
|
* CURRENT OF is a special case that we can't compile usefully;
|
|
|
|
* just drop it into the TidExpr list as-is.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
TidExprListCreate(TidScanState *tidstate)
|
|
|
|
{
|
|
|
|
TidScan *node = (TidScan *) tidstate->ss.ps.plan;
|
|
|
|
ListCell *l;
|
|
|
|
|
|
|
|
tidstate->tss_tidexprs = NIL;
|
|
|
|
tidstate->tss_isCurrentOf = false;
|
|
|
|
|
|
|
|
foreach(l, node->tidquals)
|
|
|
|
{
|
|
|
|
Expr *expr = (Expr *) lfirst(l);
|
|
|
|
TidExpr *tidexpr = (TidExpr *) palloc0(sizeof(TidExpr));
|
|
|
|
|
|
|
|
if (is_opclause(expr))
|
|
|
|
{
|
|
|
|
Node *arg1;
|
|
|
|
Node *arg2;
|
|
|
|
|
|
|
|
arg1 = get_leftop(expr);
|
|
|
|
arg2 = get_rightop(expr);
|
|
|
|
if (IsCTIDVar(arg1))
|
|
|
|
tidexpr->exprstate = ExecInitExpr((Expr *) arg2,
|
|
|
|
&tidstate->ss.ps);
|
|
|
|
else if (IsCTIDVar(arg2))
|
|
|
|
tidexpr->exprstate = ExecInitExpr((Expr *) arg1,
|
|
|
|
&tidstate->ss.ps);
|
|
|
|
else
|
|
|
|
elog(ERROR, "could not identify CTID variable");
|
|
|
|
tidexpr->isarray = false;
|
|
|
|
}
|
|
|
|
else if (expr && IsA(expr, ScalarArrayOpExpr))
|
|
|
|
{
|
|
|
|
ScalarArrayOpExpr *saex = (ScalarArrayOpExpr *) expr;
|
|
|
|
|
|
|
|
Assert(IsCTIDVar(linitial(saex->args)));
|
|
|
|
tidexpr->exprstate = ExecInitExpr(lsecond(saex->args),
|
|
|
|
&tidstate->ss.ps);
|
|
|
|
tidexpr->isarray = true;
|
|
|
|
}
|
|
|
|
else if (expr && IsA(expr, CurrentOfExpr))
|
|
|
|
{
|
|
|
|
CurrentOfExpr *cexpr = (CurrentOfExpr *) expr;
|
|
|
|
|
|
|
|
tidexpr->cexpr = cexpr;
|
|
|
|
tidstate->tss_isCurrentOf = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
elog(ERROR, "could not identify CTID expression");
|
|
|
|
|
|
|
|
tidstate->tss_tidexprs = lappend(tidstate->tss_tidexprs, tidexpr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* CurrentOfExpr could never appear OR'd with something else */
|
|
|
|
Assert(list_length(tidstate->tss_tidexprs) == 1 ||
|
|
|
|
!tidstate->tss_isCurrentOf);
|
|
|
|
}
|
|
|
|
|
2003-09-26 03:17:01 +02:00
|
|
|
/*
|
|
|
|
* Compute the list of TIDs to be visited, by evaluating the expressions
|
|
|
|
* for them.
|
2005-11-26 23:14:57 +01:00
|
|
|
*
|
|
|
|
* (The result is actually an array, not a list.)
|
2003-09-26 03:17:01 +02:00
|
|
|
*/
|
|
|
|
static void
|
Faster expression evaluation and targetlist projection.
This replaces the old, recursive tree-walk based evaluation, with
non-recursive, opcode dispatch based, expression evaluation.
Projection is now implemented as part of expression evaluation.
This both leads to significant performance improvements, and makes
future just-in-time compilation of expressions easier.
The speed gains primarily come from:
- non-recursive implementation reduces stack usage / overhead
- simple sub-expressions are implemented with a single jump, without
function calls
- sharing some state between different sub-expressions
- reduced amount of indirect/hard to predict memory accesses by laying
out operation metadata sequentially; including the avoidance of
nearly all of the previously used linked lists
- more code has been moved to expression initialization, avoiding
constant re-checks at evaluation time
Future just-in-time compilation (JIT) has become easier, as
demonstrated by released patches intended to be merged in a later
release, for primarily two reasons: Firstly, due to a stricter split
between expression initialization and evaluation, less code has to be
handled by the JIT. Secondly, due to the non-recursive nature of the
generated "instructions", less performance-critical code-paths can
easily be shared between interpreted and compiled evaluation.
The new framework allows for significant future optimizations. E.g.:
- basic infrastructure for to later reduce the per executor-startup
overhead of expression evaluation, by caching state in prepared
statements. That'd be helpful in OLTPish scenarios where
initialization overhead is measurable.
- optimizing the generated "code". A number of proposals for potential
work has already been made.
- optimizing the interpreter. Similarly a number of proposals have
been made here too.
The move of logic into the expression initialization step leads to some
backward-incompatible changes:
- Function permission checks are now done during expression
initialization, whereas previously they were done during
execution. In edge cases this can lead to errors being raised that
previously wouldn't have been, e.g. a NULL array being coerced to a
different array type previously didn't perform checks.
- The set of domain constraints to be checked, is now evaluated once
during expression initialization, previously it was re-built
every time a domain check was evaluated. For normal queries this
doesn't change much, but e.g. for plpgsql functions, which caches
ExprStates, the old set could stick around longer. The behavior
around might still change.
Author: Andres Freund, with significant changes by Tom Lane,
changes by Heikki Linnakangas
Reviewed-By: Tom Lane, Heikki Linnakangas
Discussion: https://postgr.es/m/20161206034955.bh33paeralxbtluv@alap3.anarazel.de
2017-03-14 23:45:36 +01:00
|
|
|
TidListEval(TidScanState *tidstate)
|
1999-11-23 21:07:06 +01:00
|
|
|
{
|
2003-09-26 03:17:01 +02:00
|
|
|
ExprContext *econtext = tidstate->ss.ps.ps_ExprContext;
|
2008-05-01 01:28:32 +02:00
|
|
|
BlockNumber nblocks;
|
2003-09-26 03:17:01 +02:00
|
|
|
ItemPointerData *tidList;
|
2005-11-26 23:14:57 +01:00
|
|
|
int numAllocTids;
|
|
|
|
int numTids;
|
2004-05-26 06:41:50 +02:00
|
|
|
ListCell *l;
|
2003-09-26 03:17:01 +02:00
|
|
|
|
2008-05-01 01:28:32 +02:00
|
|
|
/*
|
2009-06-11 16:49:15 +02:00
|
|
|
* We silently discard any TIDs that are out of range at the time of scan
|
|
|
|
* start. (Since we hold at least AccessShareLock on the table, it won't
|
|
|
|
* be possible for someone to truncate away the blocks we intend to
|
|
|
|
* visit.)
|
2008-05-01 01:28:32 +02:00
|
|
|
*/
|
|
|
|
nblocks = RelationGetNumberOfBlocks(tidstate->ss.ss_currentRelation);
|
|
|
|
|
2005-11-26 23:14:57 +01:00
|
|
|
/*
|
2006-10-04 02:30:14 +02:00
|
|
|
* We initialize the array with enough slots for the case that all quals
|
2007-06-11 03:16:30 +02:00
|
|
|
* are simple OpExprs or CurrentOfExprs. If there are any
|
|
|
|
* ScalarArrayOpExprs, we may have to enlarge the array.
|
2005-11-26 23:14:57 +01:00
|
|
|
*/
|
Faster expression evaluation and targetlist projection.
This replaces the old, recursive tree-walk based evaluation, with
non-recursive, opcode dispatch based, expression evaluation.
Projection is now implemented as part of expression evaluation.
This both leads to significant performance improvements, and makes
future just-in-time compilation of expressions easier.
The speed gains primarily come from:
- non-recursive implementation reduces stack usage / overhead
- simple sub-expressions are implemented with a single jump, without
function calls
- sharing some state between different sub-expressions
- reduced amount of indirect/hard to predict memory accesses by laying
out operation metadata sequentially; including the avoidance of
nearly all of the previously used linked lists
- more code has been moved to expression initialization, avoiding
constant re-checks at evaluation time
Future just-in-time compilation (JIT) has become easier, as
demonstrated by released patches intended to be merged in a later
release, for primarily two reasons: Firstly, due to a stricter split
between expression initialization and evaluation, less code has to be
handled by the JIT. Secondly, due to the non-recursive nature of the
generated "instructions", less performance-critical code-paths can
easily be shared between interpreted and compiled evaluation.
The new framework allows for significant future optimizations. E.g.:
- basic infrastructure for to later reduce the per executor-startup
overhead of expression evaluation, by caching state in prepared
statements. That'd be helpful in OLTPish scenarios where
initialization overhead is measurable.
- optimizing the generated "code". A number of proposals for potential
work has already been made.
- optimizing the interpreter. Similarly a number of proposals have
been made here too.
The move of logic into the expression initialization step leads to some
backward-incompatible changes:
- Function permission checks are now done during expression
initialization, whereas previously they were done during
execution. In edge cases this can lead to errors being raised that
previously wouldn't have been, e.g. a NULL array being coerced to a
different array type previously didn't perform checks.
- The set of domain constraints to be checked, is now evaluated once
during expression initialization, previously it was re-built
every time a domain check was evaluated. For normal queries this
doesn't change much, but e.g. for plpgsql functions, which caches
ExprStates, the old set could stick around longer. The behavior
around might still change.
Author: Andres Freund, with significant changes by Tom Lane,
changes by Heikki Linnakangas
Reviewed-By: Tom Lane, Heikki Linnakangas
Discussion: https://postgr.es/m/20161206034955.bh33paeralxbtluv@alap3.anarazel.de
2017-03-14 23:45:36 +01:00
|
|
|
numAllocTids = list_length(tidstate->tss_tidexprs);
|
2003-09-26 03:17:01 +02:00
|
|
|
tidList = (ItemPointerData *)
|
2005-11-26 23:14:57 +01:00
|
|
|
palloc(numAllocTids * sizeof(ItemPointerData));
|
|
|
|
numTids = 0;
|
1999-11-23 21:07:06 +01:00
|
|
|
|
Faster expression evaluation and targetlist projection.
This replaces the old, recursive tree-walk based evaluation, with
non-recursive, opcode dispatch based, expression evaluation.
Projection is now implemented as part of expression evaluation.
This both leads to significant performance improvements, and makes
future just-in-time compilation of expressions easier.
The speed gains primarily come from:
- non-recursive implementation reduces stack usage / overhead
- simple sub-expressions are implemented with a single jump, without
function calls
- sharing some state between different sub-expressions
- reduced amount of indirect/hard to predict memory accesses by laying
out operation metadata sequentially; including the avoidance of
nearly all of the previously used linked lists
- more code has been moved to expression initialization, avoiding
constant re-checks at evaluation time
Future just-in-time compilation (JIT) has become easier, as
demonstrated by released patches intended to be merged in a later
release, for primarily two reasons: Firstly, due to a stricter split
between expression initialization and evaluation, less code has to be
handled by the JIT. Secondly, due to the non-recursive nature of the
generated "instructions", less performance-critical code-paths can
easily be shared between interpreted and compiled evaluation.
The new framework allows for significant future optimizations. E.g.:
- basic infrastructure for to later reduce the per executor-startup
overhead of expression evaluation, by caching state in prepared
statements. That'd be helpful in OLTPish scenarios where
initialization overhead is measurable.
- optimizing the generated "code". A number of proposals for potential
work has already been made.
- optimizing the interpreter. Similarly a number of proposals have
been made here too.
The move of logic into the expression initialization step leads to some
backward-incompatible changes:
- Function permission checks are now done during expression
initialization, whereas previously they were done during
execution. In edge cases this can lead to errors being raised that
previously wouldn't have been, e.g. a NULL array being coerced to a
different array type previously didn't perform checks.
- The set of domain constraints to be checked, is now evaluated once
during expression initialization, previously it was re-built
every time a domain check was evaluated. For normal queries this
doesn't change much, but e.g. for plpgsql functions, which caches
ExprStates, the old set could stick around longer. The behavior
around might still change.
Author: Andres Freund, with significant changes by Tom Lane,
changes by Heikki Linnakangas
Reviewed-By: Tom Lane, Heikki Linnakangas
Discussion: https://postgr.es/m/20161206034955.bh33paeralxbtluv@alap3.anarazel.de
2017-03-14 23:45:36 +01:00
|
|
|
foreach(l, tidstate->tss_tidexprs)
|
1999-11-23 21:07:06 +01:00
|
|
|
{
|
Faster expression evaluation and targetlist projection.
This replaces the old, recursive tree-walk based evaluation, with
non-recursive, opcode dispatch based, expression evaluation.
Projection is now implemented as part of expression evaluation.
This both leads to significant performance improvements, and makes
future just-in-time compilation of expressions easier.
The speed gains primarily come from:
- non-recursive implementation reduces stack usage / overhead
- simple sub-expressions are implemented with a single jump, without
function calls
- sharing some state between different sub-expressions
- reduced amount of indirect/hard to predict memory accesses by laying
out operation metadata sequentially; including the avoidance of
nearly all of the previously used linked lists
- more code has been moved to expression initialization, avoiding
constant re-checks at evaluation time
Future just-in-time compilation (JIT) has become easier, as
demonstrated by released patches intended to be merged in a later
release, for primarily two reasons: Firstly, due to a stricter split
between expression initialization and evaluation, less code has to be
handled by the JIT. Secondly, due to the non-recursive nature of the
generated "instructions", less performance-critical code-paths can
easily be shared between interpreted and compiled evaluation.
The new framework allows for significant future optimizations. E.g.:
- basic infrastructure for to later reduce the per executor-startup
overhead of expression evaluation, by caching state in prepared
statements. That'd be helpful in OLTPish scenarios where
initialization overhead is measurable.
- optimizing the generated "code". A number of proposals for potential
work has already been made.
- optimizing the interpreter. Similarly a number of proposals have
been made here too.
The move of logic into the expression initialization step leads to some
backward-incompatible changes:
- Function permission checks are now done during expression
initialization, whereas previously they were done during
execution. In edge cases this can lead to errors being raised that
previously wouldn't have been, e.g. a NULL array being coerced to a
different array type previously didn't perform checks.
- The set of domain constraints to be checked, is now evaluated once
during expression initialization, previously it was re-built
every time a domain check was evaluated. For normal queries this
doesn't change much, but e.g. for plpgsql functions, which caches
ExprStates, the old set could stick around longer. The behavior
around might still change.
Author: Andres Freund, with significant changes by Tom Lane,
changes by Heikki Linnakangas
Reviewed-By: Tom Lane, Heikki Linnakangas
Discussion: https://postgr.es/m/20161206034955.bh33paeralxbtluv@alap3.anarazel.de
2017-03-14 23:45:36 +01:00
|
|
|
TidExpr *tidexpr = (TidExpr *) lfirst(l);
|
2003-09-26 03:17:01 +02:00
|
|
|
ItemPointer itemptr;
|
|
|
|
bool isNull;
|
|
|
|
|
Faster expression evaluation and targetlist projection.
This replaces the old, recursive tree-walk based evaluation, with
non-recursive, opcode dispatch based, expression evaluation.
Projection is now implemented as part of expression evaluation.
This both leads to significant performance improvements, and makes
future just-in-time compilation of expressions easier.
The speed gains primarily come from:
- non-recursive implementation reduces stack usage / overhead
- simple sub-expressions are implemented with a single jump, without
function calls
- sharing some state between different sub-expressions
- reduced amount of indirect/hard to predict memory accesses by laying
out operation metadata sequentially; including the avoidance of
nearly all of the previously used linked lists
- more code has been moved to expression initialization, avoiding
constant re-checks at evaluation time
Future just-in-time compilation (JIT) has become easier, as
demonstrated by released patches intended to be merged in a later
release, for primarily two reasons: Firstly, due to a stricter split
between expression initialization and evaluation, less code has to be
handled by the JIT. Secondly, due to the non-recursive nature of the
generated "instructions", less performance-critical code-paths can
easily be shared between interpreted and compiled evaluation.
The new framework allows for significant future optimizations. E.g.:
- basic infrastructure for to later reduce the per executor-startup
overhead of expression evaluation, by caching state in prepared
statements. That'd be helpful in OLTPish scenarios where
initialization overhead is measurable.
- optimizing the generated "code". A number of proposals for potential
work has already been made.
- optimizing the interpreter. Similarly a number of proposals have
been made here too.
The move of logic into the expression initialization step leads to some
backward-incompatible changes:
- Function permission checks are now done during expression
initialization, whereas previously they were done during
execution. In edge cases this can lead to errors being raised that
previously wouldn't have been, e.g. a NULL array being coerced to a
different array type previously didn't perform checks.
- The set of domain constraints to be checked, is now evaluated once
during expression initialization, previously it was re-built
every time a domain check was evaluated. For normal queries this
doesn't change much, but e.g. for plpgsql functions, which caches
ExprStates, the old set could stick around longer. The behavior
around might still change.
Author: Andres Freund, with significant changes by Tom Lane,
changes by Heikki Linnakangas
Reviewed-By: Tom Lane, Heikki Linnakangas
Discussion: https://postgr.es/m/20161206034955.bh33paeralxbtluv@alap3.anarazel.de
2017-03-14 23:45:36 +01:00
|
|
|
if (tidexpr->exprstate && !tidexpr->isarray)
|
1999-11-23 21:07:06 +01:00
|
|
|
{
|
2005-11-26 23:14:57 +01:00
|
|
|
itemptr = (ItemPointer)
|
Faster expression evaluation and targetlist projection.
This replaces the old, recursive tree-walk based evaluation, with
non-recursive, opcode dispatch based, expression evaluation.
Projection is now implemented as part of expression evaluation.
This both leads to significant performance improvements, and makes
future just-in-time compilation of expressions easier.
The speed gains primarily come from:
- non-recursive implementation reduces stack usage / overhead
- simple sub-expressions are implemented with a single jump, without
function calls
- sharing some state between different sub-expressions
- reduced amount of indirect/hard to predict memory accesses by laying
out operation metadata sequentially; including the avoidance of
nearly all of the previously used linked lists
- more code has been moved to expression initialization, avoiding
constant re-checks at evaluation time
Future just-in-time compilation (JIT) has become easier, as
demonstrated by released patches intended to be merged in a later
release, for primarily two reasons: Firstly, due to a stricter split
between expression initialization and evaluation, less code has to be
handled by the JIT. Secondly, due to the non-recursive nature of the
generated "instructions", less performance-critical code-paths can
easily be shared between interpreted and compiled evaluation.
The new framework allows for significant future optimizations. E.g.:
- basic infrastructure for to later reduce the per executor-startup
overhead of expression evaluation, by caching state in prepared
statements. That'd be helpful in OLTPish scenarios where
initialization overhead is measurable.
- optimizing the generated "code". A number of proposals for potential
work has already been made.
- optimizing the interpreter. Similarly a number of proposals have
been made here too.
The move of logic into the expression initialization step leads to some
backward-incompatible changes:
- Function permission checks are now done during expression
initialization, whereas previously they were done during
execution. In edge cases this can lead to errors being raised that
previously wouldn't have been, e.g. a NULL array being coerced to a
different array type previously didn't perform checks.
- The set of domain constraints to be checked, is now evaluated once
during expression initialization, previously it was re-built
every time a domain check was evaluated. For normal queries this
doesn't change much, but e.g. for plpgsql functions, which caches
ExprStates, the old set could stick around longer. The behavior
around might still change.
Author: Andres Freund, with significant changes by Tom Lane,
changes by Heikki Linnakangas
Reviewed-By: Tom Lane, Heikki Linnakangas
Discussion: https://postgr.es/m/20161206034955.bh33paeralxbtluv@alap3.anarazel.de
2017-03-14 23:45:36 +01:00
|
|
|
DatumGetPointer(ExecEvalExprSwitchContext(tidexpr->exprstate,
|
2005-11-26 23:14:57 +01:00
|
|
|
econtext,
|
2017-01-19 23:12:38 +01:00
|
|
|
&isNull));
|
2008-05-01 01:28:32 +02:00
|
|
|
if (!isNull &&
|
|
|
|
ItemPointerIsValid(itemptr) &&
|
|
|
|
ItemPointerGetBlockNumber(itemptr) < nblocks)
|
2005-11-26 23:14:57 +01:00
|
|
|
{
|
|
|
|
if (numTids >= numAllocTids)
|
|
|
|
{
|
|
|
|
numAllocTids *= 2;
|
|
|
|
tidList = (ItemPointerData *)
|
|
|
|
repalloc(tidList,
|
|
|
|
numAllocTids * sizeof(ItemPointerData));
|
|
|
|
}
|
|
|
|
tidList[numTids++] = *itemptr;
|
|
|
|
}
|
1999-11-23 21:07:06 +01:00
|
|
|
}
|
Faster expression evaluation and targetlist projection.
This replaces the old, recursive tree-walk based evaluation, with
non-recursive, opcode dispatch based, expression evaluation.
Projection is now implemented as part of expression evaluation.
This both leads to significant performance improvements, and makes
future just-in-time compilation of expressions easier.
The speed gains primarily come from:
- non-recursive implementation reduces stack usage / overhead
- simple sub-expressions are implemented with a single jump, without
function calls
- sharing some state between different sub-expressions
- reduced amount of indirect/hard to predict memory accesses by laying
out operation metadata sequentially; including the avoidance of
nearly all of the previously used linked lists
- more code has been moved to expression initialization, avoiding
constant re-checks at evaluation time
Future just-in-time compilation (JIT) has become easier, as
demonstrated by released patches intended to be merged in a later
release, for primarily two reasons: Firstly, due to a stricter split
between expression initialization and evaluation, less code has to be
handled by the JIT. Secondly, due to the non-recursive nature of the
generated "instructions", less performance-critical code-paths can
easily be shared between interpreted and compiled evaluation.
The new framework allows for significant future optimizations. E.g.:
- basic infrastructure for to later reduce the per executor-startup
overhead of expression evaluation, by caching state in prepared
statements. That'd be helpful in OLTPish scenarios where
initialization overhead is measurable.
- optimizing the generated "code". A number of proposals for potential
work has already been made.
- optimizing the interpreter. Similarly a number of proposals have
been made here too.
The move of logic into the expression initialization step leads to some
backward-incompatible changes:
- Function permission checks are now done during expression
initialization, whereas previously they were done during
execution. In edge cases this can lead to errors being raised that
previously wouldn't have been, e.g. a NULL array being coerced to a
different array type previously didn't perform checks.
- The set of domain constraints to be checked, is now evaluated once
during expression initialization, previously it was re-built
every time a domain check was evaluated. For normal queries this
doesn't change much, but e.g. for plpgsql functions, which caches
ExprStates, the old set could stick around longer. The behavior
around might still change.
Author: Andres Freund, with significant changes by Tom Lane,
changes by Heikki Linnakangas
Reviewed-By: Tom Lane, Heikki Linnakangas
Discussion: https://postgr.es/m/20161206034955.bh33paeralxbtluv@alap3.anarazel.de
2017-03-14 23:45:36 +01:00
|
|
|
else if (tidexpr->exprstate && tidexpr->isarray)
|
2005-11-26 23:14:57 +01:00
|
|
|
{
|
|
|
|
Datum arraydatum;
|
|
|
|
ArrayType *itemarray;
|
|
|
|
Datum *ipdatums;
|
|
|
|
bool *ipnulls;
|
|
|
|
int ndatums;
|
|
|
|
int i;
|
|
|
|
|
Faster expression evaluation and targetlist projection.
This replaces the old, recursive tree-walk based evaluation, with
non-recursive, opcode dispatch based, expression evaluation.
Projection is now implemented as part of expression evaluation.
This both leads to significant performance improvements, and makes
future just-in-time compilation of expressions easier.
The speed gains primarily come from:
- non-recursive implementation reduces stack usage / overhead
- simple sub-expressions are implemented with a single jump, without
function calls
- sharing some state between different sub-expressions
- reduced amount of indirect/hard to predict memory accesses by laying
out operation metadata sequentially; including the avoidance of
nearly all of the previously used linked lists
- more code has been moved to expression initialization, avoiding
constant re-checks at evaluation time
Future just-in-time compilation (JIT) has become easier, as
demonstrated by released patches intended to be merged in a later
release, for primarily two reasons: Firstly, due to a stricter split
between expression initialization and evaluation, less code has to be
handled by the JIT. Secondly, due to the non-recursive nature of the
generated "instructions", less performance-critical code-paths can
easily be shared between interpreted and compiled evaluation.
The new framework allows for significant future optimizations. E.g.:
- basic infrastructure for to later reduce the per executor-startup
overhead of expression evaluation, by caching state in prepared
statements. That'd be helpful in OLTPish scenarios where
initialization overhead is measurable.
- optimizing the generated "code". A number of proposals for potential
work has already been made.
- optimizing the interpreter. Similarly a number of proposals have
been made here too.
The move of logic into the expression initialization step leads to some
backward-incompatible changes:
- Function permission checks are now done during expression
initialization, whereas previously they were done during
execution. In edge cases this can lead to errors being raised that
previously wouldn't have been, e.g. a NULL array being coerced to a
different array type previously didn't perform checks.
- The set of domain constraints to be checked, is now evaluated once
during expression initialization, previously it was re-built
every time a domain check was evaluated. For normal queries this
doesn't change much, but e.g. for plpgsql functions, which caches
ExprStates, the old set could stick around longer. The behavior
around might still change.
Author: Andres Freund, with significant changes by Tom Lane,
changes by Heikki Linnakangas
Reviewed-By: Tom Lane, Heikki Linnakangas
Discussion: https://postgr.es/m/20161206034955.bh33paeralxbtluv@alap3.anarazel.de
2017-03-14 23:45:36 +01:00
|
|
|
arraydatum = ExecEvalExprSwitchContext(tidexpr->exprstate,
|
2005-11-26 23:14:57 +01:00
|
|
|
econtext,
|
2017-01-19 23:12:38 +01:00
|
|
|
&isNull);
|
2005-11-26 23:14:57 +01:00
|
|
|
if (isNull)
|
|
|
|
continue;
|
|
|
|
itemarray = DatumGetArrayTypeP(arraydatum);
|
|
|
|
deconstruct_array(itemarray,
|
2016-09-22 20:30:33 +02:00
|
|
|
TIDOID, sizeof(ItemPointerData), false, 's',
|
2005-11-26 23:14:57 +01:00
|
|
|
&ipdatums, &ipnulls, &ndatums);
|
|
|
|
if (numTids + ndatums > numAllocTids)
|
|
|
|
{
|
|
|
|
numAllocTids = numTids + ndatums;
|
|
|
|
tidList = (ItemPointerData *)
|
|
|
|
repalloc(tidList,
|
|
|
|
numAllocTids * sizeof(ItemPointerData));
|
|
|
|
}
|
|
|
|
for (i = 0; i < ndatums; i++)
|
|
|
|
{
|
|
|
|
if (!ipnulls[i])
|
|
|
|
{
|
|
|
|
itemptr = (ItemPointer) DatumGetPointer(ipdatums[i]);
|
2008-05-01 01:28:32 +02:00
|
|
|
if (ItemPointerIsValid(itemptr) &&
|
|
|
|
ItemPointerGetBlockNumber(itemptr) < nblocks)
|
2005-11-26 23:14:57 +01:00
|
|
|
tidList[numTids++] = *itemptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pfree(ipdatums);
|
|
|
|
pfree(ipnulls);
|
|
|
|
}
|
Faster expression evaluation and targetlist projection.
This replaces the old, recursive tree-walk based evaluation, with
non-recursive, opcode dispatch based, expression evaluation.
Projection is now implemented as part of expression evaluation.
This both leads to significant performance improvements, and makes
future just-in-time compilation of expressions easier.
The speed gains primarily come from:
- non-recursive implementation reduces stack usage / overhead
- simple sub-expressions are implemented with a single jump, without
function calls
- sharing some state between different sub-expressions
- reduced amount of indirect/hard to predict memory accesses by laying
out operation metadata sequentially; including the avoidance of
nearly all of the previously used linked lists
- more code has been moved to expression initialization, avoiding
constant re-checks at evaluation time
Future just-in-time compilation (JIT) has become easier, as
demonstrated by released patches intended to be merged in a later
release, for primarily two reasons: Firstly, due to a stricter split
between expression initialization and evaluation, less code has to be
handled by the JIT. Secondly, due to the non-recursive nature of the
generated "instructions", less performance-critical code-paths can
easily be shared between interpreted and compiled evaluation.
The new framework allows for significant future optimizations. E.g.:
- basic infrastructure for to later reduce the per executor-startup
overhead of expression evaluation, by caching state in prepared
statements. That'd be helpful in OLTPish scenarios where
initialization overhead is measurable.
- optimizing the generated "code". A number of proposals for potential
work has already been made.
- optimizing the interpreter. Similarly a number of proposals have
been made here too.
The move of logic into the expression initialization step leads to some
backward-incompatible changes:
- Function permission checks are now done during expression
initialization, whereas previously they were done during
execution. In edge cases this can lead to errors being raised that
previously wouldn't have been, e.g. a NULL array being coerced to a
different array type previously didn't perform checks.
- The set of domain constraints to be checked, is now evaluated once
during expression initialization, previously it was re-built
every time a domain check was evaluated. For normal queries this
doesn't change much, but e.g. for plpgsql functions, which caches
ExprStates, the old set could stick around longer. The behavior
around might still change.
Author: Andres Freund, with significant changes by Tom Lane,
changes by Heikki Linnakangas
Reviewed-By: Tom Lane, Heikki Linnakangas
Discussion: https://postgr.es/m/20161206034955.bh33paeralxbtluv@alap3.anarazel.de
2017-03-14 23:45:36 +01:00
|
|
|
else
|
2007-06-11 03:16:30 +02:00
|
|
|
{
|
|
|
|
ItemPointerData cursor_tid;
|
|
|
|
|
Faster expression evaluation and targetlist projection.
This replaces the old, recursive tree-walk based evaluation, with
non-recursive, opcode dispatch based, expression evaluation.
Projection is now implemented as part of expression evaluation.
This both leads to significant performance improvements, and makes
future just-in-time compilation of expressions easier.
The speed gains primarily come from:
- non-recursive implementation reduces stack usage / overhead
- simple sub-expressions are implemented with a single jump, without
function calls
- sharing some state between different sub-expressions
- reduced amount of indirect/hard to predict memory accesses by laying
out operation metadata sequentially; including the avoidance of
nearly all of the previously used linked lists
- more code has been moved to expression initialization, avoiding
constant re-checks at evaluation time
Future just-in-time compilation (JIT) has become easier, as
demonstrated by released patches intended to be merged in a later
release, for primarily two reasons: Firstly, due to a stricter split
between expression initialization and evaluation, less code has to be
handled by the JIT. Secondly, due to the non-recursive nature of the
generated "instructions", less performance-critical code-paths can
easily be shared between interpreted and compiled evaluation.
The new framework allows for significant future optimizations. E.g.:
- basic infrastructure for to later reduce the per executor-startup
overhead of expression evaluation, by caching state in prepared
statements. That'd be helpful in OLTPish scenarios where
initialization overhead is measurable.
- optimizing the generated "code". A number of proposals for potential
work has already been made.
- optimizing the interpreter. Similarly a number of proposals have
been made here too.
The move of logic into the expression initialization step leads to some
backward-incompatible changes:
- Function permission checks are now done during expression
initialization, whereas previously they were done during
execution. In edge cases this can lead to errors being raised that
previously wouldn't have been, e.g. a NULL array being coerced to a
different array type previously didn't perform checks.
- The set of domain constraints to be checked, is now evaluated once
during expression initialization, previously it was re-built
every time a domain check was evaluated. For normal queries this
doesn't change much, but e.g. for plpgsql functions, which caches
ExprStates, the old set could stick around longer. The behavior
around might still change.
Author: Andres Freund, with significant changes by Tom Lane,
changes by Heikki Linnakangas
Reviewed-By: Tom Lane, Heikki Linnakangas
Discussion: https://postgr.es/m/20161206034955.bh33paeralxbtluv@alap3.anarazel.de
2017-03-14 23:45:36 +01:00
|
|
|
Assert(tidexpr->cexpr);
|
|
|
|
if (execCurrentOf(tidexpr->cexpr, econtext,
|
Phase 3 of pgindent updates.
Don't move parenthesized lines to the left, even if that means they
flow past the right margin.
By default, BSD indent lines up statement continuation lines that are
within parentheses so that they start just to the right of the preceding
left parenthesis. However, traditionally, if that resulted in the
continuation line extending to the right of the desired right margin,
then indent would push it left just far enough to not overrun the margin,
if it could do so without making the continuation line start to the left of
the current statement indent. That makes for a weird mix of indentations
unless one has been completely rigid about never violating the 80-column
limit.
This behavior has been pretty universally panned by Postgres developers.
Hence, disable it with indent's new -lpl switch, so that parenthesized
lines are always lined up with the preceding left paren.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:35:54 +02:00
|
|
|
RelationGetRelid(tidstate->ss.ss_currentRelation),
|
2007-06-11 03:16:30 +02:00
|
|
|
&cursor_tid))
|
|
|
|
{
|
|
|
|
if (numTids >= numAllocTids)
|
|
|
|
{
|
|
|
|
numAllocTids *= 2;
|
|
|
|
tidList = (ItemPointerData *)
|
|
|
|
repalloc(tidList,
|
|
|
|
numAllocTids * sizeof(ItemPointerData));
|
|
|
|
}
|
|
|
|
tidList[numTids++] = cursor_tid;
|
|
|
|
}
|
|
|
|
}
|
2005-11-26 23:14:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sort the array of TIDs into order, and eliminate duplicates.
|
2006-10-04 02:30:14 +02:00
|
|
|
* Eliminating duplicates is necessary since we want OR semantics across
|
|
|
|
* the list. Sorting makes it easier to detect duplicates, and as a bonus
|
|
|
|
* ensures that we will visit the heap in the most efficient way.
|
2005-11-26 23:14:57 +01:00
|
|
|
*/
|
|
|
|
if (numTids > 1)
|
|
|
|
{
|
2006-10-04 02:30:14 +02:00
|
|
|
int lastTid;
|
|
|
|
int i;
|
2005-11-26 23:14:57 +01:00
|
|
|
|
2007-10-24 20:37:09 +02:00
|
|
|
/* CurrentOfExpr could never appear OR'd with something else */
|
|
|
|
Assert(!tidstate->tss_isCurrentOf);
|
|
|
|
|
2005-11-26 23:14:57 +01:00
|
|
|
qsort((void *) tidList, numTids, sizeof(ItemPointerData),
|
|
|
|
itemptr_comparator);
|
|
|
|
lastTid = 0;
|
|
|
|
for (i = 1; i < numTids; i++)
|
|
|
|
{
|
|
|
|
if (!ItemPointerEquals(&tidList[lastTid], &tidList[i]))
|
|
|
|
tidList[++lastTid] = tidList[i];
|
|
|
|
}
|
|
|
|
numTids = lastTid + 1;
|
1999-11-23 21:07:06 +01:00
|
|
|
}
|
2003-09-26 03:17:01 +02:00
|
|
|
|
|
|
|
tidstate->tss_TidList = tidList;
|
|
|
|
tidstate->tss_NumTids = numTids;
|
|
|
|
tidstate->tss_TidPtr = -1;
|
1999-11-23 21:07:06 +01:00
|
|
|
}
|
|
|
|
|
2005-11-26 23:14:57 +01:00
|
|
|
/*
|
|
|
|
* qsort comparator for ItemPointerData items
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
itemptr_comparator(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const ItemPointerData *ipa = (const ItemPointerData *) a;
|
|
|
|
const ItemPointerData *ipb = (const ItemPointerData *) b;
|
2006-10-04 02:30:14 +02:00
|
|
|
BlockNumber ba = ItemPointerGetBlockNumber(ipa);
|
|
|
|
BlockNumber bb = ItemPointerGetBlockNumber(ipb);
|
2005-11-26 23:14:57 +01:00
|
|
|
OffsetNumber oa = ItemPointerGetOffsetNumber(ipa);
|
|
|
|
OffsetNumber ob = ItemPointerGetOffsetNumber(ipb);
|
|
|
|
|
|
|
|
if (ba < bb)
|
|
|
|
return -1;
|
|
|
|
if (ba > bb)
|
|
|
|
return 1;
|
|
|
|
if (oa < ob)
|
|
|
|
return -1;
|
|
|
|
if (oa > ob)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-11-23 21:07:06 +01:00
|
|
|
/* ----------------------------------------------------------------
|
|
|
|
* TidNext
|
|
|
|
*
|
|
|
|
* Retrieve a tuple from the TidScan node's currentRelation
|
|
|
|
* using the tids in the TidScanState information.
|
|
|
|
*
|
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
static TupleTableSlot *
|
2002-12-05 16:50:39 +01:00
|
|
|
TidNext(TidScanState *node)
|
1999-11-23 21:07:06 +01:00
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
EState *estate;
|
|
|
|
ScanDirection direction;
|
1999-11-23 21:07:06 +01:00
|
|
|
Snapshot snapshot;
|
|
|
|
Relation heapRelation;
|
|
|
|
HeapTuple tuple;
|
2000-04-12 19:17:23 +02:00
|
|
|
TupleTableSlot *slot;
|
1999-11-23 21:07:06 +01:00
|
|
|
Buffer buffer = InvalidBuffer;
|
2003-09-26 03:17:01 +02:00
|
|
|
ItemPointerData *tidList;
|
2000-04-12 19:17:23 +02:00
|
|
|
int numTids;
|
1999-11-23 21:07:06 +01:00
|
|
|
bool bBackward;
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* extract necessary information from tid scan node
|
1999-11-23 21:07:06 +01:00
|
|
|
*/
|
2002-12-05 16:50:39 +01:00
|
|
|
estate = node->ss.ps.state;
|
1999-11-23 21:07:06 +01:00
|
|
|
direction = estate->es_direction;
|
|
|
|
snapshot = estate->es_snapshot;
|
2002-12-05 16:50:39 +01:00
|
|
|
heapRelation = node->ss.ss_currentRelation;
|
|
|
|
slot = node->ss.ss_ScanTupleSlot;
|
1999-11-23 21:07:06 +01:00
|
|
|
|
2003-09-26 03:17:01 +02:00
|
|
|
/*
|
|
|
|
* First time through, compute the list of TIDs to be visited
|
|
|
|
*/
|
|
|
|
if (node->tss_TidList == NULL)
|
Faster expression evaluation and targetlist projection.
This replaces the old, recursive tree-walk based evaluation, with
non-recursive, opcode dispatch based, expression evaluation.
Projection is now implemented as part of expression evaluation.
This both leads to significant performance improvements, and makes
future just-in-time compilation of expressions easier.
The speed gains primarily come from:
- non-recursive implementation reduces stack usage / overhead
- simple sub-expressions are implemented with a single jump, without
function calls
- sharing some state between different sub-expressions
- reduced amount of indirect/hard to predict memory accesses by laying
out operation metadata sequentially; including the avoidance of
nearly all of the previously used linked lists
- more code has been moved to expression initialization, avoiding
constant re-checks at evaluation time
Future just-in-time compilation (JIT) has become easier, as
demonstrated by released patches intended to be merged in a later
release, for primarily two reasons: Firstly, due to a stricter split
between expression initialization and evaluation, less code has to be
handled by the JIT. Secondly, due to the non-recursive nature of the
generated "instructions", less performance-critical code-paths can
easily be shared between interpreted and compiled evaluation.
The new framework allows for significant future optimizations. E.g.:
- basic infrastructure for to later reduce the per executor-startup
overhead of expression evaluation, by caching state in prepared
statements. That'd be helpful in OLTPish scenarios where
initialization overhead is measurable.
- optimizing the generated "code". A number of proposals for potential
work has already been made.
- optimizing the interpreter. Similarly a number of proposals have
been made here too.
The move of logic into the expression initialization step leads to some
backward-incompatible changes:
- Function permission checks are now done during expression
initialization, whereas previously they were done during
execution. In edge cases this can lead to errors being raised that
previously wouldn't have been, e.g. a NULL array being coerced to a
different array type previously didn't perform checks.
- The set of domain constraints to be checked, is now evaluated once
during expression initialization, previously it was re-built
every time a domain check was evaluated. For normal queries this
doesn't change much, but e.g. for plpgsql functions, which caches
ExprStates, the old set could stick around longer. The behavior
around might still change.
Author: Andres Freund, with significant changes by Tom Lane,
changes by Heikki Linnakangas
Reviewed-By: Tom Lane, Heikki Linnakangas
Discussion: https://postgr.es/m/20161206034955.bh33paeralxbtluv@alap3.anarazel.de
2017-03-14 23:45:36 +01:00
|
|
|
TidListEval(node);
|
2003-09-26 03:17:01 +02:00
|
|
|
|
|
|
|
tidList = node->tss_TidList;
|
|
|
|
numTids = node->tss_NumTids;
|
|
|
|
|
Faster expression evaluation and targetlist projection.
This replaces the old, recursive tree-walk based evaluation, with
non-recursive, opcode dispatch based, expression evaluation.
Projection is now implemented as part of expression evaluation.
This both leads to significant performance improvements, and makes
future just-in-time compilation of expressions easier.
The speed gains primarily come from:
- non-recursive implementation reduces stack usage / overhead
- simple sub-expressions are implemented with a single jump, without
function calls
- sharing some state between different sub-expressions
- reduced amount of indirect/hard to predict memory accesses by laying
out operation metadata sequentially; including the avoidance of
nearly all of the previously used linked lists
- more code has been moved to expression initialization, avoiding
constant re-checks at evaluation time
Future just-in-time compilation (JIT) has become easier, as
demonstrated by released patches intended to be merged in a later
release, for primarily two reasons: Firstly, due to a stricter split
between expression initialization and evaluation, less code has to be
handled by the JIT. Secondly, due to the non-recursive nature of the
generated "instructions", less performance-critical code-paths can
easily be shared between interpreted and compiled evaluation.
The new framework allows for significant future optimizations. E.g.:
- basic infrastructure for to later reduce the per executor-startup
overhead of expression evaluation, by caching state in prepared
statements. That'd be helpful in OLTPish scenarios where
initialization overhead is measurable.
- optimizing the generated "code". A number of proposals for potential
work has already been made.
- optimizing the interpreter. Similarly a number of proposals have
been made here too.
The move of logic into the expression initialization step leads to some
backward-incompatible changes:
- Function permission checks are now done during expression
initialization, whereas previously they were done during
execution. In edge cases this can lead to errors being raised that
previously wouldn't have been, e.g. a NULL array being coerced to a
different array type previously didn't perform checks.
- The set of domain constraints to be checked, is now evaluated once
during expression initialization, previously it was re-built
every time a domain check was evaluated. For normal queries this
doesn't change much, but e.g. for plpgsql functions, which caches
ExprStates, the old set could stick around longer. The behavior
around might still change.
Author: Andres Freund, with significant changes by Tom Lane,
changes by Heikki Linnakangas
Reviewed-By: Tom Lane, Heikki Linnakangas
Discussion: https://postgr.es/m/20161206034955.bh33paeralxbtluv@alap3.anarazel.de
2017-03-14 23:45:36 +01:00
|
|
|
/*
|
|
|
|
* We use node->tss_htup as the tuple pointer; note this can't just be a
|
|
|
|
* local variable here, as the scan tuple slot will keep a pointer to it.
|
|
|
|
*/
|
2002-12-05 16:50:39 +01:00
|
|
|
tuple = &(node->tss_htup);
|
1999-11-23 21:07:06 +01:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2005-11-26 23:14:57 +01:00
|
|
|
* Initialize or advance scan position, depending on direction.
|
1999-11-23 21:07:06 +01:00
|
|
|
*/
|
|
|
|
bBackward = ScanDirectionIsBackward(direction);
|
|
|
|
if (bBackward)
|
|
|
|
{
|
2005-11-26 23:14:57 +01:00
|
|
|
if (node->tss_TidPtr < 0)
|
1999-11-23 21:07:06 +01:00
|
|
|
{
|
2005-11-26 23:14:57 +01:00
|
|
|
/* initialize for backward scan */
|
2002-12-05 16:50:39 +01:00
|
|
|
node->tss_TidPtr = numTids - 1;
|
1999-11-23 21:07:06 +01:00
|
|
|
}
|
2005-11-26 23:14:57 +01:00
|
|
|
else
|
|
|
|
node->tss_TidPtr--;
|
1999-11-23 21:07:06 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-11-26 23:14:57 +01:00
|
|
|
if (node->tss_TidPtr < 0)
|
1999-11-23 21:07:06 +01:00
|
|
|
{
|
2005-11-26 23:14:57 +01:00
|
|
|
/* initialize for forward scan */
|
2002-12-05 16:50:39 +01:00
|
|
|
node->tss_TidPtr = 0;
|
1999-11-23 21:07:06 +01:00
|
|
|
}
|
2005-11-26 23:14:57 +01:00
|
|
|
else
|
|
|
|
node->tss_TidPtr++;
|
1999-11-23 21:07:06 +01:00
|
|
|
}
|
|
|
|
|
2005-11-26 23:14:57 +01:00
|
|
|
while (node->tss_TidPtr >= 0 && node->tss_TidPtr < numTids)
|
|
|
|
{
|
2002-12-05 16:50:39 +01:00
|
|
|
tuple->t_self = tidList[node->tss_TidPtr];
|
2007-10-24 20:37:09 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For WHERE CURRENT OF, the tuple retrieved from the cursor might
|
2007-11-15 22:14:46 +01:00
|
|
|
* since have been updated; if so, we should fetch the version that is
|
|
|
|
* current according to our snapshot.
|
2007-10-24 20:37:09 +02:00
|
|
|
*/
|
|
|
|
if (node->tss_isCurrentOf)
|
|
|
|
heap_get_latest_tid(heapRelation, snapshot, &tuple->t_self);
|
|
|
|
|
2002-05-24 20:57:57 +02:00
|
|
|
if (heap_fetch(heapRelation, snapshot, tuple, &buffer, false, NULL))
|
1999-11-23 21:07:06 +01:00
|
|
|
{
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* store the scanned tuple in the scan tuple slot of the scan
|
2005-10-15 04:49:52 +02:00
|
|
|
* state. Eventually we will only do this and not return a tuple.
|
|
|
|
* Note: we pass 'false' because tuples returned by amgetnext are
|
|
|
|
* pointers onto disk pages and were not created with palloc() and
|
|
|
|
* so should not be pfree()'d.
|
1999-11-23 21:07:06 +01:00
|
|
|
*/
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:18:54 +02:00
|
|
|
ExecStoreTuple(tuple, /* tuple to store */
|
2001-10-28 07:26:15 +01:00
|
|
|
slot, /* slot to store in */
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:18:54 +02:00
|
|
|
buffer, /* buffer associated with tuple */
|
|
|
|
false); /* don't pfree */
|
1999-11-23 21:07:06 +01:00
|
|
|
|
|
|
|
/*
|
2000-04-12 19:17:23 +02:00
|
|
|
* At this point we have an extra pin on the buffer, because
|
2005-10-15 04:49:52 +02:00
|
|
|
* ExecStoreTuple incremented the pin count. Drop our local pin.
|
2000-04-12 19:17:23 +02:00
|
|
|
*/
|
|
|
|
ReleaseBuffer(buffer);
|
|
|
|
|
2005-11-26 23:14:57 +01:00
|
|
|
return slot;
|
1999-11-23 21:07:06 +01:00
|
|
|
}
|
2005-11-26 23:14:57 +01:00
|
|
|
/* Bad TID or failed snapshot qual; try next */
|
1999-11-23 21:07:06 +01:00
|
|
|
if (bBackward)
|
2002-12-05 16:50:39 +01:00
|
|
|
node->tss_TidPtr--;
|
1999-11-23 21:07:06 +01:00
|
|
|
else
|
2002-12-05 16:50:39 +01:00
|
|
|
node->tss_TidPtr++;
|
2017-07-26 02:37:17 +02:00
|
|
|
|
|
|
|
CHECK_FOR_INTERRUPTS();
|
1999-11-23 21:07:06 +01:00
|
|
|
}
|
2001-03-22 07:16:21 +01:00
|
|
|
|
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* if we get here it means the tid scan failed so we are at the end of the
|
|
|
|
* scan..
|
1999-11-23 21:07:06 +01:00
|
|
|
*/
|
|
|
|
return ExecClearTuple(slot);
|
|
|
|
}
|
|
|
|
|
Re-implement EvalPlanQual processing to improve its performance and eliminate
a lot of strange behaviors that occurred in join cases. We now identify the
"current" row for every joined relation in UPDATE, DELETE, and SELECT FOR
UPDATE/SHARE queries. If an EvalPlanQual recheck is necessary, we jam the
appropriate row into each scan node in the rechecking plan, forcing it to emit
only that one row. The former behavior could rescan the whole of each joined
relation for each recheck, which was terrible for performance, and what's much
worse could result in duplicated output tuples.
Also, the original implementation of EvalPlanQual could not re-use the recheck
execution tree --- it had to go through a full executor init and shutdown for
every row to be tested. To avoid this overhead, I've associated a special
runtime Param with each LockRows or ModifyTable plan node, and arranged to
make every scan node below such a node depend on that Param. Thus, by
signaling a change in that Param, the EPQ machinery can just rescan the
already-built test plan.
This patch also adds a prohibition on set-returning functions in the
targetlist of SELECT FOR UPDATE/SHARE. This is needed to avoid the
duplicate-output-tuple problem. It seems fairly reasonable since the
other restrictions on SELECT FOR UPDATE are meant to ensure that there
is a unique correspondence between source tuples and result tuples,
which an output SRF destroys as much as anything else does.
2009-10-26 03:26:45 +01:00
|
|
|
/*
|
|
|
|
* TidRecheck -- access method routine to recheck a tuple in EvalPlanQual
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
TidRecheck(TidScanState *node, TupleTableSlot *slot)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* XXX shouldn't we check here to make sure tuple matches TID list? In
|
|
|
|
* runtime-key case this is not certain, is it? However, in the WHERE
|
|
|
|
* CURRENT OF case it might not match anyway ...
|
|
|
|
*/
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-23 21:07:06 +01:00
|
|
|
/* ----------------------------------------------------------------
|
|
|
|
* ExecTidScan(node)
|
|
|
|
*
|
|
|
|
* Scans the relation using tids and returns
|
|
|
|
* the next qualifying tuple in the direction specified.
|
Re-implement EvalPlanQual processing to improve its performance and eliminate
a lot of strange behaviors that occurred in join cases. We now identify the
"current" row for every joined relation in UPDATE, DELETE, and SELECT FOR
UPDATE/SHARE queries. If an EvalPlanQual recheck is necessary, we jam the
appropriate row into each scan node in the rechecking plan, forcing it to emit
only that one row. The former behavior could rescan the whole of each joined
relation for each recheck, which was terrible for performance, and what's much
worse could result in duplicated output tuples.
Also, the original implementation of EvalPlanQual could not re-use the recheck
execution tree --- it had to go through a full executor init and shutdown for
every row to be tested. To avoid this overhead, I've associated a special
runtime Param with each LockRows or ModifyTable plan node, and arranged to
make every scan node below such a node depend on that Param. Thus, by
signaling a change in that Param, the EPQ machinery can just rescan the
already-built test plan.
This patch also adds a prohibition on set-returning functions in the
targetlist of SELECT FOR UPDATE/SHARE. This is needed to avoid the
duplicate-output-tuple problem. It seems fairly reasonable since the
other restrictions on SELECT FOR UPDATE are meant to ensure that there
is a unique correspondence between source tuples and result tuples,
which an output SRF destroys as much as anything else does.
2009-10-26 03:26:45 +01:00
|
|
|
* We call the ExecScan() routine and pass it the appropriate
|
|
|
|
* access method functions.
|
1999-11-23 21:07:06 +01:00
|
|
|
*
|
|
|
|
* Conditions:
|
|
|
|
* -- the "cursor" maintained by the AMI is positioned at the tuple
|
|
|
|
* returned previously.
|
|
|
|
*
|
|
|
|
* Initial States:
|
|
|
|
* -- the relation indicated is opened for scanning so that the
|
|
|
|
* "cursor" is positioned before the first qualifying tuple.
|
2005-11-26 23:14:57 +01:00
|
|
|
* -- tidPtr is -1.
|
1999-11-23 21:07:06 +01:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
2017-07-17 09:33:49 +02:00
|
|
|
static TupleTableSlot *
|
|
|
|
ExecTidScan(PlanState *pstate)
|
1999-11-23 21:07:06 +01:00
|
|
|
{
|
2017-07-17 09:33:49 +02:00
|
|
|
TidScanState *node = castNode(TidScanState, pstate);
|
|
|
|
|
Re-implement EvalPlanQual processing to improve its performance and eliminate
a lot of strange behaviors that occurred in join cases. We now identify the
"current" row for every joined relation in UPDATE, DELETE, and SELECT FOR
UPDATE/SHARE queries. If an EvalPlanQual recheck is necessary, we jam the
appropriate row into each scan node in the rechecking plan, forcing it to emit
only that one row. The former behavior could rescan the whole of each joined
relation for each recheck, which was terrible for performance, and what's much
worse could result in duplicated output tuples.
Also, the original implementation of EvalPlanQual could not re-use the recheck
execution tree --- it had to go through a full executor init and shutdown for
every row to be tested. To avoid this overhead, I've associated a special
runtime Param with each LockRows or ModifyTable plan node, and arranged to
make every scan node below such a node depend on that Param. Thus, by
signaling a change in that Param, the EPQ machinery can just rescan the
already-built test plan.
This patch also adds a prohibition on set-returning functions in the
targetlist of SELECT FOR UPDATE/SHARE. This is needed to avoid the
duplicate-output-tuple problem. It seems fairly reasonable since the
other restrictions on SELECT FOR UPDATE are meant to ensure that there
is a unique correspondence between source tuples and result tuples,
which an output SRF destroys as much as anything else does.
2009-10-26 03:26:45 +01:00
|
|
|
return ExecScan(&node->ss,
|
|
|
|
(ExecScanAccessMtd) TidNext,
|
|
|
|
(ExecScanRecheckMtd) TidRecheck);
|
1999-11-23 21:07:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
2010-07-12 19:01:06 +02:00
|
|
|
* ExecReScanTidScan(node)
|
1999-11-23 21:07:06 +01:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2010-07-12 19:01:06 +02:00
|
|
|
ExecReScanTidScan(TidScanState *node)
|
1999-11-23 21:07:06 +01:00
|
|
|
{
|
2003-09-26 03:17:01 +02:00
|
|
|
if (node->tss_TidList)
|
|
|
|
pfree(node->tss_TidList);
|
|
|
|
node->tss_TidList = NULL;
|
|
|
|
node->tss_NumTids = 0;
|
2002-12-05 16:50:39 +01:00
|
|
|
node->tss_TidPtr = -1;
|
Re-implement EvalPlanQual processing to improve its performance and eliminate
a lot of strange behaviors that occurred in join cases. We now identify the
"current" row for every joined relation in UPDATE, DELETE, and SELECT FOR
UPDATE/SHARE queries. If an EvalPlanQual recheck is necessary, we jam the
appropriate row into each scan node in the rechecking plan, forcing it to emit
only that one row. The former behavior could rescan the whole of each joined
relation for each recheck, which was terrible for performance, and what's much
worse could result in duplicated output tuples.
Also, the original implementation of EvalPlanQual could not re-use the recheck
execution tree --- it had to go through a full executor init and shutdown for
every row to be tested. To avoid this overhead, I've associated a special
runtime Param with each LockRows or ModifyTable plan node, and arranged to
make every scan node below such a node depend on that Param. Thus, by
signaling a change in that Param, the EPQ machinery can just rescan the
already-built test plan.
This patch also adds a prohibition on set-returning functions in the
targetlist of SELECT FOR UPDATE/SHARE. This is needed to avoid the
duplicate-output-tuple problem. It seems fairly reasonable since the
other restrictions on SELECT FOR UPDATE are meant to ensure that there
is a unique correspondence between source tuples and result tuples,
which an output SRF destroys as much as anything else does.
2009-10-26 03:26:45 +01:00
|
|
|
|
|
|
|
ExecScanReScan(&node->ss);
|
1999-11-23 21:07:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
|
|
|
* ExecEndTidScan
|
|
|
|
*
|
|
|
|
* Releases any storage allocated through C routines.
|
|
|
|
* Returns nothing.
|
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
void
|
2002-12-05 16:50:39 +01:00
|
|
|
ExecEndTidScan(TidScanState *node)
|
1999-11-23 21:07:06 +01:00
|
|
|
{
|
2002-02-19 21:11:20 +01:00
|
|
|
/*
|
2002-12-15 17:17:59 +01:00
|
|
|
* Free the exprcontext
|
2002-02-19 21:11:20 +01:00
|
|
|
*/
|
2002-12-05 16:50:39 +01:00
|
|
|
ExecFreeExprContext(&node->ss.ps);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* clear out tuple table slots
|
|
|
|
*/
|
|
|
|
ExecClearTuple(node->ss.ps.ps_ResultTupleSlot);
|
|
|
|
ExecClearTuple(node->ss.ss_ScanTupleSlot);
|
1999-11-23 21:07:06 +01:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2002-02-19 21:11:20 +01:00
|
|
|
* close the heap relation.
|
1999-11-23 21:07:06 +01:00
|
|
|
*/
|
2005-12-02 21:03:42 +01:00
|
|
|
ExecCloseScanRelation(node->ss.ss_currentRelation);
|
1999-11-23 21:07:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
|
|
|
* ExecInitTidScan
|
|
|
|
*
|
|
|
|
* Initializes the tid scan's state information, creates
|
|
|
|
* scan keys, and opens the base and tid relations.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* node: TidNode node produced by the planner.
|
|
|
|
* estate: the execution state initialized in InitPlan.
|
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
2002-12-05 16:50:39 +01:00
|
|
|
TidScanState *
|
2006-02-28 05:10:28 +01:00
|
|
|
ExecInitTidScan(TidScan *node, EState *estate, int eflags)
|
1999-11-23 21:07:06 +01:00
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
TidScanState *tidstate;
|
1999-11-23 21:07:06 +01:00
|
|
|
Relation currentRelation;
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2002-12-05 16:50:39 +01:00
|
|
|
* create state structure
|
1999-11-23 21:07:06 +01:00
|
|
|
*/
|
2002-12-05 16:50:39 +01:00
|
|
|
tidstate = makeNode(TidScanState);
|
|
|
|
tidstate->ss.ps.plan = (Plan *) node;
|
|
|
|
tidstate->ss.ps.state = estate;
|
2017-07-17 09:33:49 +02:00
|
|
|
tidstate->ss.ps.ExecProcNode = ExecTidScan;
|
1999-11-23 21:07:06 +01:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2002-12-05 16:50:39 +01:00
|
|
|
* Miscellaneous initialization
|
1999-11-23 21:07:06 +01:00
|
|
|
*
|
2002-12-05 16:50:39 +01:00
|
|
|
* create expression context for node
|
1999-11-23 21:07:06 +01:00
|
|
|
*/
|
2002-12-05 16:50:39 +01:00
|
|
|
ExecAssignExprContext(estate, &tidstate->ss.ps);
|
1999-11-23 21:07:06 +01:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2003-09-26 03:17:01 +02:00
|
|
|
* mark tid list as not computed yet
|
1999-11-23 21:07:06 +01:00
|
|
|
*/
|
2003-09-26 03:17:01 +02:00
|
|
|
tidstate->tss_TidList = NULL;
|
|
|
|
tidstate->tss_NumTids = 0;
|
|
|
|
tidstate->tss_TidPtr = -1;
|
1999-11-23 21:07:06 +01:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2005-12-02 21:03:42 +01:00
|
|
|
* open the base relation and acquire appropriate lock on it.
|
1999-11-23 21:07:06 +01:00
|
|
|
*/
|
2013-04-27 23:48:57 +02:00
|
|
|
currentRelation = ExecOpenScanRelation(estate, node->scan.scanrelid, eflags);
|
2002-02-19 21:11:20 +01:00
|
|
|
|
2002-12-05 16:50:39 +01:00
|
|
|
tidstate->ss.ss_currentRelation = currentRelation;
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:18:54 +02:00
|
|
|
tidstate->ss.ss_currentScanDesc = NULL; /* no heap scan here */
|
1999-11-23 21:07:06 +01:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* get the scan type from the relation descriptor.
|
1999-11-23 21:07:06 +01:00
|
|
|
*/
|
2018-02-17 06:17:38 +01:00
|
|
|
ExecInitScanTupleSlot(estate, &tidstate->ss,
|
|
|
|
RelationGetDescr(currentRelation));
|
1999-11-23 21:07:06 +01:00
|
|
|
|
2003-02-03 16:07:08 +01:00
|
|
|
/*
|
2018-02-17 06:17:38 +01:00
|
|
|
* Initialize result slot, type and projection.
|
2003-02-03 16:07:08 +01:00
|
|
|
*/
|
2018-02-17 06:17:38 +01:00
|
|
|
ExecInitResultTupleSlotTL(estate, &tidstate->ss.ps);
|
2003-02-03 16:07:08 +01:00
|
|
|
ExecAssignScanProjectionInfo(&tidstate->ss);
|
|
|
|
|
2018-02-17 06:17:38 +01:00
|
|
|
/*
|
|
|
|
* initialize child expressions
|
|
|
|
*/
|
|
|
|
tidstate->ss.ps.qual =
|
|
|
|
ExecInitQual(node->scan.plan.qual, (PlanState *) tidstate);
|
|
|
|
|
|
|
|
TidExprListCreate(tidstate);
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* all done.
|
1999-11-23 21:07:06 +01:00
|
|
|
*/
|
2002-12-05 16:50:39 +01:00
|
|
|
return tidstate;
|
1999-11-23 21:07:06 +01:00
|
|
|
}
|