postgresql/src/backend/commands
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
..
Makefile Row-Level Security Policies (RLS) 2014-09-19 11:18:35 -04:00
aggregatecmds.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
alter.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
analyze.c Use abbreviated keys for faster sorting of text datums. 2015-01-19 15:28:27 -05:00
async.c Use FLEXIBLE_ARRAY_MEMBER in a number of other places. 2015-02-21 16:12:14 -05:00
cluster.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
collationcmds.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
comment.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
constraint.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
conversioncmds.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
copy.c Be more careful to not lose sync in the FE/BE protocol. 2015-02-02 17:09:53 +02:00
createas.c Fix column-privilege leak in error-message paths 2015-01-28 12:31:30 -05:00
dbcommands.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
define.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
discard.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
dropcmds.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
event_trigger.c Fix table_rewrite event trigger for ALTER TYPE/SET DATA TYPE CASCADE 2015-02-27 18:39:53 -03:00
explain.c Fix EXPLAIN output for cases where parent table is excluded by constraints. 2015-02-17 18:04:11 -05:00
extension.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
foreigncmds.c Fix whitespace 2015-01-22 16:57:16 -05:00
functioncmds.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
indexcmds.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
lockcmds.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
matview.c Fix column-privilege leak in error-message paths 2015-01-28 12:31:30 -05:00
opclasscmds.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
operatorcmds.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
policy.c Clean up some mess in row-security patches. 2015-01-24 16:16:22 -05:00
portalcmds.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
prepare.c Use FLEXIBLE_ARRAY_MEMBER in a bunch more places. 2015-02-20 00:11:42 -05:00
proclang.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
schemacmds.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
seclabel.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
sequence.c Reconsider when to wait for WAL flushes/syncrep during commit. 2015-02-26 12:50:07 +01:00
tablecmds.c Use the typcache to cache constraints for domain types. 2015-03-01 14:06:55 -05:00
tablespace.c Use FLEXIBLE_ARRAY_MEMBER in some more places. 2015-02-20 17:32:01 -05:00
trigger.c Use FLEXIBLE_ARRAY_MEMBER in some more places. 2015-02-20 17:32:01 -05:00
tsearchcmds.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
typecmds.c Use the typcache to cache constraints for domain types. 2015-03-01 14:06:55 -05:00
user.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
vacuum.c Reject ANALYZE commands during VACUUM FULL or another ANALYZE. 2015-01-07 22:33:58 -05:00
vacuumlazy.c Fix logging of pages skipped due to pins during vacuum. 2015-01-08 12:57:09 +01:00
variable.c Update copyright for 2015 2015-01-06 11:43:47 -05:00
view.c Update copyright for 2015 2015-01-06 11:43:47 -05:00