diff options
author | Andres Freund <andres@anarazel.de> | 2018-02-15 22:39:18 -0800 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2018-02-15 22:39:18 -0800 |
commit | 2a41507dab0f293ff241fe8ae326065998668af8 (patch) | |
tree | 30fe1118750ea9c2805bd38a7485390f4d381715 /src/backend/utils/adt | |
parent | 773aec7aa98abd38d6d9435913bb8e14e392c274 (diff) | |
download | postgresql-2a41507dab0f293ff241fe8ae326065998668af8.tar.gz postgresql-2a41507dab0f293ff241fe8ae326065998668af8.zip |
Revert "Do execGrouping.c via expression eval machinery."
This reverts commit 773aec7aa98abd38d6d9435913bb8e14e392c274.
There's an unresolved issue in the reverted commit: It only creates
one comparator function, but in for the nodeSubplan.c case we need
more (c.f. FindTupleHashEntry vs LookupTupleHashEntry calls in
nodeSubplan.c).
This isn't too difficult to fix, but it's not entirely trivial
either. The fact that the issue only causes breakage on 32bit systems
shows that the current test coverage isn't that great. To avoid
turning half the buildfarm red till those two issues are addressed,
revert.
Diffstat (limited to 'src/backend/utils/adt')
-rw-r--r-- | src/backend/utils/adt/orderedsetaggs.c | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/src/backend/utils/adt/orderedsetaggs.c b/src/backend/utils/adt/orderedsetaggs.c index 50b34fcbc68..63d9c670274 100644 --- a/src/backend/utils/adt/orderedsetaggs.c +++ b/src/backend/utils/adt/orderedsetaggs.c @@ -27,7 +27,6 @@ #include "utils/array.h" #include "utils/builtins.h" #include "utils/lsyscache.h" -#include "utils/memutils.h" #include "utils/timestamp.h" #include "utils/tuplesort.h" @@ -55,8 +54,6 @@ typedef struct OSAPerQueryState Aggref *aggref; /* Memory context containing this struct and other per-query data: */ MemoryContext qcontext; - /* Context for expression evaluation */ - ExprContext *econtext; /* Do we expect multiple final-function calls within one group? */ bool rescan_needed; @@ -74,7 +71,7 @@ typedef struct OSAPerQueryState Oid *sortCollations; bool *sortNullsFirsts; /* Equality operator call info, created only if needed: */ - ExprState *compareTuple; + FmgrInfo *equalfns; /* These fields are used only when accumulating datums: */ @@ -1290,8 +1287,6 @@ hypothetical_cume_dist_final(PG_FUNCTION_ARGS) Datum hypothetical_dense_rank_final(PG_FUNCTION_ARGS) { - ExprContext *econtext; - ExprState *compareTuple; int nargs = PG_NARGS() - 1; int64 rank = 1; int64 duplicate_count = 0; @@ -1299,9 +1294,12 @@ hypothetical_dense_rank_final(PG_FUNCTION_ARGS) int numDistinctCols; Datum abbrevVal = (Datum) 0; Datum abbrevOld = (Datum) 0; + AttrNumber *sortColIdx; + FmgrInfo *equalfns; TupleTableSlot *slot; TupleTableSlot *extraslot; TupleTableSlot *slot2; + MemoryContext tmpcontext; int i; Assert(AggCheckCallContext(fcinfo, NULL) == AGG_CONTEXT_AGGREGATE); @@ -1311,9 +1309,6 @@ hypothetical_dense_rank_final(PG_FUNCTION_ARGS) PG_RETURN_INT64(rank); osastate = (OSAPerGroupState *) PG_GETARG_POINTER(0); - econtext = osastate->qstate->econtext; - if (!econtext) - osastate->qstate->econtext = econtext = CreateStandaloneExprContext(); /* Adjust nargs to be the number of direct (or aggregated) args */ if (nargs % 2 != 0) @@ -1328,22 +1323,26 @@ hypothetical_dense_rank_final(PG_FUNCTION_ARGS) */ numDistinctCols = osastate->qstate->numSortCols - 1; - /* Build tuple comparator, if we didn't already */ - compareTuple = osastate->qstate->compareTuple; - if (compareTuple == NULL) + /* Look up the equality function(s), if we didn't already */ + equalfns = osastate->qstate->equalfns; + if (equalfns == NULL) { - AttrNumber *sortColIdx = osastate->qstate->sortColIdx; - MemoryContext oldContext; - - oldContext = MemoryContextSwitchTo(osastate->qstate->qcontext); - compareTuple = execTuplesMatchPrepare(osastate->qstate->tupdesc, - numDistinctCols, - sortColIdx, - osastate->qstate->eqOperators, - NULL); - MemoryContextSwitchTo(oldContext); - osastate->qstate->compareTuple = compareTuple; + MemoryContext qcontext = osastate->qstate->qcontext; + + equalfns = (FmgrInfo *) + MemoryContextAlloc(qcontext, numDistinctCols * sizeof(FmgrInfo)); + for (i = 0; i < numDistinctCols; i++) + { + fmgr_info_cxt(get_opcode(osastate->qstate->eqOperators[i]), + &equalfns[i], + qcontext); + } + osastate->qstate->equalfns = equalfns; } + sortColIdx = osastate->qstate->sortColIdx; + + /* Get short-term context we can use for execTuplesMatch */ + tmpcontext = AggGetTempMemoryContext(fcinfo); /* because we need a hypothetical row, we can't share transition state */ Assert(!osastate->sort_done); @@ -1386,18 +1385,19 @@ hypothetical_dense_rank_final(PG_FUNCTION_ARGS) break; /* count non-distinct tuples */ - econtext->ecxt_outertuple = slot; - econtext->ecxt_innertuple = slot2; - if (!TupIsNull(slot2) && abbrevVal == abbrevOld && - ExecQualAndReset(compareTuple, econtext)) + execTuplesMatch(slot, slot2, + numDistinctCols, + sortColIdx, + equalfns, + tmpcontext)) duplicate_count++; tmpslot = slot2; slot2 = slot; slot = tmpslot; - /* avoid ExecQual() calls by reusing abbreviated keys */ + /* avoid execTuplesMatch() calls by reusing abbreviated keys */ abbrevOld = abbrevVal; rank++; |