mirror of
https://github.com/postgres/postgres.git
synced 2026-01-29 12:02:15 +03:00
Add temporal PRIMARY KEY and UNIQUE constraints
Add WITHOUT OVERLAPS clause to PRIMARY KEY and UNIQUE constraints. These are backed by GiST indexes instead of B-tree indexes, since they are essentially exclusion constraints with = for the scalar parts of the key and && for the temporal part. Author: Paul A. Jungwirth <pj@illuminatedcomputing.com> Reviewed-by: Peter Eisentraut <peter@eisentraut.org> Reviewed-by: jian he <jian.universality@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/CA+renyUApHgSZF9-nd-a0+OPGharLQLO=mDHcY4_qQ0+noCUVg@mail.gmail.com
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#define GIST_H
|
||||
|
||||
#include "access/itup.h"
|
||||
#include "access/stratnum.h"
|
||||
#include "access/transam.h"
|
||||
#include "access/xlog.h"
|
||||
#include "access/xlogdefs.h"
|
||||
@@ -246,4 +247,6 @@ typedef struct
|
||||
do { (e).key = (k); (e).rel = (r); (e).page = (pg); \
|
||||
(e).offset = (o); (e).leafkey = (l); } while (0)
|
||||
|
||||
extern StrategyNumber GistTranslateStratnum(Oid opclass, StrategyNumber strat);
|
||||
|
||||
#endif /* GIST_H */
|
||||
|
||||
@@ -57,6 +57,6 @@
|
||||
*/
|
||||
|
||||
/* yyyymmddN */
|
||||
#define CATALOG_VERSION_NO 202401201
|
||||
#define CATALOG_VERSION_NO 202401241
|
||||
|
||||
#endif
|
||||
|
||||
@@ -92,6 +92,7 @@ extern Oid index_create(Relation heapRelation,
|
||||
#define INDEX_CONSTR_CREATE_INIT_DEFERRED (1 << 2)
|
||||
#define INDEX_CONSTR_CREATE_UPDATE_INDEX (1 << 3)
|
||||
#define INDEX_CONSTR_CREATE_REMOVE_OLD_DEPS (1 << 4)
|
||||
#define INDEX_CONSTR_CREATE_WITHOUT_OVERLAPS (1 << 5)
|
||||
|
||||
extern Oid index_concurrently_create_copy(Relation heapRelation,
|
||||
Oid oldIndexId,
|
||||
|
||||
@@ -107,6 +107,12 @@ CATALOG(pg_constraint,2606,ConstraintRelationId)
|
||||
/* Has a local definition and cannot be inherited */
|
||||
bool connoinherit;
|
||||
|
||||
/*
|
||||
* For primary keys and unique constraints, signifies the last column uses
|
||||
* overlaps instead of equals.
|
||||
*/
|
||||
bool conwithoutoverlaps;
|
||||
|
||||
#ifdef CATALOG_VARLEN /* variable-length fields start here */
|
||||
|
||||
/*
|
||||
@@ -146,7 +152,8 @@ CATALOG(pg_constraint,2606,ConstraintRelationId)
|
||||
|
||||
/*
|
||||
* If an exclusion constraint, the OIDs of the exclusion operators for
|
||||
* each column of the constraint
|
||||
* each column of the constraint. Also set for unique constraints/primary
|
||||
* keys using WITHOUT OVERLAPS.
|
||||
*/
|
||||
Oid conexclop[1] BKI_LOOKUP(pg_operator);
|
||||
|
||||
@@ -238,6 +245,7 @@ extern Oid CreateConstraintEntry(const char *constraintName,
|
||||
bool conIsLocal,
|
||||
int conInhCount,
|
||||
bool conNoInherit,
|
||||
bool conWithoutOverlaps,
|
||||
bool is_internal);
|
||||
|
||||
extern bool ConstraintNameIsUsed(ConstraintCategory conCat, Oid objId,
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#ifndef DEFREM_H
|
||||
#define DEFREM_H
|
||||
|
||||
#include "access/stratnum.h"
|
||||
#include "catalog/objectaddress.h"
|
||||
#include "nodes/params.h"
|
||||
#include "parser/parse_node.h"
|
||||
@@ -44,10 +45,13 @@ extern char *ChooseRelationName(const char *name1, const char *name2,
|
||||
extern bool CheckIndexCompatible(Oid oldId,
|
||||
const char *accessMethodName,
|
||||
const List *attributeList,
|
||||
const List *exclusionOpNames);
|
||||
const List *exclusionOpNames,
|
||||
bool isWithoutOverlaps);
|
||||
extern Oid GetDefaultOpClass(Oid type_id, Oid am_id);
|
||||
extern Oid ResolveOpClass(const List *opclass, Oid attrType,
|
||||
const char *accessMethodName, Oid accessMethodId);
|
||||
extern void GetOperatorFromWellKnownStrategy(Oid opclass, Oid atttype,
|
||||
Oid *opid, StrategyNumber *strat);
|
||||
|
||||
/* commands/functioncmds.c */
|
||||
extern ObjectAddress CreateFunction(ParseState *pstate, CreateFunctionStmt *stmt);
|
||||
|
||||
@@ -2590,6 +2590,7 @@ typedef struct Constraint
|
||||
bool nulls_not_distinct; /* null treatment for UNIQUE constraints */
|
||||
List *keys; /* String nodes naming referenced key
|
||||
* column(s); also used for NOT NULL */
|
||||
bool without_overlaps; /* WITHOUT OVERLAPS specified */
|
||||
List *including; /* String nodes naming referenced nonkey
|
||||
* column(s) */
|
||||
|
||||
@@ -3219,6 +3220,7 @@ typedef struct IndexStmt
|
||||
bool nulls_not_distinct; /* null treatment for UNIQUE constraints */
|
||||
bool primary; /* is index a primary key? */
|
||||
bool isconstraint; /* is it for a pkey/unique constraint? */
|
||||
bool iswithoutoverlaps; /* is the constraint WITHOUT OVERLAPS? */
|
||||
bool deferrable; /* is the constraint DEFERRABLE? */
|
||||
bool initdeferred; /* is the constraint INITIALLY DEFERRED? */
|
||||
bool transformed; /* true when transformIndexStmt is finished */
|
||||
|
||||
Reference in New Issue
Block a user