Introduce ExecQualAndReset() helper.
It's a common task to evaluate a qual and reset the corresponding expression context. Currently that requires storing the result of the qual eval, resetting the context, and then reacting on the result. As that's awkward several places only reset the context next time through a node. That's not great, so introduce a helper that evaluates and resets. It's a bit ugly that it currently uses MemoryContextReset() instead of ResetExprContext(), but that seems easier than reordering all of executor.h. Author: Andres Freund Discussion: https://postgr.es/m/20180109222544.f7loxrunqh3xjl5f@alap3.anarazel.de
This commit is contained in:
parent
97d4445a03
commit
c12693d8f3
@ -352,9 +352,7 @@ BitmapHeapNext(BitmapHeapScanState *node)
|
|||||||
if (tbmres->recheck)
|
if (tbmres->recheck)
|
||||||
{
|
{
|
||||||
econtext->ecxt_scantuple = slot;
|
econtext->ecxt_scantuple = slot;
|
||||||
ResetExprContext(econtext);
|
if (!ExecQualAndReset(node->bitmapqualorig, econtext))
|
||||||
|
|
||||||
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);
|
||||||
@ -717,10 +715,7 @@ BitmapHeapRecheck(BitmapHeapScanState *node, TupleTableSlot *slot)
|
|||||||
|
|
||||||
/* Does the tuple meet the original qual conditions? */
|
/* Does the tuple meet the original qual conditions? */
|
||||||
econtext->ecxt_scantuple = slot;
|
econtext->ecxt_scantuple = slot;
|
||||||
|
return ExecQualAndReset(node->bitmapqualorig, econtext);
|
||||||
ResetExprContext(econtext);
|
|
||||||
|
|
||||||
return ExecQual(node->bitmapqualorig, econtext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------
|
/* ----------------------------------------------------------------
|
||||||
|
@ -1942,10 +1942,7 @@ ExecScanHashBucket(HashJoinState *hjstate,
|
|||||||
false); /* do not pfree */
|
false); /* do not pfree */
|
||||||
econtext->ecxt_innertuple = inntuple;
|
econtext->ecxt_innertuple = inntuple;
|
||||||
|
|
||||||
/* reset temp memory each time to avoid leaks from qual expr */
|
if (ExecQualAndReset(hjclauses, econtext))
|
||||||
ResetExprContext(econtext);
|
|
||||||
|
|
||||||
if (ExecQual(hjclauses, econtext))
|
|
||||||
{
|
{
|
||||||
hjstate->hj_CurTuple = hashTuple;
|
hjstate->hj_CurTuple = hashTuple;
|
||||||
return true;
|
return true;
|
||||||
@ -2002,10 +1999,7 @@ ExecParallelScanHashBucket(HashJoinState *hjstate,
|
|||||||
false); /* do not pfree */
|
false); /* do not pfree */
|
||||||
econtext->ecxt_innertuple = inntuple;
|
econtext->ecxt_innertuple = inntuple;
|
||||||
|
|
||||||
/* reset temp memory each time to avoid leaks from qual expr */
|
if (ExecQualAndReset(hjclauses, econtext))
|
||||||
ResetExprContext(econtext);
|
|
||||||
|
|
||||||
if (ExecQual(hjclauses, econtext))
|
|
||||||
{
|
{
|
||||||
hjstate->hj_CurTuple = hashTuple;
|
hjstate->hj_CurTuple = hashTuple;
|
||||||
return true;
|
return true;
|
||||||
|
@ -214,8 +214,7 @@ IndexOnlyNext(IndexOnlyScanState *node)
|
|||||||
if (scandesc->xs_recheck)
|
if (scandesc->xs_recheck)
|
||||||
{
|
{
|
||||||
econtext->ecxt_scantuple = slot;
|
econtext->ecxt_scantuple = slot;
|
||||||
ResetExprContext(econtext);
|
if (!ExecQualAndReset(node->indexqual, econtext))
|
||||||
if (!ExecQual(node->indexqual, 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);
|
||||||
|
@ -152,8 +152,7 @@ IndexNext(IndexScanState *node)
|
|||||||
if (scandesc->xs_recheck)
|
if (scandesc->xs_recheck)
|
||||||
{
|
{
|
||||||
econtext->ecxt_scantuple = slot;
|
econtext->ecxt_scantuple = slot;
|
||||||
ResetExprContext(econtext);
|
if (!ExecQualAndReset(node->indexqualorig, econtext))
|
||||||
if (!ExecQual(node->indexqualorig, 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);
|
||||||
@ -300,8 +299,7 @@ next_indextuple:
|
|||||||
if (scandesc->xs_recheck)
|
if (scandesc->xs_recheck)
|
||||||
{
|
{
|
||||||
econtext->ecxt_scantuple = slot;
|
econtext->ecxt_scantuple = slot;
|
||||||
ResetExprContext(econtext);
|
if (!ExecQualAndReset(node->indexqualorig, econtext))
|
||||||
if (!ExecQual(node->indexqualorig, 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);
|
||||||
@ -420,10 +418,7 @@ IndexRecheck(IndexScanState *node, TupleTableSlot *slot)
|
|||||||
|
|
||||||
/* Does the tuple meet the indexqual condition? */
|
/* Does the tuple meet the indexqual condition? */
|
||||||
econtext->ecxt_scantuple = slot;
|
econtext->ecxt_scantuple = slot;
|
||||||
|
return ExecQualAndReset(node->indexqualorig, econtext);
|
||||||
ResetExprContext(econtext);
|
|
||||||
|
|
||||||
return ExecQual(node->indexqualorig, econtext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "catalog/partition.h"
|
#include "catalog/partition.h"
|
||||||
#include "executor/execdesc.h"
|
#include "executor/execdesc.h"
|
||||||
#include "nodes/parsenodes.h"
|
#include "nodes/parsenodes.h"
|
||||||
|
#include "utils/memutils.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -381,6 +382,22 @@ ExecQual(ExprState *state, ExprContext *econtext)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ExecQualAndReset() - evaluate qual with ExecQual() and reset expression
|
||||||
|
* context.
|
||||||
|
*/
|
||||||
|
#ifndef FRONTEND
|
||||||
|
static inline bool
|
||||||
|
ExecQualAndReset(ExprState *state, ExprContext *econtext)
|
||||||
|
{
|
||||||
|
bool ret = ExecQual(state, econtext);
|
||||||
|
|
||||||
|
/* inline ResetExprContext, to avoid ordering issue in this file */
|
||||||
|
MemoryContextReset(econtext->ecxt_per_tuple_memory);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
extern bool ExecCheck(ExprState *state, ExprContext *context);
|
extern bool ExecCheck(ExprState *state, ExprContext *context);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user