]> granicus.if.org Git - postgresql/commitdiff
Introduce ExecQualAndReset() helper.
authorAndres Freund <andres@anarazel.de>
Mon, 29 Jan 2018 20:16:53 +0000 (12:16 -0800)
committerAndres Freund <andres@anarazel.de>
Mon, 29 Jan 2018 20:19:12 +0000 (12:19 -0800)
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

src/backend/executor/nodeBitmapHeapscan.c
src/backend/executor/nodeHash.c
src/backend/executor/nodeIndexonlyscan.c
src/backend/executor/nodeIndexscan.c
src/include/executor/executor.h

index 7ba1db7d7ec08d8b67066d45dddd4c8718e7ccfe..fa65d4efbe7939c666f3ea68da35df74a12757f4 100644 (file)
@@ -352,9 +352,7 @@ BitmapHeapNext(BitmapHeapScanState *node)
                        if (tbmres->recheck)
                        {
                                econtext->ecxt_scantuple = slot;
-                               ResetExprContext(econtext);
-
-                               if (!ExecQual(node->bitmapqualorig, econtext))
+                               if (!ExecQualAndReset(node->bitmapqualorig, econtext))
                                {
                                        /* Fails recheck, so drop it and loop back for another */
                                        InstrCountFiltered2(node, 1);
@@ -717,10 +715,7 @@ BitmapHeapRecheck(BitmapHeapScanState *node, TupleTableSlot *slot)
 
        /* Does the tuple meet the original qual conditions? */
        econtext->ecxt_scantuple = slot;
-
-       ResetExprContext(econtext);
-
-       return ExecQual(node->bitmapqualorig, econtext);
+       return ExecQualAndReset(node->bitmapqualorig, econtext);
 }
 
 /* ----------------------------------------------------------------
index a9149ef81ced38ab33c6a9d03b8971a7921eb31e..c26b8ea44e33d7079ea4581bf0261889cc90b63e 100644 (file)
@@ -1942,10 +1942,7 @@ ExecScanHashBucket(HashJoinState *hjstate,
                                                                                         false);        /* do not pfree */
                        econtext->ecxt_innertuple = inntuple;
 
-                       /* reset temp memory each time to avoid leaks from qual expr */
-                       ResetExprContext(econtext);
-
-                       if (ExecQual(hjclauses, econtext))
+                       if (ExecQualAndReset(hjclauses, econtext))
                        {
                                hjstate->hj_CurTuple = hashTuple;
                                return true;
@@ -2002,10 +1999,7 @@ ExecParallelScanHashBucket(HashJoinState *hjstate,
                                                                                         false);        /* do not pfree */
                        econtext->ecxt_innertuple = inntuple;
 
-                       /* reset temp memory each time to avoid leaks from qual expr */
-                       ResetExprContext(econtext);
-
-                       if (ExecQual(hjclauses, econtext))
+                       if (ExecQualAndReset(hjclauses, econtext))
                        {
                                hjstate->hj_CurTuple = hashTuple;
                                return true;
index f61b3abf3262a4a15579b0cc13d917e504cc1de4..8ffcc52bea5841b653024f709ce538ac13b0478a 100644 (file)
@@ -214,8 +214,7 @@ IndexOnlyNext(IndexOnlyScanState *node)
                if (scandesc->xs_recheck)
                {
                        econtext->ecxt_scantuple = slot;
-                       ResetExprContext(econtext);
-                       if (!ExecQual(node->indexqual, econtext))
+                       if (!ExecQualAndReset(node->indexqual, econtext))
                        {
                                /* Fails recheck, so drop it and loop back for another */
                                InstrCountFiltered2(node, 1);
index eed69a0c665ad55b8df7c9e67c85c37c2c3a2e27..b8b961add4c6762055eba33001a3b79f8b580a32 100644 (file)
@@ -152,8 +152,7 @@ IndexNext(IndexScanState *node)
                if (scandesc->xs_recheck)
                {
                        econtext->ecxt_scantuple = slot;
-                       ResetExprContext(econtext);
-                       if (!ExecQual(node->indexqualorig, econtext))
+                       if (!ExecQualAndReset(node->indexqualorig, econtext))
                        {
                                /* Fails recheck, so drop it and loop back for another */
                                InstrCountFiltered2(node, 1);
@@ -300,8 +299,7 @@ next_indextuple:
                if (scandesc->xs_recheck)
                {
                        econtext->ecxt_scantuple = slot;
-                       ResetExprContext(econtext);
-                       if (!ExecQual(node->indexqualorig, econtext))
+                       if (!ExecQualAndReset(node->indexqualorig, econtext))
                        {
                                /* Fails recheck, so drop it and loop back for another */
                                InstrCountFiltered2(node, 1);
@@ -420,10 +418,7 @@ IndexRecheck(IndexScanState *node, TupleTableSlot *slot)
 
        /* Does the tuple meet the indexqual condition? */
        econtext->ecxt_scantuple = slot;
-
-       ResetExprContext(econtext);
-
-       return ExecQual(node->indexqualorig, econtext);
+       return ExecQualAndReset(node->indexqualorig, econtext);
 }
 
 
index 6545a80222344d8ee62d3928d0a7d46f26bef59d..1d824eff361e77d2c7f900eb945995ec25ab51ed 100644 (file)
@@ -17,6 +17,7 @@
 #include "catalog/partition.h"
 #include "executor/execdesc.h"
 #include "nodes/parsenodes.h"
+#include "utils/memutils.h"
 
 
 /*
@@ -381,6 +382,22 @@ ExecQual(ExprState *state, ExprContext *econtext)
 }
 #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);
 
 /*