postgresql/src/backend
Tom Lane 442accc3fe Allow memory contexts to have both fixed and variable ident strings.
Originally, we treated memory context names as potentially variable in
all cases, and therefore always copied them into the context header.
Commit 9fa6f00b1 rethought this a little bit and invented a distinction
between fixed and variable names, skipping the copy step for the former.
But we can make things both simpler and more useful by instead allowing
there to be two parts to a context's identification, a fixed "name" and
an optional, variable "ident".  The name supplied in the context create
call is now required to be a compile-time-constant string in all cases,
as it is never copied but just pointed to.  The "ident" string, if
wanted, is supplied later.  This is needed because typically we want
the ident to be stored inside the context so that it's cleaned up
automatically on context deletion; that means it has to be copied into
the context before we can set the pointer.

The cost of this approach is basically just an additional pointer field
in struct MemoryContextData, which isn't much overhead, and is bought
back entirely in the AllocSet case by not needing a headerSize field
anymore, since we no longer have to cope with variable header length.
In addition, we can simplify the internal interfaces for memory context
creation still further, saving a few cycles there.  And it's no longer
true that a custom identifier disqualifies a context from participating
in aset.c's freelist scheme, so possibly there's some win on that end.

All the places that were using non-compile-time-constant context names
are adjusted to put the variable info into the "ident" instead.  This
allows more effective identification of those contexts in many cases;
for example, subsidary contexts of relcache entries are now identified
by both type (e.g. "index info") and relname, where before you got only
one or the other.  Contexts associated with PL function cache entries
are now identified more fully and uniformly, too.

I also arranged for plancache contexts to use the query source string
as their identifier.  This is basically free for CachedPlanSources, as
they contained a copy of that string already.  We pay an extra pstrdup
to do it for CachedPlans.  That could perhaps be avoided, but it would
make things more fragile (since the CachedPlanSource is sometimes
destroyed first).  I suspect future improvements in error reporting will
require CachedPlans to have a copy of that string anyway, so it's not
clear that it's worth moving mountains to avoid it now.

This also changes the APIs for context statistics routines so that the
context-specific routines no longer assume that output goes straight
to stderr, nor do they know all details of the output format.  This
is useful immediately to reduce code duplication, and it also allows
for external code to do something with stats output that's different
from printing to stderr.

The reason for pushing this now rather than waiting for v12 is that
it rethinks some of the API changes made by commit 9fa6f00b1.  Seems
better for extension authors to endure just one round of API changes
not two.

Discussion: https://postgr.es/m/CAB=Je-FdtmFZ9y9REHD7VsSrnCkiBhsA4mdsLKSPauwXtQBeNA@mail.gmail.com
2018-03-27 16:46:51 -04:00
..
access Allow memory contexts to have both fixed and variable ident strings. 2018-03-27 16:46:51 -04:00
bootstrap Handle heap rewrites even better in logical decoding 2018-03-21 09:15:04 -04:00
catalog Allow memory contexts to have both fixed and variable ident strings. 2018-03-27 16:46:51 -04:00
commands Allow memory contexts to have both fixed and variable ident strings. 2018-03-27 16:46:51 -04:00
executor Allow memory contexts to have both fixed and variable ident strings. 2018-03-27 16:46:51 -04:00
foreign Remove bogus "extern" annotations on function definitions. 2018-02-19 12:07:44 -05:00
jit Adapt to LLVM 7+ Orc API changes. 2018-03-26 16:04:53 -07:00
lib Minor clean-up in dshash.{c,h}. 2018-03-01 16:25:46 -08:00
libpq Fix typo in comment 2018-03-19 10:45:44 +01:00
main Update copyright for 2018 2018-01-02 23:30:12 -05:00
nodes Basic planner and executor integration for JIT. 2018-03-22 11:51:58 -07:00
optimizer JIT tuple deforming in LLVM JIT provider. 2018-03-26 12:57:19 -07:00
parser Handle INSERT .. ON CONFLICT with partitioned tables 2018-03-26 10:43:54 -03:00
po Translation updates 2017-08-07 13:55:34 -04:00
port Support huge pages on Windows 2018-01-21 15:40:46 +01:00
postmaster Log when a BRIN autosummarization request fails 2018-03-14 11:59:40 -03:00
regex Update copyright for 2018 2018-01-02 23:30:12 -05:00
replication Allow memory contexts to have both fixed and variable ident strings. 2018-03-27 16:46:51 -04:00
rewrite Remove pg_class.relhaspkey 2018-03-14 15:31:34 -04:00
snowball Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers. 2018-01-26 18:25:14 -05:00
statistics Allow memory contexts to have both fixed and variable ident strings. 2018-03-27 16:46:51 -04:00
storage Skip temp tables from basebackup. 2018-03-27 16:14:40 +03:00
tcop Small refactoring 2018-03-23 17:18:22 -04:00
tsearch Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers. 2018-01-26 18:25:14 -05:00
utils Allow memory contexts to have both fixed and variable ident strings. 2018-03-27 16:46:51 -04:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
Makefile Fix make rules that generate multiple output files. 2018-03-23 13:46:00 -04:00
common.mk Support for optimizing and emitting code in LLVM JIT provider. 2018-03-22 11:05:22 -07:00
nls.mk Translation updates 2017-05-15 12:19:54 -04:00