diff options
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++; |