postgresql/src/backend
David Rowley 1083f94dac Be smarter about freeing tuples during tuplesorts
During dumptuples() the call to writetuple() would pfree any non-null
tuple.  This was quite wasteful as this happens just before we perform a
reset of the context which stores all of those tuples.

It seems to make sense to do a bit of a code refactor to make this work,
so here we just get rid of the writetuple function and adjust the WRITETUP
macro to call the state's writetup function.  The WRITETUP usage in
mergeonerun() always has state->slabAllocatorUsed == true, so writetuple()
would never free the tuple or do any memory accounting.  The only call
path that needs memory accounting done is in dumptuples(), so let's just
do it manually there.

In passing, let's get rid of the state->memtupcount-- code that counts the
memtupcount down to 0 one tuple at a time inside the loop.  That seems to
be a rather inefficient way to set memtupcount to 0, so let's just zero it
after the loop instead.

Author: David Rowley
Discussion: https://postgr.es/m/CAApHDvqZXoDCyrfCzZJR0-xH+7_q+GgitcQiYXUjRani7h4j8Q@mail.gmail.com
2022-09-01 11:08:10 +12:00
..
access Derive freeze cutoff from nextXID, not OldestXmin. 2022-08-31 11:37:35 -07:00
backup Remove obsolete comment 2022-08-26 10:44:50 +02:00
bootstrap Process session_preload_libraries within InitPostgres's transaction. 2022-07-25 10:27:43 -04:00
catalog Ensure that pg_auth_members.grantor is always valid. 2022-08-18 13:13:02 -04:00
commands Derive freeze cutoff from nextXID, not OldestXmin. 2022-08-31 11:37:35 -07:00
executor Doc: add comment about bug fixed in back branches as of 3f7323cbb. 2022-08-27 12:16:21 -04:00
foreign Create routine able to set single-call SRFs for Materialize mode 2022-03-07 10:26:29 +09:00
jit Improve performance of ORDER BY / DISTINCT aggregates 2022-08-02 23:11:45 +12:00
lib More -Wshadow=compatible-local warning fixes 2022-08-26 02:35:40 +12:00
libpq Remove configure probe for sockaddr_in6 and require AF_INET6. 2022-08-26 10:18:30 +12:00
main Fix outdated --help message for postgres -f 2022-08-15 13:36:36 +09:00
nodes Remove redundant spaces in _outA_Expr() output 2022-08-15 12:43:52 +02:00
optimizer More -Wshadow=compatible-local warning fixes 2022-08-26 02:35:40 +12:00
parser Allow grant-level control of role inheritance behavior. 2022-08-25 10:06:02 -04:00
partitioning Improve performance of adjust_appendrel_attrs_multilevel. 2022-08-18 12:36:16 -04:00
po NLS: Put list of available languages into LINGUAS files 2022-07-13 08:19:17 +02:00
port Cleanup more code and comments related to Windows NT4 (XP days) 2022-08-30 09:52:58 +09:00
postmaster Prevent long-term memory leakage in autovacuum launcher. 2022-08-31 16:23:35 -04:00
regex Defend against stack overrun in a few more places. 2022-08-24 13:02:19 -04:00
replication Drop replication origin slots before tablesync worker exits. 2022-08-30 08:51:41 +05:30
rewrite More -Wshadow=compatible-local warning fixes 2022-08-26 02:35:40 +12:00
snowball In the Snowball dictionary, don't try to stem excessively-long words. 2022-08-31 10:42:05 -04:00
statistics More -Wshadow=compatible-local warning fixes 2022-08-26 02:35:40 +12:00
storage Clean up inconsistent use of fflush(). 2022-08-29 13:55:41 -04:00
tcop Allow grant-level control of role inheritance behavior. 2022-08-25 10:06:02 -04:00
tsearch Defend against stack overrun in a few more places. 2022-08-24 13:02:19 -04:00
utils Be smarter about freeing tuples during tuplesorts 2022-09-01 11:08:10 +12:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
Makefile Remove rule to generate postgres.o, not needed for 20+ years 2022-08-24 20:37:54 -07:00
common.mk Remove SUBSYS.o rule in common.mk, hasn't been used in a long time 2022-08-24 20:38:14 -07:00
nls.mk NLS: Put list of available languages into LINGUAS files 2022-07-13 08:19:17 +02:00