diff options
author | Andres Freund <andres@anarazel.de> | 2017-04-06 14:48:59 -0700 |
---|---|---|
committer | Andres Freund <andres@anarazel.de> | 2017-04-06 14:48:59 -0700 |
commit | fa117ee40330db401da776e7b003f047098a7d4c (patch) | |
tree | d145a528de8e9c8d085a300a026f33cd6ff8e55b /src/backend/executor/nodeSort.c | |
parent | af8a94d18d70ca226a12057ad4b3d17f27d8ff13 (diff) | |
download | postgresql-fa117ee40330db401da776e7b003f047098a7d4c.tar.gz postgresql-fa117ee40330db401da776e7b003f047098a7d4c.zip |
Allow avoiding tuple copy within tuplesort_gettupleslot().
Add a "copy" argument to make it optional to receive a copy of caller
tuple that is safe to use following a subsequent manipulating of
tuplesort's state. This is a performance optimization. Most existing
tuplesort_gettupleslot() callers are made to opt out of copying.
Existing callers that happen to rely on the validity of tuple memory
beyond subsequent manipulations of the tuplesort request their own
copy.
This brings tuplesort_gettupleslot() in line with
tuplestore_gettupleslot(). In the future, a "copy"
tuplesort_getdatum() argument may be added, that similarly allows
callers to opt out of receiving their own copy of tuple.
In passing, clarify assumptions that callers of other tuplesort fetch
routines may make about tuple memory validity, per gripe from Tom
Lane.
Author: Peter Geoghegan
Discussion: CAM3SWZQWZZ_N=DmmL7tKy_OUjGH_5mN=N=A6h7kHyyDvEhg2DA@mail.gmail.com
Diffstat (limited to 'src/backend/executor/nodeSort.c')
-rw-r--r-- | src/backend/executor/nodeSort.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/backend/executor/nodeSort.c b/src/backend/executor/nodeSort.c index 591a31aa6ab..924b458df87 100644 --- a/src/backend/executor/nodeSort.c +++ b/src/backend/executor/nodeSort.c @@ -132,12 +132,13 @@ ExecSort(SortState *node) /* * Get the first or next tuple from tuplesort. Returns NULL if no more - * tuples. + * tuples. Note that we only rely on slot tuple remaining valid until the + * next fetch from the tuplesort. */ slot = node->ss.ps.ps_ResultTupleSlot; (void) tuplesort_gettupleslot(tuplesortstate, ScanDirectionIsForward(dir), - slot, NULL); + false, slot, NULL); return slot; } |