postgresql/src/include
Tom Lane 9aab83fc50 Redesign get_attstatsslot()/free_attstatsslot() for more safety and speed.
The mess cleaned up in commit da0759600 is clear evidence that it's a
bug hazard to expect the caller of get_attstatsslot()/free_attstatsslot()
to provide the correct type OID for the array elements in the slot.
Moreover, we weren't even getting any performance benefit from that,
since get_attstatsslot() was extracting the real type OID from the array
anyway.  So we ought to get rid of that requirement; indeed, it would
make more sense for get_attstatsslot() to pass back the type OID it found,
in case the caller isn't sure what to expect, which is likely in binary-
compatible-operator cases.

Another problem with the current implementation is that if the stats array
element type is pass-by-reference, we incur a palloc/memcpy/pfree cycle
for each element.  That seemed acceptable when the code was written because
we were targeting O(10) array sizes --- but these days, stats arrays are
almost always bigger than that, sometimes much bigger.  We can save a
significant number of cycles by doing one palloc/memcpy/pfree of the whole
array.  Indeed, in the now-probably-common case where the array is toasted,
that happens anyway so this method is basically free.  (Note: although the
catcache code will inline any out-of-line toasted values, it doesn't
decompress them.  At the other end of the size range, it doesn't expand
short-header datums either.  In either case, DatumGetArrayTypeP would have
to make a copy.  We do end up using an extra array copy step if the element
type is pass-by-value and the array length is neither small enough for a
short header nor large enough to have suffered compression.  But that
seems like a very acceptable price for winning in pass-by-ref cases.)

Hence, redesign to take these insights into account.  While at it,
convert to an API in which we fill a struct rather than passing a bunch
of pointers to individual output arguments.  That will make it less
painful if we ever want further expansion of what get_attstatsslot can
pass back.

It's certainly arguable that this is new development and not something to
push post-feature-freeze.  However, I view it as primarily bug-proofing
and therefore something that's better to have sooner not later.  Since
we aren't quite at beta phase yet, let's put it in.

Discussion: https://postgr.es/m/16364.1494520862@sss.pgh.pa.us
2017-05-13 15:14:39 -04:00
..
access Standardize "WAL location" terminology 2017-05-12 13:51:27 -04:00
bootstrap Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
catalog Teach \d+ to show partitioning constraints. 2017-05-13 12:04:53 -04:00
commands Identity columns 2017-04-06 08:41:37 -04:00
common Make SCRAM salts and nonces longer. 2017-05-05 10:02:13 +03:00
datatype Consistently declare timestamp variables as TimestampTz. 2017-02-23 15:57:08 -05:00
executor Provide an error cursor for "can't call an SRF here" errors. 2017-04-18 13:21:08 -04:00
fe_utils Allow psql variable substitution to occur in backtick command strings. 2017-04-01 21:44:54 -04:00
foreign Allow custom and foreign scans to have shutdown callbacks. 2017-02-26 13:41:12 +05:30
lib Revert "Permit dump/reload of not-too-large >1GB tuples" 2017-05-10 18:41:27 -03:00
libpq Remove support for password_encryption='off' / 'plain'. 2017-05-08 11:26:07 +03:00
mb ICU support 2017-03-23 15:28:48 -04:00
nodes Fix multi-column range partitioning constraints. 2017-05-13 11:36:41 -04:00
optimizer Reduce semijoins with unique inner relations to plain inner joins. 2017-05-01 14:53:42 -04:00
parser Rework the options syntax for logical replication commands 2017-05-12 08:57:49 -04:00
port Remove symbol WIN32_ONLY_COMPILER 2017-04-11 15:22:21 +02:00
portability Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
postmaster Add an Assert() to max_parallel_workers enforcement. 2017-04-11 13:03:44 -04:00
regex Document intentional violations of header inclusion policy. 2017-03-08 17:01:13 -05:00
replication Lag tracking for logical replication 2017-05-12 10:50:56 +01:00
rewrite Remove deprecated COMMENT ON RULE syntax 2017-02-23 08:19:52 -05:00
snowball Document intentional violations of header inclusion policy. 2017-03-08 17:01:13 -05:00
statistics Collect and use multi-column dependency stats 2017-04-05 18:00:42 -04:00
storage Preserve required !catalog tuples while computing initial decoding snapshot. 2017-04-27 13:13:36 -07:00
tcop Remove dead code and fix comments in fast-path function handling. 2017-04-06 09:09:39 +03:00
tsearch Full Text Search support for json and jsonb 2017-03-31 14:26:03 -04:00
utils Redesign get_attstatsslot()/free_attstatsslot() for more safety and speed. 2017-05-13 15:14:39 -04:00
.gitignore Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
c.h Recommend wrappers of PG_DETOAST_DATUM_PACKED(). 2017-03-12 19:35:33 -04:00
fmgr.h Avoid passing function pointers across process boundaries. 2017-04-14 23:50:16 -04:00
funcapi.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
getaddrinfo.h Remove symbol WIN32_ONLY_COMPILER 2017-04-11 15:22:21 +02:00
getopt_long.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
Makefile Generate fmgr prototypes automatically 2017-01-17 14:06:07 -05:00
miscadmin.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
pg_config.h.in Revert "Use pselect(2) not select(2), if available, to wait in postmaster's loop." 2017-04-24 18:29:03 -04:00
pg_config.h.win32 Revert "Use pselect(2) not select(2), if available, to wait in postmaster's loop." 2017-04-24 18:29:03 -04:00
pg_config_ext.h.in Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_ext.h.win32 Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_manual.h Fix default minimum value for descending sequences 2017-01-23 14:00:58 -05:00
pg_getopt.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
pg_trace.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
pgstat.h Add ProcArrayGroupUpdate wait event. 2017-04-07 13:41:47 -04:00
pgtar.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
pgtime.h Fix incorrect comment: pgtime's tm_mon is 1-based, not 0-based. 2017-01-24 09:36:17 -05:00
port.h Run the postmaster's signal handlers without SA_RESTART. 2017-04-24 13:00:30 -04:00
postgres.h Recommend wrappers of PG_DETOAST_DATUM_PACKED(). 2017-03-12 19:35:33 -04:00
postgres_ext.h Move atooid() definition to a central place 2017-03-01 11:55:28 -05:00
postgres_fe.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
rusagestub.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
windowapi.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00