Commit b8d7f053 authored by Andres Freund's avatar Andres Freund

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
parent 7d3957e5
...@@ -3421,7 +3421,7 @@ prepare_query_params(PlanState *node, ...@@ -3421,7 +3421,7 @@ prepare_query_params(PlanState *node,
* benefit, and it'd require postgres_fdw to know more than is desirable * benefit, and it'd require postgres_fdw to know more than is desirable
* about Param evaluation.) * about Param evaluation.)
*/ */
*param_exprs = (List *) ExecInitExpr((Expr *) fdw_exprs, node); *param_exprs = ExecInitExprList(fdw_exprs, node);
/* Allocate buffer for text form of query parameters. */ /* Allocate buffer for text form of query parameters. */
*param_values = (const char **) palloc0(numParams * sizeof(char *)); *param_values = (const char **) palloc0(numParams * sizeof(char *));
......
...@@ -1084,7 +1084,7 @@ index_register(Oid heap, ...@@ -1084,7 +1084,7 @@ index_register(Oid heap,
/* predicate will likely be null, but may as well copy it */ /* predicate will likely be null, but may as well copy it */
newind->il_info->ii_Predicate = (List *) newind->il_info->ii_Predicate = (List *)
copyObject(indexInfo->ii_Predicate); copyObject(indexInfo->ii_Predicate);
newind->il_info->ii_PredicateState = NIL; newind->il_info->ii_PredicateState = NULL;
/* no exclusion constraints at bootstrap time, so no need to copy */ /* no exclusion constraints at bootstrap time, so no need to copy */
Assert(indexInfo->ii_ExclusionOps == NULL); Assert(indexInfo->ii_ExclusionOps == NULL);
Assert(indexInfo->ii_ExclusionProcs == NULL); Assert(indexInfo->ii_ExclusionProcs == NULL);
......
...@@ -1658,7 +1658,7 @@ BuildIndexInfo(Relation index) ...@@ -1658,7 +1658,7 @@ BuildIndexInfo(Relation index)
/* fetch index predicate if any */ /* fetch index predicate if any */
ii->ii_Predicate = RelationGetIndexPredicate(index); ii->ii_Predicate = RelationGetIndexPredicate(index);
ii->ii_PredicateState = NIL; ii->ii_PredicateState = NULL;
/* fetch exclusion constraint info if any */ /* fetch exclusion constraint info if any */
if (indexStruct->indisexclusion) if (indexStruct->indisexclusion)
...@@ -1774,9 +1774,8 @@ FormIndexDatum(IndexInfo *indexInfo, ...@@ -1774,9 +1774,8 @@ FormIndexDatum(IndexInfo *indexInfo,
indexInfo->ii_ExpressionsState == NIL) indexInfo->ii_ExpressionsState == NIL)
{ {
/* First time through, set up expression evaluation state */ /* First time through, set up expression evaluation state */
indexInfo->ii_ExpressionsState = (List *) indexInfo->ii_ExpressionsState =
ExecPrepareExpr((Expr *) indexInfo->ii_Expressions, ExecPrepareExprList(indexInfo->ii_Expressions, estate);
estate);
/* Check caller has set up context correctly */ /* Check caller has set up context correctly */
Assert(GetPerTupleExprContext(estate)->ecxt_scantuple == slot); Assert(GetPerTupleExprContext(estate)->ecxt_scantuple == slot);
} }
...@@ -2208,7 +2207,7 @@ IndexBuildHeapRangeScan(Relation heapRelation, ...@@ -2208,7 +2207,7 @@ IndexBuildHeapRangeScan(Relation heapRelation,
Datum values[INDEX_MAX_KEYS]; Datum values[INDEX_MAX_KEYS];
bool isnull[INDEX_MAX_KEYS]; bool isnull[INDEX_MAX_KEYS];
double reltuples; double reltuples;
List *predicate; ExprState *predicate;
TupleTableSlot *slot; TupleTableSlot *slot;
EState *estate; EState *estate;
ExprContext *econtext; ExprContext *econtext;
...@@ -2247,9 +2246,7 @@ IndexBuildHeapRangeScan(Relation heapRelation, ...@@ -2247,9 +2246,7 @@ IndexBuildHeapRangeScan(Relation heapRelation,
econtext->ecxt_scantuple = slot; econtext->ecxt_scantuple = slot;
/* Set up execution state for predicate, if any. */ /* Set up execution state for predicate, if any. */
predicate = (List *) predicate = ExecPrepareQual(indexInfo->ii_Predicate, estate);
ExecPrepareExpr((Expr *) indexInfo->ii_Predicate,
estate);
/* /*
* Prepare for scan of the base relation. In a normal index build, we use * Prepare for scan of the base relation. In a normal index build, we use
...@@ -2552,9 +2549,9 @@ IndexBuildHeapRangeScan(Relation heapRelation, ...@@ -2552,9 +2549,9 @@ IndexBuildHeapRangeScan(Relation heapRelation,
* In a partial index, discard tuples that don't satisfy the * In a partial index, discard tuples that don't satisfy the
* predicate. * predicate.
*/ */
if (predicate != NIL) if (predicate != NULL)
{ {
if (!ExecQual(predicate, econtext, false)) if (!ExecQual(predicate, econtext))
continue; continue;
} }
...@@ -2619,7 +2616,7 @@ IndexBuildHeapRangeScan(Relation heapRelation, ...@@ -2619,7 +2616,7 @@ IndexBuildHeapRangeScan(Relation heapRelation,
/* These may have been pointing to the now-gone estate */ /* These may have been pointing to the now-gone estate */
indexInfo->ii_ExpressionsState = NIL; indexInfo->ii_ExpressionsState = NIL;
indexInfo->ii_PredicateState = NIL; indexInfo->ii_PredicateState = NULL;
return reltuples; return reltuples;
} }
...@@ -2646,7 +2643,7 @@ IndexCheckExclusion(Relation heapRelation, ...@@ -2646,7 +2643,7 @@ IndexCheckExclusion(Relation heapRelation,
HeapTuple heapTuple; HeapTuple heapTuple;
Datum values[INDEX_MAX_KEYS]; Datum values[INDEX_MAX_KEYS];
bool isnull[INDEX_MAX_KEYS]; bool isnull[INDEX_MAX_KEYS];
List *predicate; ExprState *predicate;
TupleTableSlot *slot; TupleTableSlot *slot;
EState *estate; EState *estate;
ExprContext *econtext; ExprContext *econtext;
...@@ -2672,9 +2669,7 @@ IndexCheckExclusion(Relation heapRelation, ...@@ -2672,9 +2669,7 @@ IndexCheckExclusion(Relation heapRelation,
econtext->ecxt_scantuple = slot; econtext->ecxt_scantuple = slot;
/* Set up execution state for predicate, if any. */ /* Set up execution state for predicate, if any. */
predicate = (List *) predicate = ExecPrepareQual(indexInfo->ii_Predicate, estate);
ExecPrepareExpr((Expr *) indexInfo->ii_Predicate,
estate);
/* /*
* Scan all live tuples in the base relation. * Scan all live tuples in the base relation.
...@@ -2699,9 +2694,9 @@ IndexCheckExclusion(Relation heapRelation, ...@@ -2699,9 +2694,9 @@ IndexCheckExclusion(Relation heapRelation,
/* /*
* In a partial index, ignore tuples that don't satisfy the predicate. * In a partial index, ignore tuples that don't satisfy the predicate.
*/ */
if (predicate != NIL) if (predicate != NULL)
{ {
if (!ExecQual(predicate, econtext, false)) if (!ExecQual(predicate, econtext))
continue; continue;
} }
...@@ -2732,7 +2727,7 @@ IndexCheckExclusion(Relation heapRelation, ...@@ -2732,7 +2727,7 @@ IndexCheckExclusion(Relation heapRelation,
/* These may have been pointing to the now-gone estate */ /* These may have been pointing to the now-gone estate */
indexInfo->ii_ExpressionsState = NIL; indexInfo->ii_ExpressionsState = NIL;
indexInfo->ii_PredicateState = NIL; indexInfo->ii_PredicateState = NULL;
} }
...@@ -2962,7 +2957,7 @@ validate_index_heapscan(Relation heapRelation, ...@@ -2962,7 +2957,7 @@ validate_index_heapscan(Relation heapRelation,
HeapTuple heapTuple; HeapTuple heapTuple;
Datum values[INDEX_MAX_KEYS]; Datum values[INDEX_MAX_KEYS];
bool isnull[INDEX_MAX_KEYS]; bool isnull[INDEX_MAX_KEYS];
List *predicate; ExprState *predicate;
TupleTableSlot *slot; TupleTableSlot *slot;
EState *estate; EState *estate;
ExprContext *econtext; ExprContext *econtext;
...@@ -2992,9 +2987,7 @@ validate_index_heapscan(Relation heapRelation, ...@@ -2992,9 +2987,7 @@ validate_index_heapscan(Relation heapRelation,
econtext->ecxt_scantuple = slot; econtext->ecxt_scantuple = slot;
/* Set up execution state for predicate, if any. */ /* Set up execution state for predicate, if any. */
predicate = (List *) predicate = ExecPrepareQual(indexInfo->ii_Predicate, estate);
ExecPrepareExpr((Expr *) indexInfo->ii_Predicate,
estate);
/* /*
* Prepare for scan of the base relation. We need just those tuples * Prepare for scan of the base relation. We need just those tuples
...@@ -3121,9 +3114,9 @@ validate_index_heapscan(Relation heapRelation, ...@@ -3121,9 +3114,9 @@ validate_index_heapscan(Relation heapRelation,
* In a partial index, discard tuples that don't satisfy the * In a partial index, discard tuples that don't satisfy the
* predicate. * predicate.
*/ */
if (predicate != NIL) if (predicate != NULL)
{ {
if (!ExecQual(predicate, econtext, false)) if (!ExecQual(predicate, econtext))
continue; continue;
} }
...@@ -3177,7 +3170,7 @@ validate_index_heapscan(Relation heapRelation, ...@@ -3177,7 +3170,7 @@ validate_index_heapscan(Relation heapRelation,
/* These may have been pointing to the now-gone estate */ /* These may have been pointing to the now-gone estate */
indexInfo->ii_ExpressionsState = NIL; indexInfo->ii_ExpressionsState = NIL;
indexInfo->ii_PredicateState = NIL; indexInfo->ii_PredicateState = NULL;
} }
......
...@@ -1618,8 +1618,7 @@ FormPartitionKeyDatum(PartitionDispatch pd, ...@@ -1618,8 +1618,7 @@ FormPartitionKeyDatum(PartitionDispatch pd,
GetPerTupleExprContext(estate)->ecxt_scantuple == slot); GetPerTupleExprContext(estate)->ecxt_scantuple == slot);
/* First time through, set up expression evaluation state */ /* First time through, set up expression evaluation state */
pd->keystate = (List *) ExecPrepareExpr((Expr *) pd->key->partexprs, pd->keystate = ExecPrepareExprList(pd->key->partexprs, estate);
estate);
} }
partexpr_item = list_head(pd->keystate); partexpr_item = list_head(pd->keystate);
......
...@@ -307,7 +307,7 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, ...@@ -307,7 +307,7 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
indexInfo->ii_Expressions = NIL; indexInfo->ii_Expressions = NIL;
indexInfo->ii_ExpressionsState = NIL; indexInfo->ii_ExpressionsState = NIL;
indexInfo->ii_Predicate = NIL; indexInfo->ii_Predicate = NIL;
indexInfo->ii_PredicateState = NIL; indexInfo->ii_PredicateState = NULL;
indexInfo->ii_ExclusionOps = NULL; indexInfo->ii_ExclusionOps = NULL;
indexInfo->ii_ExclusionProcs = NULL; indexInfo->ii_ExclusionProcs = NULL;
indexInfo->ii_ExclusionStrats = NULL; indexInfo->ii_ExclusionStrats = NULL;
......
...@@ -713,7 +713,7 @@ compute_index_stats(Relation onerel, double totalrows, ...@@ -713,7 +713,7 @@ compute_index_stats(Relation onerel, double totalrows,
TupleTableSlot *slot; TupleTableSlot *slot;
EState *estate; EState *estate;
ExprContext *econtext; ExprContext *econtext;
List *predicate; ExprState *predicate;
Datum *exprvals; Datum *exprvals;
bool *exprnulls; bool *exprnulls;
int numindexrows, int numindexrows,
...@@ -739,9 +739,7 @@ compute_index_stats(Relation onerel, double totalrows, ...@@ -739,9 +739,7 @@ compute_index_stats(Relation onerel, double totalrows,
econtext->ecxt_scantuple = slot; econtext->ecxt_scantuple = slot;
/* Set up execution state for predicate. */ /* Set up execution state for predicate. */
predicate = castNode(List, predicate = ExecPrepareQual(indexInfo->ii_Predicate, estate);
ExecPrepareExpr((Expr *) indexInfo->ii_Predicate,
estate));
/* Compute and save index expression values */ /* Compute and save index expression values */
exprvals = (Datum *) palloc(numrows * attr_cnt * sizeof(Datum)); exprvals = (Datum *) palloc(numrows * attr_cnt * sizeof(Datum));
...@@ -764,9 +762,9 @@ compute_index_stats(Relation onerel, double totalrows, ...@@ -764,9 +762,9 @@ compute_index_stats(Relation onerel, double totalrows,
ExecStoreTuple(heapTuple, slot, InvalidBuffer, false); ExecStoreTuple(heapTuple, slot, InvalidBuffer, false);
/* If index is partial, check predicate */ /* If index is partial, check predicate */
if (predicate != NIL) if (predicate != NULL)
{ {
if (!ExecQual(predicate, econtext, false)) if (!ExecQual(predicate, econtext))
continue; continue;
} }
numindexrows++; numindexrows++;
......
...@@ -2890,7 +2890,7 @@ ExplainSubPlans(List *plans, List *ancestors, ...@@ -2890,7 +2890,7 @@ ExplainSubPlans(List *plans, List *ancestors,
foreach(lst, plans) foreach(lst, plans)
{ {
SubPlanState *sps = (SubPlanState *) lfirst(lst); SubPlanState *sps = (SubPlanState *) lfirst(lst);
SubPlan *sp = (SubPlan *) sps->xprstate.expr; SubPlan *sp = sps->subplan;
/* /*
* There can be multiple SubPlan nodes referencing the same physical * There can be multiple SubPlan nodes referencing the same physical
......
...@@ -179,7 +179,7 @@ CheckIndexCompatible(Oid oldId, ...@@ -179,7 +179,7 @@ CheckIndexCompatible(Oid oldId,
indexInfo = makeNode(IndexInfo); indexInfo = makeNode(IndexInfo);
indexInfo->ii_Expressions = NIL; indexInfo->ii_Expressions = NIL;
indexInfo->ii_ExpressionsState = NIL; indexInfo->ii_ExpressionsState = NIL;
indexInfo->ii_PredicateState = NIL; indexInfo->ii_PredicateState = NULL;
indexInfo->ii_ExclusionOps = NULL; indexInfo->ii_ExclusionOps = NULL;
indexInfo->ii_ExclusionProcs = NULL; indexInfo->ii_ExclusionProcs = NULL;
indexInfo->ii_ExclusionStrats = NULL; indexInfo->ii_ExclusionStrats = NULL;
...@@ -551,7 +551,7 @@ DefineIndex(Oid relationId, ...@@ -551,7 +551,7 @@ DefineIndex(Oid relationId,
indexInfo->ii_Expressions = NIL; /* for now */ indexInfo->ii_Expressions = NIL; /* for now */
indexInfo->ii_ExpressionsState = NIL; indexInfo->ii_ExpressionsState = NIL;
indexInfo->ii_Predicate = make_ands_implicit((Expr *) stmt->whereClause); indexInfo->ii_Predicate = make_ands_implicit((Expr *) stmt->whereClause);
indexInfo->ii_PredicateState = NIL; indexInfo->ii_PredicateState = NULL;
indexInfo->ii_ExclusionOps = NULL; indexInfo->ii_ExclusionOps = NULL;
indexInfo->ii_ExclusionProcs = NULL; indexInfo->ii_ExclusionProcs = NULL;
indexInfo->ii_ExclusionStrats = NULL; indexInfo->ii_ExclusionStrats = NULL;
......
...@@ -391,7 +391,7 @@ EvaluateParams(PreparedStatement *pstmt, List *params, ...@@ -391,7 +391,7 @@ EvaluateParams(PreparedStatement *pstmt, List *params,
} }
/* Prepare the expressions for execution */ /* Prepare the expressions for execution */
exprstates = (List *) ExecPrepareExpr((Expr *) params, estate); exprstates = ExecPrepareExprList(params, estate);
paramLI = (ParamListInfo) paramLI = (ParamListInfo)
palloc(offsetof(ParamListInfoData, params) + palloc(offsetof(ParamListInfoData, params) +
...@@ -407,7 +407,7 @@ EvaluateParams(PreparedStatement *pstmt, List *params, ...@@ -407,7 +407,7 @@ EvaluateParams(PreparedStatement *pstmt, List *params,
i = 0; i = 0;
foreach(l, exprstates) foreach(l, exprstates)
{ {
ExprState *n = lfirst(l); ExprState *n = (ExprState *) lfirst(l);
ParamExternData *prm = &paramLI->params[i]; ParamExternData *prm = &paramLI->params[i];
prm->ptype = param_types[i]; prm->ptype = param_types[i];
......
...@@ -185,7 +185,7 @@ typedef struct NewConstraint ...@@ -185,7 +185,7 @@ typedef struct NewConstraint
Oid refindid; /* OID of PK's index, if FOREIGN */ Oid refindid; /* OID of PK's index, if FOREIGN */
Oid conid; /* OID of pg_constraint entry, if FOREIGN */ Oid conid; /* OID of pg_constraint entry, if FOREIGN */
Node *qual; /* Check expr or CONSTR_FOREIGN Constraint */ Node *qual; /* Check expr or CONSTR_FOREIGN Constraint */
List *qualstate; /* Execution state for CHECK */ ExprState *qualstate; /* Execution state for CHECK expr */
} NewConstraint; } NewConstraint;
/* /*
...@@ -4262,7 +4262,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode) ...@@ -4262,7 +4262,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
CommandId mycid; CommandId mycid;
BulkInsertState bistate; BulkInsertState bistate;
int hi_options; int hi_options;
List *partqualstate = NIL; ExprState *partqualstate = NULL;
/* /*
* Open the relation(s). We have surely already locked the existing * Open the relation(s). We have surely already locked the existing
...@@ -4315,8 +4315,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode) ...@@ -4315,8 +4315,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
{ {
case CONSTR_CHECK: case CONSTR_CHECK:
needscan = true; needscan = true;
con->qualstate = (List *) con->qualstate = ExecPrepareExpr((Expr *) con->qual, estate);
ExecPrepareExpr((Expr *) con->qual, estate);
break; break;
case CONSTR_FOREIGN: case CONSTR_FOREIGN:
/* Nothing to do here */ /* Nothing to do here */
...@@ -4331,9 +4330,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode) ...@@ -4331,9 +4330,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
if (tab->partition_constraint) if (tab->partition_constraint)
{ {
needscan = true; needscan = true;
partqualstate = (List *) partqualstate = ExecPrepareCheck(tab->partition_constraint, estate);
ExecPrepareExpr((Expr *) tab->partition_constraint,
estate);
} }
foreach(l, tab->newvals) foreach(l, tab->newvals)
...@@ -4508,7 +4505,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode) ...@@ -4508,7 +4505,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
switch (con->contype) switch (con->contype)
{ {
case CONSTR_CHECK: case CONSTR_CHECK:
if (!ExecQual(con->qualstate, econtext, true)) if (!ExecCheck(con->qualstate, econtext))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_CHECK_VIOLATION), (errcode(ERRCODE_CHECK_VIOLATION),
errmsg("check constraint \"%s\" is violated by some row", errmsg("check constraint \"%s\" is violated by some row",
...@@ -4524,7 +4521,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode) ...@@ -4524,7 +4521,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
} }
} }
if (partqualstate && !ExecQual(partqualstate, econtext, true)) if (partqualstate && !ExecCheck(partqualstate, econtext))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_CHECK_VIOLATION), (errcode(ERRCODE_CHECK_VIOLATION),
errmsg("partition constraint is violated by some row"))); errmsg("partition constraint is violated by some row")));
...@@ -6607,8 +6604,7 @@ ATAddCheckConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel, ...@@ -6607,8 +6604,7 @@ ATAddCheckConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
newcon = (NewConstraint *) palloc0(sizeof(NewConstraint)); newcon = (NewConstraint *) palloc0(sizeof(NewConstraint));
newcon->name = ccon->name; newcon->name = ccon->name;
newcon->contype = ccon->contype; newcon->contype = ccon->contype;
/* ExecQual wants implicit-AND format */ newcon->qual = ccon->expr;
newcon->qual = (Node *) make_ands_implicit((Expr *) ccon->expr);
tab->constraints = lappend(tab->constraints, newcon); tab->constraints = lappend(tab->constraints, newcon);
} }
...@@ -7786,7 +7782,7 @@ validateCheckConstraint(Relation rel, HeapTuple constrtup) ...@@ -7786,7 +7782,7 @@ validateCheckConstraint(Relation rel, HeapTuple constrtup)
Datum val; Datum val;
char *conbin; char *conbin;
Expr *origexpr; Expr *origexpr;
List *exprstate; ExprState *exprstate;
TupleDesc tupdesc; TupleDesc tupdesc;
HeapScanDesc scan; HeapScanDesc scan;
HeapTuple tuple; HeapTuple tuple;
...@@ -7817,8 +7813,7 @@ validateCheckConstraint(Relation rel, HeapTuple constrtup) ...@@ -7817,8 +7813,7 @@ validateCheckConstraint(Relation rel, HeapTuple constrtup)
HeapTupleGetOid(constrtup)); HeapTupleGetOid(constrtup));
conbin = TextDatumGetCString(val); conbin = TextDatumGetCString(val);
origexpr = (Expr *) stringToNode(conbin); origexpr = (Expr *) stringToNode(conbin);
exprstate = (List *) exprstate = ExecPrepareExpr(origexpr, estate);
ExecPrepareExpr((Expr *) make_ands_implicit(origexpr), estate);
econtext = GetPerTupleExprContext(estate); econtext = GetPerTupleExprContext(estate);
tupdesc = RelationGetDescr(rel); tupdesc = RelationGetDescr(rel);
...@@ -7838,7 +7833,7 @@ validateCheckConstraint(Relation rel, HeapTuple constrtup) ...@@ -7838,7 +7833,7 @@ validateCheckConstraint(Relation rel, HeapTuple constrtup)
{ {
ExecStoreTuple(tuple, slot, InvalidBuffer, false); ExecStoreTuple(tuple, slot, InvalidBuffer, false);
if (!ExecQual(exprstate, econtext, true)) if (!ExecCheck(exprstate, econtext))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_CHECK_VIOLATION), (errcode(ERRCODE_CHECK_VIOLATION),
errmsg("check constraint \"%s\" is violated by some row", errmsg("check constraint \"%s\" is violated by some row",
......
...@@ -3057,7 +3057,7 @@ TriggerEnabled(EState *estate, ResultRelInfo *relinfo, ...@@ -3057,7 +3057,7 @@ TriggerEnabled(EState *estate, ResultRelInfo *relinfo,
if (trigger->tgqual) if (trigger->tgqual)
{ {
TupleDesc tupdesc = RelationGetDescr(relinfo->ri_RelationDesc); TupleDesc tupdesc = RelationGetDescr(relinfo->ri_RelationDesc);
List **predicate; ExprState **predicate;
ExprContext *econtext; ExprContext *econtext;
TupleTableSlot *oldslot = NULL; TupleTableSlot *oldslot = NULL;
TupleTableSlot *newslot = NULL; TupleTableSlot *newslot = NULL;
...@@ -3078,7 +3078,7 @@ TriggerEnabled(EState *estate, ResultRelInfo *relinfo, ...@@ -3078,7 +3078,7 @@ TriggerEnabled(EState *estate, ResultRelInfo *relinfo,
* nodetrees for it. Keep them in the per-query memory context so * nodetrees for it. Keep them in the per-query memory context so
* they'll survive throughout the query. * they'll survive throughout the query.
*/ */
if (*predicate == NIL) if (*predicate == NULL)
{ {
Node *tgqual; Node *tgqual;
...@@ -3087,9 +3087,9 @@ TriggerEnabled(EState *estate, ResultRelInfo *relinfo, ...@@ -3087,9 +3087,9 @@ TriggerEnabled(EState *estate, ResultRelInfo *relinfo,
/* Change references to OLD and NEW to INNER_VAR and OUTER_VAR */ /* Change references to OLD and NEW to INNER_VAR and OUTER_VAR */
ChangeVarNodes(tgqual, PRS2_OLD_VARNO, INNER_VAR, 0); ChangeVarNodes(tgqual, PRS2_OLD_VARNO, INNER_VAR, 0);
ChangeVarNodes(tgqual, PRS2_NEW_VARNO, OUTER_VAR, 0); ChangeVarNodes(tgqual, PRS2_NEW_VARNO, OUTER_VAR, 0);
/* ExecQual wants implicit-AND form */ /* ExecPrepareQual wants implicit-AND form */
tgqual = (Node *) make_ands_implicit((Expr *) tgqual); tgqual = (Node *) make_ands_implicit((Expr *) tgqual);
*predicate = (List *) ExecPrepareExpr((Expr *) tgqual, estate); *predicate = ExecPrepareQual((List *) tgqual, estate);
MemoryContextSwitchTo(oldContext); MemoryContextSwitchTo(oldContext);
} }
...@@ -3137,7 +3137,7 @@ TriggerEnabled(EState *estate, ResultRelInfo *relinfo, ...@@ -3137,7 +3137,7 @@ TriggerEnabled(EState *estate, ResultRelInfo *relinfo,
*/ */
econtext->ecxt_innertuple = oldslot; econtext->ecxt_innertuple = oldslot;
econtext->ecxt_outertuple = newslot; econtext->ecxt_outertuple = newslot;
if (!ExecQual(*predicate, econtext, false)) if (!ExecQual(*predicate, econtext))
return false; return false;
} }
......
...@@ -12,9 +12,10 @@ subdir = src/backend/executor ...@@ -12,9 +12,10 @@ subdir = src/backend/executor
top_builddir = ../../.. top_builddir = ../../..
include $(top_builddir)/src/Makefile.global include $(top_builddir)/src/Makefile.global
OBJS = execAmi.o execCurrent.o execGrouping.o execIndexing.o execJunk.o \ OBJS = execAmi.o execCurrent.o execExpr.o execExprInterp.o \
execMain.o execParallel.o execProcnode.o execQual.o \ execGrouping.o execIndexing.o execJunk.o \
execReplication.o execScan.o execTuples.o \ execMain.o execParallel.o execProcnode.o \
execReplication.o execScan.o execSRF.o execTuples.o \
execUtils.o functions.o instrument.o nodeAppend.o nodeAgg.o \ execUtils.o functions.o instrument.o nodeAppend.o nodeAgg.o \
nodeBitmapAnd.o nodeBitmapOr.o \ nodeBitmapAnd.o nodeBitmapOr.o \
nodeBitmapHeapscan.o nodeBitmapIndexscan.o \ nodeBitmapHeapscan.o nodeBitmapIndexscan.o \
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -327,23 +327,21 @@ ExecInsertIndexTuples(TupleTableSlot *slot, ...@@ -327,23 +327,21 @@ ExecInsertIndexTuples(TupleTableSlot *slot,
/* Check for partial index */ /* Check for partial index */
if (indexInfo->ii_Predicate != NIL) if (indexInfo->ii_Predicate != NIL)
{ {
List *predicate; ExprState *predicate;
/* /*
* If predicate state not set up yet, create it (in the estate's * If predicate state not set up yet, create it (in the estate's
* per-query context) * per-query context)
*/ */
predicate = indexInfo->ii_PredicateState; predicate = indexInfo->ii_PredicateState;
if (predicate == NIL) if (predicate == NULL)
{ {
predicate = (List *) predicate = ExecPrepareQual(indexInfo->ii_Predicate, estate);
ExecPrepareExpr((Expr *) indexInfo->ii_Predicate,
estate);
indexInfo->ii_PredicateState = predicate; indexInfo->ii_PredicateState = predicate;
} }
/* Skip this index-update if the predicate isn't satisfied */ /* Skip this index-update if the predicate isn't satisfied */
if (!ExecQual(predicate, econtext, false)) if (!ExecQual(predicate, econtext))
continue; continue;
} }
...@@ -551,23 +549,21 @@ ExecCheckIndexConstraints(TupleTableSlot *slot, ...@@ -551,23 +549,21 @@ ExecCheckIndexConstraints(TupleTableSlot *slot,
/* Check for partial index */ /* Check for partial index */
if (indexInfo->ii_Predicate != NIL) if (indexInfo->ii_Predicate != NIL)
{ {
List *predicate; ExprState *predicate;
/* /*
* If predicate state not set up yet, create it (in the estate's * If predicate state not set up yet, create it (in the estate's
* per-query context) * per-query context)
*/ */
predicate = indexInfo->ii_PredicateState; predicate = indexInfo->ii_PredicateState;
if (predicate == NIL) if (predicate == NULL)
{ {
predicate = (List *) predicate = ExecPrepareQual(indexInfo->ii_Predicate, estate);
ExecPrepareExpr((Expr *) indexInfo->ii_Predicate,
estate);
indexInfo->ii_PredicateState = predicate; indexInfo->ii_PredicateState = predicate;
} }
/* Skip this index-update if the predicate isn't satisfied */ /* Skip this index-update if the predicate isn't satisfied */
if (!ExecQual(predicate, econtext, false)) if (!ExecQual(predicate, econtext))
continue; continue;
} }
......
...@@ -600,8 +600,8 @@ ExecCheckRTEPerms(RangeTblEntry *rte) ...@@ -600,8 +600,8 @@ ExecCheckRTEPerms(RangeTblEntry *rte)
/* /*
* Only plain-relation RTEs need to be checked here. Function RTEs are * Only plain-relation RTEs need to be checked here. Function RTEs are
* checked by init_fcache when the function is prepared for execution. * checked when the function is prepared for execution. Join, subquery,
* Join, subquery, and special RTEs need no checks. * and special RTEs need no checks.
*/ */
if (rte->rtekind != RTE_RELATION) if (rte->rtekind != RTE_RELATION)
return true; return true;
...@@ -1275,8 +1275,8 @@ InitResultRelInfo(ResultRelInfo *resultRelInfo, ...@@ -1275,8 +1275,8 @@ InitResultRelInfo(ResultRelInfo *resultRelInfo,
resultRelInfo->ri_TrigFunctions = (FmgrInfo *) resultRelInfo->ri_TrigFunctions = (FmgrInfo *)
palloc0(n * sizeof(FmgrInfo)); palloc0(n * sizeof(FmgrInfo));
resultRelInfo->ri_TrigWhenExprs = (List **) resultRelInfo->ri_TrigWhenExprs = (ExprState **)
palloc0(n * sizeof(List *)); palloc0(n * sizeof(ExprState *));
if (instrument_options) if (instrument_options)
resultRelInfo->ri_TrigInstrument = InstrAlloc(n, instrument_options); resultRelInfo->ri_TrigInstrument = InstrAlloc(n, instrument_options);
} }
...@@ -1723,7 +1723,6 @@ ExecRelCheck(ResultRelInfo *resultRelInfo, ...@@ -1723,7 +1723,6 @@ ExecRelCheck(ResultRelInfo *resultRelInfo,
ConstrCheck *check = rel->rd_att->constr->check; ConstrCheck *check = rel->rd_att->constr->check;
ExprContext *econtext; ExprContext *econtext;
MemoryContext oldContext; MemoryContext oldContext;
List *qual;
int i; int i;
/* /*
...@@ -1735,13 +1734,14 @@ ExecRelCheck(ResultRelInfo *resultRelInfo, ...@@ -1735,13 +1734,14 @@ ExecRelCheck(ResultRelInfo *resultRelInfo,
{ {
oldContext = MemoryContextSwitchTo(estate->es_query_cxt); oldContext = MemoryContextSwitchTo(estate->es_query_cxt);
resultRelInfo->ri_ConstraintExprs = resultRelInfo->ri_ConstraintExprs =
(List **) palloc(ncheck * sizeof(List *)); (ExprState **) palloc(ncheck * sizeof(ExprState *));
for (i = 0; i < ncheck; i++) for (i = 0; i < ncheck; i++)
{ {
/* ExecQual wants implicit-AND form */ Expr *checkconstr;
qual = make_ands_implicit(stringToNode(check[i].ccbin));
resultRelInfo->ri_ConstraintExprs[i] = (List *) checkconstr = stringToNode(check[i].ccbin);
ExecPrepareExpr((Expr *) qual, estate); resultRelInfo->ri_ConstraintExprs[i] =
ExecPrepareExpr(checkconstr, estate);
} }
MemoryContextSwitchTo(oldContext); MemoryContextSwitchTo(oldContext);
} }
...@@ -1758,14 +1758,14 @@ ExecRelCheck(ResultRelInfo *resultRelInfo, ...@@ -1758,14 +1758,14 @@ ExecRelCheck(ResultRelInfo *resultRelInfo,
/* And evaluate the constraints */ /* And evaluate the constraints */
for (i = 0; i < ncheck; i++) for (i = 0; i < ncheck; i++)
{ {
qual = resultRelInfo->ri_ConstraintExprs[i]; ExprState *checkconstr = resultRelInfo->ri_ConstraintExprs[i];
/* /*
* NOTE: SQL specifies that a NULL result from a constraint expression * NOTE: SQL specifies that a NULL result from a constraint expression
* is not to be treated as a failure. Therefore, tell ExecQual to * is not to be treated as a failure. Therefore, use ExecCheck not
* return TRUE for NULL. * ExecQual.
*/ */
if (!ExecQual(qual, econtext, true)) if (!ExecCheck(checkconstr, econtext))
return check[i].ccname; return check[i].ccname;
} }
...@@ -1793,8 +1793,7 @@ ExecPartitionCheck(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, ...@@ -1793,8 +1793,7 @@ ExecPartitionCheck(ResultRelInfo *resultRelInfo, TupleTableSlot *slot,
{ {
List *qual = resultRelInfo->ri_PartitionCheck; List *qual = resultRelInfo->ri_PartitionCheck;
resultRelInfo->ri_PartitionCheckExpr = (List *) resultRelInfo->ri_PartitionCheckExpr = ExecPrepareCheck(qual, estate);
ExecPrepareExpr((Expr *) qual, estate);
} }
/* /*
...@@ -1810,7 +1809,7 @@ ExecPartitionCheck(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, ...@@ -1810,7 +1809,7 @@ ExecPartitionCheck(ResultRelInfo *resultRelInfo, TupleTableSlot *slot,
* As in case of the catalogued constraints, we treat a NULL result as * As in case of the catalogued constraints, we treat a NULL result as
* success here, not a failure. * success here, not a failure.
*/ */
return ExecQual(resultRelInfo->ri_PartitionCheckExpr, econtext, true); return ExecCheck(resultRelInfo->ri_PartitionCheckExpr, econtext);
} }
/* /*
...@@ -1990,11 +1989,9 @@ ExecWithCheckOptions(WCOKind kind, ResultRelInfo *resultRelInfo, ...@@ -1990,11 +1989,9 @@ ExecWithCheckOptions(WCOKind kind, ResultRelInfo *resultRelInfo,
* is visible (in the case of a view) or that it passes the * is visible (in the case of a view) or that it passes the
* 'with-check' policy (in the case of row security). If the qual * 'with-check' policy (in the case of row security). If the qual
* evaluates to NULL or FALSE, then the new tuple won't be included in * evaluates to NULL or FALSE, then the new tuple won't be included in
* the view or doesn't pass the 'with-check' policy for the table. We * the view or doesn't pass the 'with-check' policy for the table.
* need ExecQual to return FALSE for NULL to handle the view case (the
* opposite of what we do above for CHECK constraints).
*/ */
if (!ExecQual((List *) wcoExpr, econtext, false)) if (!ExecQual(wcoExpr, econtext))
{ {
char *val_desc; char *val_desc;
Bitmapset *modifiedCols; Bitmapset *modifiedCols;
......
This diff is collapsed.
This diff is collapsed.
...@@ -123,7 +123,7 @@ ExecScan(ScanState *node, ...@@ -123,7 +123,7 @@ ExecScan(ScanState *node,
ExecScanRecheckMtd recheckMtd) ExecScanRecheckMtd recheckMtd)
{ {
ExprContext *econtext; ExprContext *econtext;
List *qual; ExprState *qual;
ProjectionInfo *projInfo; ProjectionInfo *projInfo;
/* /*
...@@ -170,7 +170,7 @@ ExecScan(ScanState *node, ...@@ -170,7 +170,7 @@ ExecScan(ScanState *node,
if (TupIsNull(slot)) if (TupIsNull(slot))
{ {
if (projInfo) if (projInfo)
return ExecClearTuple(projInfo->pi_slot); return ExecClearTuple(projInfo->pi_state.resultslot);
else else
return slot; return slot;
} }
...@@ -183,11 +183,11 @@ ExecScan(ScanState *node, ...@@ -183,11 +183,11 @@ ExecScan(ScanState *node,
/* /*
* check that the current tuple satisfies the qual-clause * check that the current tuple satisfies the qual-clause
* *
* check for non-nil qual here to avoid a function call to ExecQual() * check for non-null qual here to avoid a function call to ExecQual()
* when the qual is nil ... saves only a few cycles, but they add up * when the qual is null ... saves only a few cycles, but they add up
* ... * ...
*/ */
if (!qual || ExecQual(qual, econtext, false)) if (qual == NULL || ExecQual(qual, econtext))
{ {
/* /*
* Found a satisfactory scan tuple. * Found a satisfactory scan tuple.
......
This diff is collapsed.
...@@ -1279,7 +1279,7 @@ fmgr_sql(PG_FUNCTION_ARGS) ...@@ -1279,7 +1279,7 @@ fmgr_sql(PG_FUNCTION_ARGS)
rsi->returnMode = SFRM_Materialize; rsi->returnMode = SFRM_Materialize;
rsi->setResult = fcache->tstore; rsi->setResult = fcache->tstore;
fcache->tstore = NULL; fcache->tstore = NULL;
/* must copy desc because execQual will free it */ /* must copy desc because execSRF.c will free it */
if (fcache->junkFilter) if (fcache->junkFilter)
rsi->setDesc = CreateTupleDescCopy(fcache->junkFilter->jf_cleanTupType); rsi->setDesc = CreateTupleDescCopy(fcache->junkFilter->jf_cleanTupType);
......
...@@ -1639,7 +1639,7 @@ project_aggregates(AggState *aggstate) ...@@ -1639,7 +1639,7 @@ project_aggregates(AggState *aggstate)
/* /*
* Check the qual (HAVING clause); if the group does not match, ignore it. * Check the qual (HAVING clause); if the group does not match, ignore it.
*/ */
if (ExecQual(aggstate->ss.ps.qual, econtext, false)) if (ExecQual(aggstate->ss.ps.qual, econtext))
{ {
/* /*
* Form and return projection tuple using the aggregate results and * Form and return projection tuple using the aggregate results and
...@@ -2501,18 +2501,17 @@ ExecInitAgg(Agg *node, EState *estate, int eflags) ...@@ -2501,18 +2501,17 @@ ExecInitAgg(Agg *node, EState *estate, int eflags)
/* /*
* initialize child expressions * initialize child expressions
* *
* Note: ExecInitExpr finds Aggrefs for us, and also checks that no aggs * We rely on the parser to have checked that no aggs contain other agg
* contain other agg calls in their arguments. This would make no sense * calls in their arguments. This would make no sense under SQL semantics
* under SQL semantics anyway (and it's forbidden by the spec). Because * (and it's forbidden by the spec). Because it is true, we don't need to
* that is true, we don't need to worry about evaluating the aggs in any * worry about evaluating the aggs in any particular order.
* particular order. *
* Note: execExpr.c finds Aggrefs for us, and adds their AggrefExprState
* nodes to aggstate->aggs. Aggrefs in the qual are found here; Aggrefs
* in the targetlist are found during ExecAssignProjectionInfo, below.
*/ */
aggstate->ss.ps.targetlist = (List *) aggstate->ss.ps.qual =
ExecInitExpr((Expr *) node->plan.targetlist, ExecInitQual(node->plan.qual, (PlanState *) aggstate);
(PlanState *) aggstate);
aggstate->ss.ps.qual = (List *)
ExecInitExpr((Expr *) node->plan.qual,
(PlanState *) aggstate);
/* /*
* Initialize child nodes. * Initialize child nodes.
...@@ -2540,7 +2539,7 @@ ExecInitAgg(Agg *node, EState *estate, int eflags) ...@@ -2540,7 +2539,7 @@ ExecInitAgg(Agg *node, EState *estate, int eflags)
ExecAssignProjectionInfo(&aggstate->ss.ps, NULL); ExecAssignProjectionInfo(&aggstate->ss.ps, NULL);
/* /*
* get the count of aggregates in targetlist and quals * We should now have found all Aggrefs in the targetlist and quals.
*/ */
numaggs = aggstate->numaggs; numaggs = aggstate->numaggs;
Assert(numaggs == list_length(aggstate->aggs)); Assert(numaggs == list_length(aggstate->aggs));
...@@ -2724,7 +2723,7 @@ ExecInitAgg(Agg *node, EState *estate, int eflags) ...@@ -2724,7 +2723,7 @@ ExecInitAgg(Agg *node, EState *estate, int eflags)
foreach(l, aggstate->aggs) foreach(l, aggstate->aggs)
{ {
AggrefExprState *aggrefstate = (AggrefExprState *) lfirst(l); AggrefExprState *aggrefstate = (AggrefExprState *) lfirst(l);
Aggref *aggref = (Aggref *) aggrefstate->xprstate.expr; Aggref *aggref = aggrefstate->aggref;
AggStatePerAgg peragg; AggStatePerAgg peragg;
AggStatePerTrans pertrans; AggStatePerTrans pertrans;
int existing_aggno; int existing_aggno;
...@@ -3024,11 +3023,10 @@ ExecInitAgg(Agg *node, EState *estate, int eflags) ...@@ -3024,11 +3023,10 @@ ExecInitAgg(Agg *node, EState *estate, int eflags)
/* and then create a projection for that targetlist */ /* and then create a projection for that targetlist */
aggstate->evaldesc = ExecTypeFromTL(combined_inputeval, false); aggstate->evaldesc = ExecTypeFromTL(combined_inputeval, false);
aggstate->evalslot = ExecInitExtraTupleSlot(estate); aggstate->evalslot = ExecInitExtraTupleSlot(estate);
combined_inputeval = (List *) ExecInitExpr((Expr *) combined_inputeval,
(PlanState *) aggstate);
aggstate->evalproj = ExecBuildProjectionInfo(combined_inputeval, aggstate->evalproj = ExecBuildProjectionInfo(combined_inputeval,
aggstate->tmpcontext, aggstate->tmpcontext,
aggstate->evalslot, aggstate->evalslot,
&aggstate->ss.ps,
NULL); NULL);
ExecSetSlotDescriptor(aggstate->evalslot, aggstate->evaldesc); ExecSetSlotDescriptor(aggstate->evalslot, aggstate->evaldesc);
...@@ -3206,7 +3204,7 @@ build_pertrans_for_aggref(AggStatePerTrans pertrans, ...@@ -3206,7 +3204,7 @@ build_pertrans_for_aggref(AggStatePerTrans pertrans,
naggs = aggstate->numaggs; naggs = aggstate->numaggs;
pertrans->aggfilter = ExecInitExpr(aggref->aggfilter, pertrans->aggfilter = ExecInitExpr(aggref->aggfilter,
(PlanState *) aggstate); (PlanState *) aggstate);
pertrans->aggdirectargs = (List *) ExecInitExpr((Expr *) aggref->aggdirectargs, pertrans->aggdirectargs = ExecInitExprList(aggref->aggdirectargs,
(PlanState *) aggstate); (PlanState *) aggstate);
/* /*
......
...@@ -319,7 +319,7 @@ BitmapHeapNext(BitmapHeapScanState *node) ...@@ -319,7 +319,7 @@ BitmapHeapNext(BitmapHeapScanState *node)
econtext->ecxt_scantuple = slot; econtext->ecxt_scantuple = slot;
ResetExprContext(econtext); ResetExprContext(econtext);
if (!ExecQual(node->bitmapqualorig, econtext, false)) if (!ExecQual(node->bitmapqualorig, econtext))
{ {
/* Fails recheck, so drop it and loop back for another */ /* Fails recheck, so drop it and loop back for another */
InstrCountFiltered2(node, 1); InstrCountFiltered2(node, 1);
...@@ -654,7 +654,7 @@ BitmapHeapRecheck(BitmapHeapScanState *node, TupleTableSlot *slot) ...@@ -654,7 +654,7 @@ BitmapHeapRecheck(BitmapHeapScanState *node, TupleTableSlot *slot)
ResetExprContext(econtext); ResetExprContext(econtext);
return ExecQual(node->bitmapqualorig, econtext, false); return ExecQual(node->bitmapqualorig, econtext);
} }
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
...@@ -837,15 +837,10 @@ ExecInitBitmapHeapScan(BitmapHeapScan *node, EState *estate, int eflags) ...@@ -837,15 +837,10 @@ ExecInitBitmapHeapScan(BitmapHeapScan *node, EState *estate, int eflags)
/* /*
* initialize child expressions * initialize child expressions
*/ */
scanstate->ss.ps.targetlist = (List *) scanstate->ss.ps.qual =
ExecInitExpr((Expr *) node->scan.plan.targetlist, ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
(PlanState *) scanstate); scanstate->bitmapqualorig =
scanstate->ss.ps.qual = (List *) ExecInitQual(node->bitmapqualorig, (PlanState *) scanstate);
ExecInitExpr((Expr *) node->scan.plan.qual,
(PlanState *) scanstate);
scanstate->bitmapqualorig = (List *)
ExecInitExpr((Expr *) node->bitmapqualorig,
(PlanState *) scanstate);
/* /*
* tuple table initialization * tuple table initialization
......
...@@ -242,12 +242,8 @@ ExecInitCteScan(CteScan *node, EState *estate, int eflags) ...@@ -242,12 +242,8 @@ ExecInitCteScan(CteScan *node, EState *estate, int eflags)
/* /*
* initialize child expressions * initialize child expressions
*/ */
scanstate->ss.ps.targetlist = (List *) scanstate->ss.ps.qual =
ExecInitExpr((Expr *) node->scan.plan.targetlist, ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
(PlanState *) scanstate);
scanstate->ss.ps.qual = (List *)
ExecInitExpr((Expr *) node->scan.plan.qual,
(PlanState *) scanstate);
/* /*
* tuple table initialization * tuple table initialization
......
...@@ -49,12 +49,8 @@ ExecInitCustomScan(CustomScan *cscan, EState *estate, int eflags) ...@@ -49,12 +49,8 @@ ExecInitCustomScan(CustomScan *cscan, EState *estate, int eflags)
ExecAssignExprContext(estate, &css->ss.ps); ExecAssignExprContext(estate, &css->ss.ps);
/* initialize child expressions */ /* initialize child expressions */
css->ss.ps.targetlist = (List *) css->ss.ps.qual =
ExecInitExpr((Expr *) cscan->scan.plan.targetlist, ExecInitQual(cscan->scan.plan.qual, (PlanState *) css);
(PlanState *) css);
css->ss.ps.qual = (List *)
ExecInitExpr((Expr *) cscan->scan.plan.qual,
(PlanState *) css);
/* tuple table initialization */ /* tuple table initialization */
ExecInitScanTupleSlot(estate, &css->ss); ExecInitScanTupleSlot(estate, &css->ss);
......
...@@ -101,7 +101,7 @@ ForeignRecheck(ForeignScanState *node, TupleTableSlot *slot) ...@@ -101,7 +101,7 @@ ForeignRecheck(ForeignScanState *node, TupleTableSlot *slot)
!fdwroutine->RecheckForeignScan(node, slot)) !fdwroutine->RecheckForeignScan(node, slot))
return false; return false;
return ExecQual(node->fdw_recheck_quals, econtext, false); return ExecQual(node->fdw_recheck_quals, econtext);
} }
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
...@@ -155,15 +155,10 @@ ExecInitForeignScan(ForeignScan *node, EState *estate, int eflags) ...@@ -155,15 +155,10 @@ ExecInitForeignScan(ForeignScan *node, EState *estate, int eflags)
/* /*
* initialize child expressions * initialize child expressions
*/ */
scanstate->ss.ps.targetlist = (List *) scanstate->ss.ps.qual =
ExecInitExpr((Expr *) node->scan.plan.targetlist, ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
(PlanState *) scanstate); scanstate->fdw_recheck_quals =
scanstate->ss.ps.qual = (List *) ExecInitQual(node->fdw_recheck_quals, (PlanState *) scanstate);
ExecInitExpr((Expr *) node->scan.plan.qual,
(PlanState *) scanstate);
scanstate->fdw_recheck_quals = (List *)
ExecInitExpr((Expr *) node->fdw_recheck_quals,
(PlanState *) scanstate);
/* /*
* tuple table initialization * tuple table initialization
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
*/ */
typedef struct FunctionScanPerFuncState typedef struct FunctionScanPerFuncState
{ {
ExprState *funcexpr; /* state of the expression being evaluated */ SetExprState *setexpr; /* state of the expression being evaluated */
TupleDesc tupdesc; /* desc of the function result type */ TupleDesc tupdesc; /* desc of the function result type */
int colcount; /* expected number of result columns */ int colcount; /* expected number of result columns */
Tuplestorestate *tstore; /* holds the function result set */ Tuplestorestate *tstore; /* holds the function result set */
...@@ -92,7 +92,7 @@ FunctionNext(FunctionScanState *node) ...@@ -92,7 +92,7 @@ FunctionNext(FunctionScanState *node)
if (tstore == NULL) if (tstore == NULL)
{ {
node->funcstates[0].tstore = tstore = node->funcstates[0].tstore = tstore =
ExecMakeTableFunctionResult(node->funcstates[0].funcexpr, ExecMakeTableFunctionResult(node->funcstates[0].setexpr,
node->ss.ps.ps_ExprContext, node->ss.ps.ps_ExprContext,
node->argcontext, node->argcontext,
node->funcstates[0].tupdesc, node->funcstates[0].tupdesc,
...@@ -151,7 +151,7 @@ FunctionNext(FunctionScanState *node) ...@@ -151,7 +151,7 @@ FunctionNext(FunctionScanState *node)
if (fs->tstore == NULL) if (fs->tstore == NULL)
{ {
fs->tstore = fs->tstore =
ExecMakeTableFunctionResult(fs->funcexpr, ExecMakeTableFunctionResult(fs->setexpr,
node->ss.ps.ps_ExprContext, node->ss.ps.ps_ExprContext,
node->argcontext, node->argcontext,
fs->tupdesc, fs->tupdesc,
...@@ -340,12 +340,8 @@ ExecInitFunctionScan(FunctionScan *node, EState *estate, int eflags) ...@@ -340,12 +340,8 @@ ExecInitFunctionScan(FunctionScan *node, EState *estate, int eflags)
/* /*
* initialize child expressions * initialize child expressions
*/ */
scanstate->ss.ps.targetlist = (List *) scanstate->ss.ps.qual =
ExecInitExpr((Expr *) node->scan.plan.targetlist, ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
(PlanState *) scanstate);
scanstate->ss.ps.qual = (List *)
ExecInitExpr((Expr *) node->scan.plan.qual,
(PlanState *) scanstate);
scanstate->funcstates = palloc(nfuncs * sizeof(FunctionScanPerFuncState)); scanstate->funcstates = palloc(nfuncs * sizeof(FunctionScanPerFuncState));
...@@ -361,7 +357,10 @@ ExecInitFunctionScan(FunctionScan *node, EState *estate, int eflags) ...@@ -361,7 +357,10 @@ ExecInitFunctionScan(FunctionScan *node, EState *estate, int eflags)
Oid funcrettype; Oid funcrettype;
TupleDesc tupdesc; TupleDesc tupdesc;
fs->funcexpr = ExecInitExpr((Expr *) funcexpr, (PlanState *) scanstate); fs->setexpr =
ExecInitTableFunctionResult((Expr *) funcexpr,
scanstate->ss.ps.ps_ExprContext,
&scanstate->ss.ps);
/* /*
* Don't allocate the tuplestores; the actual calls to the functions * Don't allocate the tuplestores; the actual calls to the functions
......
...@@ -81,12 +81,8 @@ ExecInitGather(Gather *node, EState *estate, int eflags) ...@@ -81,12 +81,8 @@ ExecInitGather(Gather *node, EState *estate, int eflags)
/* /*
* initialize child expressions * initialize child expressions
*/ */
gatherstate->ps.targetlist = (List *) gatherstate->ps.qual =
ExecInitExpr((Expr *) node->plan.targetlist, ExecInitQual(node->plan.qual, (PlanState *) gatherstate);
(PlanState *) gatherstate);
gatherstate->ps.qual = (List *)
ExecInitExpr((Expr *) node->plan.qual,
(PlanState *) gatherstate);
/* /*
* tuple table initialization * tuple table initialization
......
...@@ -86,12 +86,8 @@ ExecInitGatherMerge(GatherMerge *node, EState *estate, int eflags) ...@@ -86,12 +86,8 @@ ExecInitGatherMerge(GatherMerge *node, EState *estate, int eflags)
/* /*
* initialize child expressions * initialize child expressions
*/ */
gm_state->ps.targetlist = (List *) gm_state->ps.qual =
ExecInitExpr((Expr *) node->plan.targetlist, ExecInitQual(node->plan.qual, &gm_state->ps);
(PlanState *) gm_state);
gm_state->ps.qual = (List *)
ExecInitExpr((Expr *) node->plan.qual,
(PlanState *) gm_state);
/* /*
* tuple table initialization * tuple table initialization
......
...@@ -85,7 +85,7 @@ ExecGroup(GroupState *node) ...@@ -85,7 +85,7 @@ ExecGroup(GroupState *node)
* Check the qual (HAVING clause); if the group does not match, ignore * Check the qual (HAVING clause); if the group does not match, ignore
* it and fall into scan loop. * it and fall into scan loop.
*/ */
if (ExecQual(node->ss.ps.qual, econtext, false)) if (ExecQual(node->ss.ps.qual, econtext))
{ {
/* /*
* Form and return a projection tuple using the first input tuple. * Form and return a projection tuple using the first input tuple.
...@@ -139,7 +139,7 @@ ExecGroup(GroupState *node) ...@@ -139,7 +139,7 @@ ExecGroup(GroupState *node)
* Check the qual (HAVING clause); if the group does not match, ignore * Check the qual (HAVING clause); if the group does not match, ignore
* it and loop back to scan the rest of the group. * it and loop back to scan the rest of the group.
*/ */
if (ExecQual(node->ss.ps.qual, econtext, false)) if (ExecQual(node->ss.ps.qual, econtext))
{ {
/* /*
* Form and return a projection tuple using the first input tuple. * Form and return a projection tuple using the first input tuple.
...@@ -188,12 +188,8 @@ ExecInitGroup(Group *node, EState *estate, int eflags) ...@@ -188,12 +188,8 @@ ExecInitGroup(Group *node, EState *estate, int eflags)
/* /*
* initialize child expressions * initialize child expressions
*/ */
grpstate->ss.ps.targetlist = (List *) grpstate->ss.ps.qual =
ExecInitExpr((Expr *) node->plan.targetlist, ExecInitQual(node->plan.qual, (PlanState *) grpstate);
(PlanState *) grpstate);
grpstate->ss.ps.qual = (List *)
ExecInitExpr((Expr *) node->plan.qual,
(PlanState *) grpstate);
/* /*
* initialize child nodes * initialize child nodes
......
...@@ -190,12 +190,8 @@ ExecInitHash(Hash *node, EState *estate, int eflags) ...@@ -190,12 +190,8 @@ ExecInitHash(Hash *node, EState *estate, int eflags)
/* /*
* initialize child expressions * initialize child expressions
*/ */
hashstate->ps.targetlist = (List *) hashstate->ps.qual =
ExecInitExpr((Expr *) node->plan.targetlist, ExecInitQual(node->plan.qual, (PlanState *) hashstate);
(PlanState *) hashstate);
hashstate->ps.qual = (List *)
ExecInitExpr((Expr *) node->plan.qual,
(PlanState *) hashstate);
/* /*
* initialize child nodes * initialize child nodes
...@@ -1063,7 +1059,7 @@ bool ...@@ -1063,7 +1059,7 @@ bool
ExecScanHashBucket(HashJoinState *hjstate, ExecScanHashBucket(HashJoinState *hjstate,
ExprContext *econtext) ExprContext *econtext)
{ {
List *hjclauses = hjstate->hashclauses; ExprState *hjclauses = hjstate->hashclauses;
HashJoinTable hashtable = hjstate->hj_HashTable; HashJoinTable hashtable = hjstate->hj_HashTable;
HashJoinTuple hashTuple = hjstate->hj_CurTuple; HashJoinTuple hashTuple = hjstate->hj_CurTuple;
uint32 hashvalue = hjstate->hj_CurHashValue; uint32 hashvalue = hjstate->hj_CurHashValue;
...@@ -1097,7 +1093,7 @@ ExecScanHashBucket(HashJoinState *hjstate, ...@@ -1097,7 +1093,7 @@ ExecScanHashBucket(HashJoinState *hjstate,
/* reset temp memory each time to avoid leaks from qual expr */ /* reset temp memory each time to avoid leaks from qual expr */
ResetExprContext(econtext); ResetExprContext(econtext);
if (ExecQual(hjclauses, econtext, false)) if (ExecQual(hjclauses, econtext))
{ {
hjstate->hj_CurTuple = hashTuple; hjstate->hj_CurTuple = hashTuple;
return true; return true;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment