aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeIncrementalSort.c
diff options
context:
space:
mode:
authorDavid Rowley <drowley@postgresql.org>2022-04-04 22:52:35 +1200
committerDavid Rowley <drowley@postgresql.org>2022-04-04 22:52:35 +1200
commit40af10b571bdabbab06839d090083c9f9c2091d2 (patch)
tree8097ad818ef6981f466e979c88f3edcb7002015f /src/backend/executor/nodeIncrementalSort.c
parent77bae396df3f6f883f58f1877b7c08eb3ebb6b63 (diff)
downloadpostgresql-40af10b571bdabbab06839d090083c9f9c2091d2.tar.gz
postgresql-40af10b571bdabbab06839d090083c9f9c2091d2.zip
Use Generation memory contexts to store tuples in sorts
The general usage pattern when we store tuples in tuplesort.c is that we store a series of tuples one by one then either perform a sort or spill them to disk. In the common case, there is no pfreeing of already stored tuples. For the common case since we do not individually pfree tuples, we have very little need for aset.c memory allocation behavior which maintains freelists and always rounds allocation sizes up to the next power of 2 size. Here we conditionally use generation.c contexts for storing tuples in tuplesort.c when the sort will never be bounded. Unfortunately, the memory context to store tuples is already created by the time any calls would be made to tuplesort_set_bound(), so here we add a new sort option that allows callers to specify if they're going to need a bounded sort or not. We'll use a standard aset.c allocator when this sort option is not set. Extension authors must ensure that the TUPLESORT_ALLOWBOUNDED flag is used when calling tuplesort_begin_* for any sorts that make a call to tuplesort_set_bound(). Author: David Rowley Reviewed-by: Andy Fan Discussion: https://postgr.es/m/CAApHDvoH4ASzsAOyHcxkuY01Qf++8JJ0paw+03dk+W25tQEcNQ@mail.gmail.com
Diffstat (limited to 'src/backend/executor/nodeIncrementalSort.c')
-rw-r--r--src/backend/executor/nodeIncrementalSort.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/backend/executor/nodeIncrementalSort.c b/src/backend/executor/nodeIncrementalSort.c
index 4f50bc845da..d1b97d46bc0 100644
--- a/src/backend/executor/nodeIncrementalSort.c
+++ b/src/backend/executor/nodeIncrementalSort.c
@@ -315,7 +315,7 @@ switchToPresortedPrefixMode(PlanState *pstate)
&(plannode->sort.nullsFirst[nPresortedCols]),
work_mem,
NULL,
- TUPLESORT_NONE);
+ node->bounded ? TUPLESORT_ALLOWBOUNDED : TUPLESORT_NONE);
node->prefixsort_state = prefixsort_state;
}
else
@@ -616,6 +616,8 @@ ExecIncrementalSort(PlanState *pstate)
plannode->sort.nullsFirst,
work_mem,
NULL,
+ node->bounded ?
+ TUPLESORT_ALLOWBOUNDED :
TUPLESORT_NONE);
node->fullsort_state = fullsort_state;
}