mirror of
https://github.com/postgres/postgres.git
synced 2025-11-18 02:02:55 +03:00
Revert temporal primary keys and foreign keys
This feature set did not handle empty ranges correctly, and it's now
too late for PostgreSQL 17 to fix it.
The following commits are reverted:
6db4598fcb Add stratnum GiST support function
46a0cd4cef Add temporal PRIMARY KEY and UNIQUE constraints
86232a49a4 Fix comment on gist_stratnum_btree
030e10ff1a Rename pg_constraint.conwithoutoverlaps to conperiod
a88c800deb Use daterange and YMD in without_overlaps tests instead of tsrange.
5577a71fb0 Use half-open interval notation in without_overlaps tests
34768ee361 Add temporal FOREIGN KEY contraints
482e108cd3 Add test for REPLICA IDENTITY with a temporal key
c3db1f30cb doc: clarify PERIOD and WITHOUT OVERLAPS in CREATE TABLE
144c2ce0cc Fix ON CONFLICT DO NOTHING/UPDATE for temporal indexes
Discussion: https://www.postgresql.org/message-id/d0b64a7a-dfe4-4b84-a906-c7dedfa40a3e@eisentraut.org
This commit is contained in:
@@ -525,15 +525,14 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
|
||||
SetResetClause FunctionSetResetClause
|
||||
|
||||
%type <node> TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
|
||||
%type <node> columnDef columnOptions optionalPeriodName
|
||||
%type <node> columnDef columnOptions
|
||||
%type <defelt> def_elem reloption_elem old_aggr_elem operator_def_elem
|
||||
%type <node> def_arg columnElem where_clause where_or_current_clause
|
||||
a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
|
||||
columnref in_expr having_clause func_table xmltable array_expr
|
||||
OptWhereClause operator_def_arg
|
||||
%type <list> opt_column_and_period_list
|
||||
%type <list> rowsfrom_item rowsfrom_list opt_col_def_list
|
||||
%type <boolean> opt_ordinality opt_without_overlaps
|
||||
%type <boolean> opt_ordinality
|
||||
%type <list> ExclusionConstraintList ExclusionConstraintElem
|
||||
%type <list> func_arg_list func_arg_list_opt
|
||||
%type <node> func_arg_expr
|
||||
@@ -765,7 +764,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
|
||||
OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
|
||||
|
||||
PARALLEL PARAMETER PARSER PARTIAL PARTITION PARTITIONS PASSING PASSWORD PATH
|
||||
PERIOD PLACING PLAN PLANS POLICY
|
||||
PLACING PLAN PLANS POLICY
|
||||
POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
|
||||
PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
|
||||
|
||||
@@ -4194,7 +4193,7 @@ ConstraintElem:
|
||||
n->initially_valid = !n->skip_validation;
|
||||
$$ = (Node *) n;
|
||||
}
|
||||
| UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
|
||||
| UNIQUE opt_unique_null_treatment '(' columnList ')' opt_c_include opt_definition OptConsTableSpace
|
||||
ConstraintAttributeSpec
|
||||
{
|
||||
Constraint *n = makeNode(Constraint);
|
||||
@@ -4203,12 +4202,11 @@ ConstraintElem:
|
||||
n->location = @1;
|
||||
n->nulls_not_distinct = !$2;
|
||||
n->keys = $4;
|
||||
n->without_overlaps = $5;
|
||||
n->including = $7;
|
||||
n->options = $8;
|
||||
n->including = $6;
|
||||
n->options = $7;
|
||||
n->indexname = NULL;
|
||||
n->indexspace = $9;
|
||||
processCASbits($10, @10, "UNIQUE",
|
||||
n->indexspace = $8;
|
||||
processCASbits($9, @9, "UNIQUE",
|
||||
&n->deferrable, &n->initdeferred, NULL,
|
||||
NULL, yyscanner);
|
||||
$$ = (Node *) n;
|
||||
@@ -4229,7 +4227,7 @@ ConstraintElem:
|
||||
NULL, yyscanner);
|
||||
$$ = (Node *) n;
|
||||
}
|
||||
| PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
|
||||
| PRIMARY KEY '(' columnList ')' opt_c_include opt_definition OptConsTableSpace
|
||||
ConstraintAttributeSpec
|
||||
{
|
||||
Constraint *n = makeNode(Constraint);
|
||||
@@ -4237,12 +4235,11 @@ ConstraintElem:
|
||||
n->contype = CONSTR_PRIMARY;
|
||||
n->location = @1;
|
||||
n->keys = $4;
|
||||
n->without_overlaps = $5;
|
||||
n->including = $7;
|
||||
n->options = $8;
|
||||
n->including = $6;
|
||||
n->options = $7;
|
||||
n->indexname = NULL;
|
||||
n->indexspace = $9;
|
||||
processCASbits($10, @10, "PRIMARY KEY",
|
||||
n->indexspace = $8;
|
||||
processCASbits($9, @9, "PRIMARY KEY",
|
||||
&n->deferrable, &n->initdeferred, NULL,
|
||||
NULL, yyscanner);
|
||||
$$ = (Node *) n;
|
||||
@@ -4283,31 +4280,21 @@ ConstraintElem:
|
||||
NULL, yyscanner);
|
||||
$$ = (Node *) n;
|
||||
}
|
||||
| FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
|
||||
opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
|
||||
| FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
|
||||
opt_column_list key_match key_actions ConstraintAttributeSpec
|
||||
{
|
||||
Constraint *n = makeNode(Constraint);
|
||||
|
||||
n->contype = CONSTR_FOREIGN;
|
||||
n->location = @1;
|
||||
n->pktable = $8;
|
||||
n->pktable = $7;
|
||||
n->fk_attrs = $4;
|
||||
if ($5)
|
||||
{
|
||||
n->fk_attrs = lappend(n->fk_attrs, $5);
|
||||
n->fk_with_period = true;
|
||||
}
|
||||
n->pk_attrs = linitial($9);
|
||||
if (lsecond($9))
|
||||
{
|
||||
n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
|
||||
n->pk_with_period = true;
|
||||
}
|
||||
n->fk_matchtype = $10;
|
||||
n->fk_upd_action = ($11)->updateAction->action;
|
||||
n->fk_del_action = ($11)->deleteAction->action;
|
||||
n->fk_del_set_cols = ($11)->deleteAction->cols;
|
||||
processCASbits($12, @12, "FOREIGN KEY",
|
||||
n->pk_attrs = $8;
|
||||
n->fk_matchtype = $9;
|
||||
n->fk_upd_action = ($10)->updateAction->action;
|
||||
n->fk_del_action = ($10)->deleteAction->action;
|
||||
n->fk_del_set_cols = ($10)->deleteAction->cols;
|
||||
processCASbits($11, @11, "FOREIGN KEY",
|
||||
&n->deferrable, &n->initdeferred,
|
||||
&n->skip_validation, NULL,
|
||||
yyscanner);
|
||||
@@ -4374,11 +4361,6 @@ opt_no_inherit: NO INHERIT { $$ = true; }
|
||||
| /* EMPTY */ { $$ = false; }
|
||||
;
|
||||
|
||||
opt_without_overlaps:
|
||||
WITHOUT OVERLAPS { $$ = true; }
|
||||
| /*EMPTY*/ { $$ = false; }
|
||||
;
|
||||
|
||||
opt_column_list:
|
||||
'(' columnList ')' { $$ = $2; }
|
||||
| /*EMPTY*/ { $$ = NIL; }
|
||||
@@ -4389,16 +4371,6 @@ columnList:
|
||||
| columnList ',' columnElem { $$ = lappend($1, $3); }
|
||||
;
|
||||
|
||||
optionalPeriodName:
|
||||
',' PERIOD columnElem { $$ = $3; }
|
||||
| /*EMPTY*/ { $$ = NULL; }
|
||||
;
|
||||
|
||||
opt_column_and_period_list:
|
||||
'(' columnList optionalPeriodName ')' { $$ = list_make2($2, $3); }
|
||||
| /*EMPTY*/ { $$ = list_make2(NIL, NULL); }
|
||||
;
|
||||
|
||||
columnElem: ColId
|
||||
{
|
||||
$$ = (Node *) makeString($1);
|
||||
@@ -17793,7 +17765,6 @@ unreserved_keyword:
|
||||
| PASSING
|
||||
| PASSWORD
|
||||
| PATH
|
||||
| PERIOD
|
||||
| PLAN
|
||||
| PLANS
|
||||
| POLICY
|
||||
@@ -18420,7 +18391,6 @@ bare_label_keyword:
|
||||
| PASSING
|
||||
| PASSWORD
|
||||
| PATH
|
||||
| PERIOD
|
||||
| PLACING
|
||||
| PLAN
|
||||
| PLANS
|
||||
|
||||
@@ -1562,7 +1562,6 @@ generateClonedIndexStmt(RangeVar *heapRel, Relation source_idx,
|
||||
index->unique = idxrec->indisunique;
|
||||
index->nulls_not_distinct = idxrec->indnullsnotdistinct;
|
||||
index->primary = idxrec->indisprimary;
|
||||
index->iswithoutoverlaps = (idxrec->indisprimary || idxrec->indisunique) && idxrec->indisexclusion;
|
||||
index->transformed = true; /* don't need transformIndexStmt */
|
||||
index->concurrent = false;
|
||||
index->if_not_exists = false;
|
||||
@@ -1612,9 +1611,7 @@ generateClonedIndexStmt(RangeVar *heapRel, Relation source_idx,
|
||||
int nElems;
|
||||
int i;
|
||||
|
||||
Assert(conrec->contype == CONSTRAINT_EXCLUSION ||
|
||||
(index->iswithoutoverlaps &&
|
||||
(conrec->contype == CONSTRAINT_PRIMARY || conrec->contype == CONSTRAINT_UNIQUE)));
|
||||
Assert(conrec->contype == CONSTRAINT_EXCLUSION);
|
||||
/* Extract operator OIDs from the pg_constraint tuple */
|
||||
datum = SysCacheGetAttrNotNull(CONSTROID, ht_constr,
|
||||
Anum_pg_constraint_conexclop);
|
||||
@@ -2156,7 +2153,6 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
|
||||
}
|
||||
index->nulls_not_distinct = constraint->nulls_not_distinct;
|
||||
index->isconstraint = true;
|
||||
index->iswithoutoverlaps = constraint->without_overlaps;
|
||||
index->deferrable = constraint->deferrable;
|
||||
index->initdeferred = constraint->initdeferred;
|
||||
|
||||
@@ -2249,11 +2245,6 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
|
||||
errmsg("index \"%s\" is not valid", index_name),
|
||||
parser_errposition(cxt->pstate, constraint->location)));
|
||||
|
||||
/*
|
||||
* Today we forbid non-unique indexes, but we could permit GiST
|
||||
* indexes whose last entry is a range type and use that to create a
|
||||
* WITHOUT OVERLAPS constraint (i.e. a temporal constraint).
|
||||
*/
|
||||
if (!index_form->indisunique)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
|
||||
@@ -2542,23 +2533,6 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
|
||||
notnullcmds = lappend(notnullcmds, notnullcmd);
|
||||
}
|
||||
}
|
||||
|
||||
if (constraint->without_overlaps)
|
||||
{
|
||||
/*
|
||||
* This enforces that there is at least one equality column
|
||||
* besides the WITHOUT OVERLAPS columns. This is per SQL
|
||||
* standard. XXX Do we need this?
|
||||
*/
|
||||
if (list_length(constraint->keys) < 2)
|
||||
ereport(ERROR,
|
||||
errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("constraint using WITHOUT OVERLAPS needs at least two columns"));
|
||||
|
||||
/* WITHOUT OVERLAPS requires a GiST index */
|
||||
index->accessMethod = "gist";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user