postgresql/src/include/utils
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
..
.gitignore Generate fmgr prototypes automatically 2017-01-17 14:06:07 -05:00
acl.h Implement multivariate n-distinct coefficients 2017-03-24 14:06:10 -03:00
aclchk_internal.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
array.h Remove create_singleton_array(), hard-coding the case in its sole caller. 2017-05-02 20:41:37 -04:00
arrayaccess.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
ascii.h Generate fmgr prototypes automatically 2017-01-17 14:06:07 -05:00
attoptcache.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
backend_random.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
builtins.h Collect duplicate copies of oid_cmp() 2017-03-01 11:55:28 -05:00
bytea.h Generate fmgr prototypes automatically 2017-01-17 14:06:07 -05:00
cash.h Generate fmgr prototypes automatically 2017-01-17 14:06:07 -05:00
catcache.h Avoid searching for the target catcache in CatalogCacheIdInvalidate. 2017-05-12 18:17:29 -04:00
combocid.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
date.h Remove now-dead code for !HAVE_INT64_TIMESTAMP. 2017-02-23 14:04:43 -05:00
datetime.h Remove now-dead code for !HAVE_INT64_TIMESTAMP. 2017-02-23 14:04:43 -05:00
datum.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
dsa.h Remove inclusion of postgres.h from a few header files. 2017-03-08 08:18:12 -05:00
dynahash.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
dynamic_loader.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
elog.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
evtcache.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
expandeddatum.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
fmgrtab.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
formatting.h Generate fmgr prototypes automatically 2017-01-17 14:06:07 -05:00
freepage.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
geo_decls.h Generate fmgr prototypes automatically 2017-01-17 14:06:07 -05:00
guc_tables.h Add max_sync_workers_per_subscription to postgresql.conf.sample. 2017-04-12 00:10:54 +09:00
guc.h Make min_wal_size/max_wal_size use MB internally 2017-04-04 18:00:01 -04:00
help_config.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
hsearch.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
index_selfuncs.h Add optimizer and executor support for parallel index scans. 2017-02-15 13:53:24 -05:00
inet.h Add support for EUI-64 MAC addresses as macaddr8 2017-03-15 11:16:25 -04:00
int8.h Generate fmgr prototypes automatically 2017-01-17 14:06:07 -05:00
inval.h Logical replication 2017-01-20 09:04:49 -05:00
json.h Generate fmgr prototypes automatically 2017-01-17 14:06:07 -05:00
jsonapi.h Transform or iterate over json(b) string values 2017-03-31 14:25:25 -04:00
jsonb.h Introduce convenience macros to hide JsonbContainer header accesses better. 2017-01-25 13:28:38 -05:00
logtape.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
lsyscache.h Redesign get_attstatsslot()/free_attstatsslot() for more safety and speed. 2017-05-13 15:14:39 -04:00
memdebug.h Make useful infrastructure from aset.c generally available. 2017-02-27 03:41:44 -08:00
memutils.h Reduce size of common allocation header. 2017-02-28 19:42:44 -08:00
nabstime.h Generate fmgr prototypes automatically 2017-01-17 14:06:07 -05:00
numeric.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
palloc.h chomp PQerrorMessage() in backend uses 2017-02-27 08:54:51 -05:00
pg_crc.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
pg_locale.h Fix cpluspluscheck warning 2017-03-26 18:31:05 -04:00
pg_lsn.h Generate fmgr prototypes automatically 2017-01-17 14:06:07 -05:00
pg_rusage.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
plancache.h Fix two undocumented parameters to functions from ENR patch. 2017-04-01 15:21:05 -05:00
portal.h Add infrastructure to support EphemeralNamedRelation references. 2017-03-31 23:17:18 -05:00
ps_status.h Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
queryenvironment.h Add infrastructure to support EphemeralNamedRelation references. 2017-03-31 23:17:18 -05:00
rangetypes.h Generate fmgr prototypes automatically 2017-01-17 14:06:07 -05:00
regproc.h Move some things from builtins.h to new header files 2017-01-20 20:29:53 -05:00
rel.h Implement multivariate n-distinct coefficients 2017-03-24 14:06:10 -03:00
relcache.h Implement multivariate n-distinct coefficients 2017-03-24 14:06:10 -03:00
relfilenodemap.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
relmapper.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
relptr.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
reltrigger.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
resowner_private.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
resowner.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
rls.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
ruleutils.h Improve error reporting for tuple-routing failures. 2017-03-03 09:09:52 +05:30
sampling.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
selfuncs.h Redesign get_attstatsslot()/free_attstatsslot() for more safety and speed. 2017-05-13 15:14:39 -04:00
snapmgr.h Always SnapshotResetXmin() during ClearTransaction() 2017-04-06 10:30:22 -04:00
snapshot.h Consistently declare timestamp variables as TimestampTz. 2017-02-23 15:57:08 -05:00
sortsupport.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
spccache.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
syscache.h Avoid searching for callback functions in CallSyscacheCallbacks(). 2017-05-12 19:05:27 -04:00
timeout.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
timestamp.h Consistently declare timestamp variables as TimestampTz. 2017-02-23 15:57:08 -05:00
tqual.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
tuplesort.h Allow avoiding tuple copy within tuplesort_gettupleslot(). 2017-04-06 14:48:59 -07:00
tuplestore.h Add infrastructure to support EphemeralNamedRelation references. 2017-03-31 23:17:18 -05:00
typcache.h Faster expression evaluation and targetlist projection. 2017-03-25 14:52:06 -07:00
tzparser.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
uuid.h Update copyright via script for 2017 2017-01-03 13:48:53 -05:00
varbit.h Generate fmgr prototypes automatically 2017-01-17 14:06:07 -05:00
varlena.h Move some things from builtins.h to new header files 2017-01-20 20:29:53 -05:00
xml.h Faster expression evaluation and targetlist projection. 2017-03-25 14:52:06 -07:00