1996-08-28 03:59:28 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* relcache.h
|
1997-09-07 07:04:48 +02:00
|
|
|
* Relation descriptor cache definitions.
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*
|
2015-01-06 17:43:47 +01:00
|
|
|
* Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/include/utils/relcache.h
|
1996-08-28 03:59:28 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#ifndef RELCACHE_H
|
1996-08-28 03:59:28 +02:00
|
|
|
#define RELCACHE_H
|
|
|
|
|
2008-06-19 02:46:06 +02:00
|
|
|
#include "access/tupdesc.h"
|
|
|
|
#include "nodes/bitmapset.h"
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct RelationData *Relation;
|
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* RelationPtr is used in the executor to support index scans
|
|
|
|
* where we have to keep track of several index relations in an
|
2014-05-06 18:12:18 +02:00
|
|
|
* array. -cim 9/10/89
|
2008-06-19 02:46:06 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
typedef Relation *RelationPtr;
|
1996-08-28 03:59:28 +02:00
|
|
|
|
|
|
|
/*
|
2006-07-31 22:09:10 +02:00
|
|
|
* Routines to open (lookup) and close a relcache entry
|
1996-08-28 03:59:28 +02:00
|
|
|
*/
|
|
|
|
extern Relation RelationIdGetRelation(Oid relationId);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern void RelationClose(Relation relation);
|
1999-10-04 01:55:40 +02:00
|
|
|
|
2000-06-17 23:49:04 +02:00
|
|
|
/*
|
|
|
|
* Routines to compute/retrieve additional cached information
|
|
|
|
*/
|
|
|
|
extern List *RelationGetIndexList(Relation relation);
|
2005-08-12 03:36:05 +02:00
|
|
|
extern Oid RelationGetOidIndex(Relation relation);
|
2014-05-14 20:55:48 +02:00
|
|
|
extern Oid RelationGetReplicaIndex(Relation relation);
|
2003-05-28 18:04:02 +02:00
|
|
|
extern List *RelationGetIndexExpressions(Relation relation);
|
|
|
|
extern List *RelationGetIndexPredicate(Relation relation);
|
Add new wal_level, logical, sufficient for logical decoding.
When wal_level=logical, we'll log columns from the old tuple as
configured by the REPLICA IDENTITY facility added in commit
07cacba983ef79be4a84fcd0e0ca3b5fcb85dd65. This makes it possible
a properly-configured logical replication solution to correctly
follow table updates even if they change the chosen key columns,
or, with REPLICA IDENTITY FULL, even if the table has no key at
all. Note that updates which do not modify the replica identity
column won't log anything extra, making the choice of a good key
(i.e. one that will rarely be changed) important to performance
when wal_level=logical is configured.
Each insert, update, or delete to a catalog table will also log
the CMIN and/or CMAX values of stamped by the current transaction.
This is necessary because logical decoding will require access to
historical snapshots of the catalog in order to decode some data
types, and the CMIN/CMAX values that we may need in order to judge
row visibility may have been overwritten by the time we need them.
Andres Freund, reviewed in various versions by myself, Heikki
Linnakangas, KONDO Mitsumasa, and many others.
2013-12-11 00:33:45 +01:00
|
|
|
|
|
|
|
typedef enum IndexAttrBitmapKind
|
|
|
|
{
|
|
|
|
INDEX_ATTR_BITMAP_ALL,
|
|
|
|
INDEX_ATTR_BITMAP_KEY,
|
|
|
|
INDEX_ATTR_BITMAP_IDENTITY_KEY
|
|
|
|
} IndexAttrBitmapKind;
|
|
|
|
|
|
|
|
extern Bitmapset *RelationGetIndexAttrBitmap(Relation relation,
|
2014-05-06 18:12:18 +02:00
|
|
|
IndexAttrBitmapKind keyAttrs);
|
Add new wal_level, logical, sufficient for logical decoding.
When wal_level=logical, we'll log columns from the old tuple as
configured by the REPLICA IDENTITY facility added in commit
07cacba983ef79be4a84fcd0e0ca3b5fcb85dd65. This makes it possible
a properly-configured logical replication solution to correctly
follow table updates even if they change the chosen key columns,
or, with REPLICA IDENTITY FULL, even if the table has no key at
all. Note that updates which do not modify the replica identity
column won't log anything extra, making the choice of a good key
(i.e. one that will rarely be changed) important to performance
when wal_level=logical is configured.
Each insert, update, or delete to a catalog table will also log
the CMIN and/or CMAX values of stamped by the current transaction.
This is necessary because logical decoding will require access to
historical snapshots of the catalog in order to decode some data
types, and the CMIN/CMAX values that we may need in order to judge
row visibility may have been overwritten by the time we need them.
Andres Freund, reviewed in various versions by myself, Heikki
Linnakangas, KONDO Mitsumasa, and many others.
2013-12-11 00:33:45 +01:00
|
|
|
|
2009-12-07 06:22:23 +01:00
|
|
|
extern void RelationGetExclusionInfo(Relation indexRelation,
|
2010-02-26 03:01:40 +01:00
|
|
|
Oid **operators,
|
|
|
|
Oid **procs,
|
|
|
|
uint16 **strategies);
|
2000-06-17 23:49:04 +02:00
|
|
|
|
2005-08-12 03:36:05 +02:00
|
|
|
extern void RelationSetIndexList(Relation relation,
|
2005-10-15 04:49:52 +02:00
|
|
|
List *indexIds, Oid oidIndex);
|
2003-09-24 20:54:02 +02:00
|
|
|
|
2001-10-07 01:21:45 +02:00
|
|
|
extern void RelationInitIndexAccessInfo(Relation relation);
|
|
|
|
|
Provide database object names as separate fields in error messages.
This patch addresses the problem that applications currently have to
extract object names from possibly-localized textual error messages,
if they want to know for example which index caused a UNIQUE_VIOLATION
failure. It adds new error message fields to the wire protocol, which
can carry the name of a table, table column, data type, or constraint
associated with the error. (Since the protocol spec has always instructed
clients to ignore unrecognized field types, this should not create any
compatibility problem.)
Support for providing these new fields has been added to just a limited set
of error reports (mainly, those in the "integrity constraint violation"
SQLSTATE class), but we will doubtless add them to more calls in future.
Pavel Stehule, reviewed and extensively revised by Peter Geoghegan, with
additional hacking by Tom Lane.
2013-01-29 23:06:26 +01:00
|
|
|
/*
|
|
|
|
* Routines to support ereport() reports of relation-related errors
|
|
|
|
*/
|
|
|
|
extern int errtable(Relation rel);
|
|
|
|
extern int errtablecol(Relation rel, int attnum);
|
|
|
|
extern int errtablecolname(Relation rel, const char *colname);
|
|
|
|
extern int errtableconstraint(Relation rel, const char *conname);
|
|
|
|
|
2000-08-06 06:40:08 +02:00
|
|
|
/*
|
|
|
|
* Routines for backend startup
|
|
|
|
*/
|
|
|
|
extern void RelationCacheInitialize(void);
|
|
|
|
extern void RelationCacheInitializePhase2(void);
|
2009-08-12 22:53:31 +02:00
|
|
|
extern void RelationCacheInitializePhase3(void);
|
2000-08-06 06:40:08 +02:00
|
|
|
|
2001-06-29 23:08:25 +02:00
|
|
|
/*
|
|
|
|
* Routine to create a relcache entry for an about-to-be-created relation
|
|
|
|
*/
|
|
|
|
extern Relation RelationBuildLocalRelation(const char *relname,
|
2002-03-26 20:17:02 +01:00
|
|
|
Oid relnamespace,
|
2001-10-25 07:50:21 +02:00
|
|
|
TupleDesc tupDesc,
|
2004-06-18 08:14:31 +02:00
|
|
|
Oid relid,
|
2011-07-18 17:02:48 +02:00
|
|
|
Oid relfilenode,
|
2004-06-18 08:14:31 +02:00
|
|
|
Oid reltablespace,
|
2010-02-07 21:48:13 +01:00
|
|
|
bool shared_relation,
|
2010-12-13 18:34:26 +01:00
|
|
|
bool mapped_relation,
|
2012-06-14 15:47:30 +02:00
|
|
|
char relpersistence,
|
|
|
|
char relkind);
|
2001-06-29 23:08:25 +02:00
|
|
|
|
2010-02-03 02:14:17 +01:00
|
|
|
/*
|
|
|
|
* Routine to manage assignment of new relfilenode to a relation
|
|
|
|
*/
|
2014-11-17 15:23:35 +01:00
|
|
|
extern void RelationSetNewRelfilenode(Relation relation, char persistence,
|
Improve concurrency of foreign key locking
This patch introduces two additional lock modes for tuples: "SELECT FOR
KEY SHARE" and "SELECT FOR NO KEY UPDATE". These don't block each
other, in contrast with already existing "SELECT FOR SHARE" and "SELECT
FOR UPDATE". UPDATE commands that do not modify the values stored in
the columns that are part of the key of the tuple now grab a SELECT FOR
NO KEY UPDATE lock on the tuple, allowing them to proceed concurrently
with tuple locks of the FOR KEY SHARE variety.
Foreign key triggers now use FOR KEY SHARE instead of FOR SHARE; this
means the concurrency improvement applies to them, which is the whole
point of this patch.
The added tuple lock semantics require some rejiggering of the multixact
module, so that the locking level that each transaction is holding can
be stored alongside its Xid. Also, multixacts now need to persist
across server restarts and crashes, because they can now represent not
only tuple locks, but also tuple updates. This means we need more
careful tracking of lifetime of pg_multixact SLRU files; since they now
persist longer, we require more infrastructure to figure out when they
can be removed. pg_upgrade also needs to be careful to copy
pg_multixact files over from the old server to the new, or at least part
of multixact.c state, depending on the versions of the old and new
servers.
Tuple time qualification rules (HeapTupleSatisfies routines) need to be
careful not to consider tuples with the "is multi" infomask bit set as
being only locked; they might need to look up MultiXact values (i.e.
possibly do pg_multixact I/O) to find out the Xid that updated a tuple,
whereas they previously were assured to only use information readily
available from the tuple header. This is considered acceptable, because
the extra I/O would involve cases that would previously cause some
commands to block waiting for concurrent transactions to finish.
Another important change is the fact that locking tuples that have
previously been updated causes the future versions to be marked as
locked, too; this is essential for correctness of foreign key checks.
This causes additional WAL-logging, also (there was previously a single
WAL record for a locked tuple; now there are as many as updated copies
of the tuple there exist.)
With all this in place, contention related to tuples being checked by
foreign key rules should be much reduced.
As a bonus, the old behavior that a subtransaction grabbing a stronger
tuple lock than the parent (sub)transaction held on a given tuple and
later aborting caused the weaker lock to be lost, has been fixed.
Many new spec files were added for isolation tester framework, to ensure
overall behavior is sane. There's probably room for several more tests.
There were several reviewers of this patch; in particular, Noah Misch
and Andres Freund spent considerable time in it. Original idea for the
patch came from Simon Riggs, after a problem report by Joel Jacobson.
Most code is from me, with contributions from Marti Raudsepp, Alexander
Shulgin, Noah Misch and Andres Freund.
This patch was discussed in several pgsql-hackers threads; the most
important start at the following message-ids:
AANLkTimo9XVcEzfiBR-ut3KVNDkjm2Vxh+t8kAmWjPuv@mail.gmail.com
1290721684-sup-3951@alvh.no-ip.org
1294953201-sup-2099@alvh.no-ip.org
1320343602-sup-2290@alvh.no-ip.org
1339690386-sup-8927@alvh.no-ip.org
4FE5FF020200002500048A3D@gw.wicourts.gov
4FEAB90A0200002500048B7D@gw.wicourts.gov
2013-01-23 16:04:59 +01:00
|
|
|
TransactionId freezeXid, MultiXactId minmulti);
|
2010-02-03 02:14:17 +01:00
|
|
|
|
1999-10-04 01:55:40 +02:00
|
|
|
/*
|
|
|
|
* Routines for flushing/rebuilding relcache entries in various scenarios
|
|
|
|
*/
|
2001-06-29 23:08:25 +02:00
|
|
|
extern void RelationForgetRelation(Oid rid);
|
|
|
|
|
2005-01-10 21:02:24 +01:00
|
|
|
extern void RelationCacheInvalidateEntry(Oid relationId);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2000-01-31 05:35:57 +01:00
|
|
|
extern void RelationCacheInvalidate(void);
|
1996-08-28 03:59:28 +02:00
|
|
|
|
2010-02-07 21:48:13 +01:00
|
|
|
extern void RelationCloseSmgrByOid(Oid relationId);
|
|
|
|
|
2004-07-01 02:52:04 +02:00
|
|
|
extern void AtEOXact_RelationCache(bool isCommit);
|
2004-09-16 18:58:44 +02:00
|
|
|
extern void AtEOSubXact_RelationCache(bool isCommit, SubTransactionId mySubid,
|
2005-10-15 04:49:52 +02:00
|
|
|
SubTransactionId parentSubid);
|
1999-09-04 20:42:15 +02:00
|
|
|
|
2002-02-19 21:11:20 +01:00
|
|
|
/*
|
2009-08-12 22:53:31 +02:00
|
|
|
* Routines to help manage rebuilding of relcache init files
|
2002-02-19 21:11:20 +01:00
|
|
|
*/
|
2011-08-16 19:11:54 +02:00
|
|
|
extern void RelationCacheInitFilePreInvalidate(void);
|
|
|
|
extern void RelationCacheInitFilePostInvalidate(void);
|
2009-08-12 22:53:31 +02:00
|
|
|
extern void RelationCacheInitFileRemove(void);
|
2000-11-21 22:16:06 +01:00
|
|
|
|
2002-02-19 21:11:20 +01:00
|
|
|
/* should be used only by relcache.c and catcache.c */
|
|
|
|
extern bool criticalRelcachesBuilt;
|
2010-02-26 03:01:40 +01:00
|
|
|
|
2009-08-12 22:53:31 +02:00
|
|
|
/* should be used only by relcache.c and postinit.c */
|
|
|
|
extern bool criticalSharedRelcachesBuilt;
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* RELCACHE_H */
|