diff options
author | Andres Freund <andres@anarazel.de> | 2018-02-15 21:55:31 -0800 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2018-02-16 14:38:13 -0800 |
commit | bf6c614a2f2c58312b3be34a47e7fb7362e07bcb (patch) | |
tree | bbc91aed13afc3ef3b71bada700322197fe40b69 /src/backend/executor/nodeWindowAgg.c | |
parent | ad9a274778d2d88c46b90309212b92ee7fdf9afe (diff) | |
download | postgresql-bf6c614a2f2c58312b3be34a47e7fb7362e07bcb.tar.gz postgresql-bf6c614a2f2c58312b3be34a47e7fb7362e07bcb.zip |
Do execGrouping.c via expression eval machinery, take two.
This has a performance benefit on own, although not hugely so. The
primary benefit is that it will allow for to JIT tuple deforming and
comparator invocations.
Large parts of this were previously committed (773aec7aa), but the
commit contained an omission around cross-type comparisons and was
thus reverted.
Author: Andres Freund
Discussion: https://postgr.es/m/20171129080934.amqqkke2zjtekd4t@alap3.anarazel.de
Diffstat (limited to 'src/backend/executor/nodeWindowAgg.c')
-rw-r--r-- | src/backend/executor/nodeWindowAgg.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/backend/executor/nodeWindowAgg.c b/src/backend/executor/nodeWindowAgg.c index f6412576f40..1c807a82922 100644 --- a/src/backend/executor/nodeWindowAgg.c +++ b/src/backend/executor/nodeWindowAgg.c @@ -1272,12 +1272,13 @@ spool_tuples(WindowAggState *winstate, int64 pos) if (node->partNumCols > 0) { + ExprContext *econtext = winstate->tmpcontext; + + econtext->ecxt_innertuple = winstate->first_part_slot; + econtext->ecxt_outertuple = outerslot; + /* Check if this tuple still belongs to the current partition */ - if (!execTuplesMatch(winstate->first_part_slot, - outerslot, - node->partNumCols, node->partColIdx, - winstate->partEqfunctions, - winstate->tmpcontext->ecxt_per_tuple_memory)) + if (!ExecQualAndReset(winstate->partEqfunction, econtext)) { /* * end of partition; copy the tuple for the next cycle. @@ -2245,6 +2246,7 @@ ExecInitWindowAgg(WindowAgg *node, EState *estate, int eflags) wfuncno, numaggs, aggno; + TupleDesc scanDesc; ListCell *l; /* check for unsupported flags */ @@ -2327,6 +2329,7 @@ ExecInitWindowAgg(WindowAgg *node, EState *estate, int eflags) * store in the tuplestore and use in all our working slots). */ ExecAssignScanTypeFromOuterPlan(&winstate->ss); + scanDesc = winstate->ss.ss_ScanTupleSlot->tts_tupleDescriptor; ExecSetSlotDescriptor(winstate->first_part_slot, winstate->ss.ss_ScanTupleSlot->tts_tupleDescriptor); @@ -2351,11 +2354,20 @@ ExecInitWindowAgg(WindowAgg *node, EState *estate, int eflags) /* Set up data for comparing tuples */ if (node->partNumCols > 0) - winstate->partEqfunctions = execTuplesMatchPrepare(node->partNumCols, - node->partOperators); + winstate->partEqfunction = + execTuplesMatchPrepare(scanDesc, + node->partNumCols, + node->partColIdx, + node->partOperators, + &winstate->ss.ps); + if (node->ordNumCols > 0) - winstate->ordEqfunctions = execTuplesMatchPrepare(node->ordNumCols, - node->ordOperators); + winstate->ordEqfunction = + execTuplesMatchPrepare(scanDesc, + node->ordNumCols, + node->ordColIdx, + node->ordOperators, + &winstate->ss.ps); /* * WindowAgg nodes use aggvalues and aggnulls as well as Agg nodes. @@ -2879,15 +2891,15 @@ are_peers(WindowAggState *winstate, TupleTableSlot *slot1, TupleTableSlot *slot2) { WindowAgg *node = (WindowAgg *) winstate->ss.ps.plan; + ExprContext *econtext = winstate->tmpcontext; /* If no ORDER BY, all rows are peers with each other */ if (node->ordNumCols == 0) return true; - return execTuplesMatch(slot1, slot2, - node->ordNumCols, node->ordColIdx, - winstate->ordEqfunctions, - winstate->tmpcontext->ecxt_per_tuple_memory); + econtext->ecxt_outertuple = slot1; + econtext->ecxt_innertuple = slot2; + return ExecQualAndReset(winstate->ordEqfunction, econtext); } /* |