postgresql/src
Tom Lane 8abb3cda0d Use the typcache to cache constraints for domain types.
Previously, we cached domain constraints for the life of a query, or
really for the life of the FmgrInfo struct that was used to invoke
domain_in() or domain_check().  But plpgsql (and probably other places)
are set up to cache such FmgrInfos for the whole lifespan of a session,
which meant they could be enforcing really stale sets of constraints.
On the other hand, searching pg_constraint once per query gets kind of
expensive too: testing says that as much as half the runtime of a
trivial query such as "SELECT 0::domaintype" went into that.

To fix this, delegate the responsibility for tracking a domain's
constraints to the typcache, which has the infrastructure needed to
detect syscache invalidation events that signal possible changes.
This not only removes unnecessary repeat reads of pg_constraint,
but ensures that we never apply stale constraint data: whatever we
use is the current data according to syscache rules.

Unfortunately, the current configuration of the system catalogs means
we have to flush cached domain-constraint data whenever either pg_type
or pg_constraint changes, which happens rather a lot (eg, creation or
deletion of a temp table will do it).  It might be worth rearranging
things to split pg_constraint into two catalogs, of which the domain
constraint one would probably be very low-traffic.  That's a job for
another patch though, and in any case this patch should improve matters
materially even with that handicap.

This patch makes use of the recently-added memory context reset callback
feature to manage the lifespan of domain constraint caches, so that we
don't risk deleting a cache that might be in the midst of evaluation.

Although this is a bug fix as well as a performance improvement, no
back-patch.  There haven't been many if any field complaints about
stale domain constraint checks, so it doesn't seem worth taking the
risk of modifying data structures as basic as MemoryContexts in back
branches.
2015-03-01 14:06:55 -05:00
..
backend Use the typcache to cache constraints for domain types. 2015-03-01 14:06:55 -05:00
bin Error when creating names too long for tar format 2015-02-24 13:41:07 -05:00
common Unlink static libraries before rebuilding them. 2015-03-01 13:05:23 -05:00
include Use the typcache to cache constraints for domain types. 2015-03-01 14:06:55 -05:00
interfaces Remove null-pointer checks that are not needed. 2015-02-25 11:50:28 +01:00
makefiles Revert haphazard pgxs makefile changes 2014-12-04 08:07:59 -05:00
pl Track typmods in plpgsql expression evaluation and assignment. 2015-02-28 14:34:35 -05:00
port Unlink static libraries before rebuilding them. 2015-03-01 13:05:23 -05:00
template Remove duplicate specification of -Ae for HP-UX C compiler. 2015-01-13 22:52:11 -05:00
test Use the typcache to cache constraints for domain types. 2015-03-01 14:06:55 -05:00
timezone Update time zone data files to tzdata release 2015a. 2015-01-30 22:45:44 -05:00
tools Fix Perl coding error in msvc build system 2015-02-18 20:24:30 -05:00
tutorial Update copyright for 2015 2015-01-06 11:43:47 -05:00
.gitignore
DEVELOPERS
Makefile
Makefile.global.in Fix installcheck case for tap tests 2014-12-24 10:31:36 -05:00
Makefile.shlib Unlink static libraries before rebuilding them. 2015-03-01 13:05:23 -05:00
bcc32.mak
nls-global.mk
win32.mak