2003-08-17 21:58:06 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* typcache.h
|
|
|
|
* Type cache definitions.
|
|
|
|
*
|
|
|
|
* The type cache exists to speed lookup of certain information about data
|
|
|
|
* types that is not directly available from a type's pg_type row.
|
|
|
|
*
|
2017-01-03 19:48:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
|
2003-08-17 21:58:06 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/include/utils/typcache.h
|
2003-08-17 21:58:06 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef TYPCACHE_H
|
|
|
|
#define TYPCACHE_H
|
|
|
|
|
2004-04-01 23:28:47 +02:00
|
|
|
#include "access/tupdesc.h"
|
2003-08-17 21:58:06 +02:00
|
|
|
#include "fmgr.h"
|
|
|
|
|
|
|
|
|
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 20:06:50 +01:00
|
|
|
/* DomainConstraintCache is an opaque struct known only within typcache.c */
|
|
|
|
typedef struct DomainConstraintCache DomainConstraintCache;
|
|
|
|
|
2010-10-25 05:04:37 +02:00
|
|
|
/* TypeCacheEnumData is an opaque struct known only within typcache.c */
|
|
|
|
struct TypeCacheEnumData;
|
|
|
|
|
2003-08-17 21:58:06 +02:00
|
|
|
typedef struct TypeCacheEntry
|
|
|
|
{
|
|
|
|
/* typeId is the hash lookup key and MUST BE FIRST */
|
|
|
|
Oid type_id; /* OID of the data type */
|
|
|
|
|
|
|
|
/* some subsidiary information copied from the pg_type row */
|
|
|
|
int16 typlen;
|
|
|
|
bool typbyval;
|
|
|
|
char typalign;
|
2011-11-15 19:05:45 +01:00
|
|
|
char typstorage;
|
2004-04-01 23:28:47 +02:00
|
|
|
char typtype;
|
|
|
|
Oid typrelid;
|
2003-08-17 21:58:06 +02:00
|
|
|
|
|
|
|
/*
|
2006-12-23 01:43:13 +01:00
|
|
|
* Information obtained from opfamily entries
|
2003-08-17 21:58:06 +02:00
|
|
|
*
|
2005-11-22 19:17:34 +01:00
|
|
|
* These will be InvalidOid if no match could be found, or if the
|
2011-06-03 21:38:12 +02:00
|
|
|
* information hasn't yet been requested. Also note that for array and
|
|
|
|
* composite types, typcache.c checks that the contained types are
|
|
|
|
* comparable or hashable before allowing eq_opr etc to become set.
|
2003-08-17 21:58:06 +02:00
|
|
|
*/
|
2006-12-23 01:43:13 +01:00
|
|
|
Oid btree_opf; /* the default btree opclass' family */
|
2007-11-15 22:14:46 +01:00
|
|
|
Oid btree_opintype; /* the default btree opclass' opcintype */
|
2006-12-23 01:43:13 +01:00
|
|
|
Oid hash_opf; /* the default hash opclass' family */
|
|
|
|
Oid hash_opintype; /* the default hash opclass' opcintype */
|
|
|
|
Oid eq_opr; /* the equality operator */
|
|
|
|
Oid lt_opr; /* the less-than operator */
|
|
|
|
Oid gt_opr; /* the greater-than operator */
|
|
|
|
Oid cmp_proc; /* the btree comparison function */
|
2010-10-31 02:55:20 +01:00
|
|
|
Oid hash_proc; /* the hash calculation function */
|
2003-08-17 21:58:06 +02:00
|
|
|
|
|
|
|
/*
|
2010-10-31 02:55:20 +01:00
|
|
|
* Pre-set-up fmgr call info for the equality operator, the btree
|
2014-05-06 18:12:18 +02:00
|
|
|
* comparison function, and the hash calculation function. These are kept
|
2010-10-31 02:55:20 +01:00
|
|
|
* in the type cache to avoid problems with memory leaks in repeated calls
|
2011-06-03 21:38:12 +02:00
|
|
|
* to functions such as array_eq, array_cmp, hash_array. There is not
|
|
|
|
* currently a need to maintain call info for the lt_opr or gt_opr.
|
2003-08-17 21:58:06 +02:00
|
|
|
*/
|
|
|
|
FmgrInfo eq_opr_finfo;
|
|
|
|
FmgrInfo cmp_proc_finfo;
|
2010-10-31 02:55:20 +01:00
|
|
|
FmgrInfo hash_proc_finfo;
|
2004-04-01 23:28:47 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Tuple descriptor if it's a composite type (row type). NULL if not
|
2006-10-04 02:30:14 +02:00
|
|
|
* composite or information hasn't yet been requested. (NOTE: this is a
|
|
|
|
* reference-counted tupledesc.)
|
2004-04-01 23:28:47 +02:00
|
|
|
*/
|
|
|
|
TupleDesc tupDesc;
|
2010-10-25 05:04:37 +02:00
|
|
|
|
2011-11-15 19:05:45 +01:00
|
|
|
/*
|
2014-05-06 18:12:18 +02:00
|
|
|
* Fields computed when TYPECACHE_RANGE_INFO is requested. Zeroes if not
|
2012-06-10 21:20:04 +02:00
|
|
|
* a range type or information hasn't yet been requested. Note that
|
2011-11-15 19:05:45 +01:00
|
|
|
* rng_cmp_proc_finfo could be different from the element type's default
|
|
|
|
* btree comparison function.
|
|
|
|
*/
|
2012-06-10 21:20:04 +02:00
|
|
|
struct TypeCacheEntry *rngelemtype; /* range's element type */
|
|
|
|
Oid rng_collation; /* collation for comparisons, if any */
|
2011-11-15 19:05:45 +01:00
|
|
|
FmgrInfo rng_cmp_proc_finfo; /* comparison function */
|
|
|
|
FmgrInfo rng_canonical_finfo; /* canonicalization function, if any */
|
|
|
|
FmgrInfo rng_subdiff_finfo; /* difference function, if any */
|
|
|
|
|
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 20:06:50 +01:00
|
|
|
/*
|
|
|
|
* Domain constraint data if it's a domain type. NULL if not domain, or
|
|
|
|
* if domain has no constraints, or if information hasn't been requested.
|
|
|
|
*/
|
|
|
|
DomainConstraintCache *domainData;
|
|
|
|
|
2011-06-03 21:38:12 +02:00
|
|
|
/* Private data, for internal use of typcache.c only */
|
|
|
|
int flags; /* flags about what we've computed */
|
|
|
|
|
2010-10-25 05:04:37 +02:00
|
|
|
/*
|
2014-05-06 18:12:18 +02:00
|
|
|
* Private information about an enum type. NULL if not enum or
|
2010-10-25 05:04:37 +02:00
|
|
|
* information hasn't been requested.
|
|
|
|
*/
|
|
|
|
struct TypeCacheEnumData *enumData;
|
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 20:06:50 +01:00
|
|
|
|
|
|
|
/* We also maintain a list of all known domain-type cache entries */
|
|
|
|
struct TypeCacheEntry *nextDomain;
|
2003-08-17 21:58:06 +02:00
|
|
|
} TypeCacheEntry;
|
|
|
|
|
|
|
|
/* Bit flags to indicate which fields a given caller needs to have set */
|
|
|
|
#define TYPECACHE_EQ_OPR 0x0001
|
|
|
|
#define TYPECACHE_LT_OPR 0x0002
|
|
|
|
#define TYPECACHE_GT_OPR 0x0004
|
|
|
|
#define TYPECACHE_CMP_PROC 0x0008
|
2010-10-31 02:55:20 +01:00
|
|
|
#define TYPECACHE_HASH_PROC 0x0010
|
|
|
|
#define TYPECACHE_EQ_OPR_FINFO 0x0020
|
|
|
|
#define TYPECACHE_CMP_PROC_FINFO 0x0040
|
|
|
|
#define TYPECACHE_HASH_PROC_FINFO 0x0080
|
|
|
|
#define TYPECACHE_TUPDESC 0x0100
|
|
|
|
#define TYPECACHE_BTREE_OPFAMILY 0x0200
|
|
|
|
#define TYPECACHE_HASH_OPFAMILY 0x0400
|
2011-11-15 19:05:45 +01:00
|
|
|
#define TYPECACHE_RANGE_INFO 0x0800
|
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 20:06:50 +01:00
|
|
|
#define TYPECACHE_DOMAIN_INFO 0x1000
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Callers wishing to maintain a long-lived reference to a domain's constraint
|
|
|
|
* set must store it in one of these. Use InitDomainConstraintRef() and
|
|
|
|
* UpdateDomainConstraintRef() to manage it. Note: DomainConstraintState is
|
|
|
|
* considered an executable expression type, so it's defined in execnodes.h.
|
|
|
|
*/
|
|
|
|
typedef struct DomainConstraintRef
|
|
|
|
{
|
|
|
|
List *constraints; /* list of DomainConstraintState nodes */
|
2015-11-30 00:18:42 +01:00
|
|
|
MemoryContext refctx; /* context holding DomainConstraintRef */
|
2016-12-22 21:01:27 +01:00
|
|
|
TypeCacheEntry *tcache; /* typcache entry for domain type */
|
Faster expression evaluation and targetlist projection.
This replaces the old, recursive tree-walk based evaluation, with
non-recursive, opcode dispatch based, expression evaluation.
Projection is now implemented as part of expression evaluation.
This both leads to significant performance improvements, and makes
future just-in-time compilation of expressions easier.
The speed gains primarily come from:
- non-recursive implementation reduces stack usage / overhead
- simple sub-expressions are implemented with a single jump, without
function calls
- sharing some state between different sub-expressions
- reduced amount of indirect/hard to predict memory accesses by laying
out operation metadata sequentially; including the avoidance of
nearly all of the previously used linked lists
- more code has been moved to expression initialization, avoiding
constant re-checks at evaluation time
Future just-in-time compilation (JIT) has become easier, as
demonstrated by released patches intended to be merged in a later
release, for primarily two reasons: Firstly, due to a stricter split
between expression initialization and evaluation, less code has to be
handled by the JIT. Secondly, due to the non-recursive nature of the
generated "instructions", less performance-critical code-paths can
easily be shared between interpreted and compiled evaluation.
The new framework allows for significant future optimizations. E.g.:
- basic infrastructure for to later reduce the per executor-startup
overhead of expression evaluation, by caching state in prepared
statements. That'd be helpful in OLTPish scenarios where
initialization overhead is measurable.
- optimizing the generated "code". A number of proposals for potential
work has already been made.
- optimizing the interpreter. Similarly a number of proposals have
been made here too.
The move of logic into the expression initialization step leads to some
backward-incompatible changes:
- Function permission checks are now done during expression
initialization, whereas previously they were done during
execution. In edge cases this can lead to errors being raised that
previously wouldn't have been, e.g. a NULL array being coerced to a
different array type previously didn't perform checks.
- The set of domain constraints to be checked, is now evaluated once
during expression initialization, previously it was re-built
every time a domain check was evaluated. For normal queries this
doesn't change much, but e.g. for plpgsql functions, which caches
ExprStates, the old set could stick around longer. The behavior
around might still change.
Author: Andres Freund, with significant changes by Tom Lane,
changes by Heikki Linnakangas
Reviewed-By: Tom Lane, Heikki Linnakangas
Discussion: https://postgr.es/m/20161206034955.bh33paeralxbtluv@alap3.anarazel.de
2017-03-14 23:45:36 +01:00
|
|
|
bool need_exprstate; /* does caller need check_exprstate? */
|
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 20:06:50 +01:00
|
|
|
|
|
|
|
/* Management data --- treat these fields as private to typcache.c */
|
|
|
|
DomainConstraintCache *dcc; /* current constraints, or NULL if none */
|
|
|
|
MemoryContextCallback callback; /* used to release refcount when done */
|
|
|
|
} DomainConstraintRef;
|
|
|
|
|
2003-08-17 21:58:06 +02:00
|
|
|
|
|
|
|
extern TypeCacheEntry *lookup_type_cache(Oid type_id, int flags);
|
|
|
|
|
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 20:06:50 +01:00
|
|
|
extern void InitDomainConstraintRef(Oid type_id, DomainConstraintRef *ref,
|
Faster expression evaluation and targetlist projection.
This replaces the old, recursive tree-walk based evaluation, with
non-recursive, opcode dispatch based, expression evaluation.
Projection is now implemented as part of expression evaluation.
This both leads to significant performance improvements, and makes
future just-in-time compilation of expressions easier.
The speed gains primarily come from:
- non-recursive implementation reduces stack usage / overhead
- simple sub-expressions are implemented with a single jump, without
function calls
- sharing some state between different sub-expressions
- reduced amount of indirect/hard to predict memory accesses by laying
out operation metadata sequentially; including the avoidance of
nearly all of the previously used linked lists
- more code has been moved to expression initialization, avoiding
constant re-checks at evaluation time
Future just-in-time compilation (JIT) has become easier, as
demonstrated by released patches intended to be merged in a later
release, for primarily two reasons: Firstly, due to a stricter split
between expression initialization and evaluation, less code has to be
handled by the JIT. Secondly, due to the non-recursive nature of the
generated "instructions", less performance-critical code-paths can
easily be shared between interpreted and compiled evaluation.
The new framework allows for significant future optimizations. E.g.:
- basic infrastructure for to later reduce the per executor-startup
overhead of expression evaluation, by caching state in prepared
statements. That'd be helpful in OLTPish scenarios where
initialization overhead is measurable.
- optimizing the generated "code". A number of proposals for potential
work has already been made.
- optimizing the interpreter. Similarly a number of proposals have
been made here too.
The move of logic into the expression initialization step leads to some
backward-incompatible changes:
- Function permission checks are now done during expression
initialization, whereas previously they were done during
execution. In edge cases this can lead to errors being raised that
previously wouldn't have been, e.g. a NULL array being coerced to a
different array type previously didn't perform checks.
- The set of domain constraints to be checked, is now evaluated once
during expression initialization, previously it was re-built
every time a domain check was evaluated. For normal queries this
doesn't change much, but e.g. for plpgsql functions, which caches
ExprStates, the old set could stick around longer. The behavior
around might still change.
Author: Andres Freund, with significant changes by Tom Lane,
changes by Heikki Linnakangas
Reviewed-By: Tom Lane, Heikki Linnakangas
Discussion: https://postgr.es/m/20161206034955.bh33paeralxbtluv@alap3.anarazel.de
2017-03-14 23:45:36 +01:00
|
|
|
MemoryContext refctx, bool need_exprstate);
|
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 20:06:50 +01:00
|
|
|
|
|
|
|
extern void UpdateDomainConstraintRef(DomainConstraintRef *ref);
|
|
|
|
|
|
|
|
extern bool DomainHasConstraints(Oid type_id);
|
|
|
|
|
2004-04-01 23:28:47 +02:00
|
|
|
extern TupleDesc lookup_rowtype_tupdesc(Oid type_id, int32 typmod);
|
|
|
|
|
2004-06-05 03:55:05 +02:00
|
|
|
extern TupleDesc lookup_rowtype_tupdesc_noerror(Oid type_id, int32 typmod,
|
2004-08-29 07:07:03 +02:00
|
|
|
bool noError);
|
2004-06-05 03:55:05 +02:00
|
|
|
|
2006-06-16 20:42:24 +02:00
|
|
|
extern TupleDesc lookup_rowtype_tupdesc_copy(Oid type_id, int32 typmod);
|
|
|
|
|
2004-04-01 23:28:47 +02:00
|
|
|
extern void assign_record_type_typmod(TupleDesc tupDesc);
|
|
|
|
|
2010-10-25 05:04:37 +02:00
|
|
|
extern int compare_values_of_enum(TypeCacheEntry *tcache, Oid arg1, Oid arg2);
|
|
|
|
|
2003-08-17 21:58:06 +02:00
|
|
|
#endif /* TYPCACHE_H */
|