mirror of
https://github.com/postgres/postgres.git
synced 2025-04-22 23:02:54 +03:00
connoinherit may be true only for CHECK constraints
The code was setting it true for other constraints, which is bogus. Doing so caused bogus catalog entries for such constraints, and in particular caused an error to be raised when trying to drop a constraint of types other than CHECK from a table that has children, such as reported in bug #6712. In 9.2, additionally ignore connoinherit=true for other constraint types, to avoid having to force initdb; existing databases might already contain bogus catalog entries. Includes a catversion bump (in HEAD only). Bug report from Miroslav Šulc Analysis from Amit Kapila and Noah Misch; Amit also contributed the patch.
This commit is contained in:
parent
8e617e29aa
commit
f5bcd398ad
@ -1154,7 +1154,7 @@ index_constraint_create(Relation heapRelation,
|
|||||||
NULL,
|
NULL,
|
||||||
true, /* islocal */
|
true, /* islocal */
|
||||||
0, /* inhcount */
|
0, /* inhcount */
|
||||||
false); /* noinherit */
|
true); /* noinherit */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Register the index as internally dependent on the constraint.
|
* Register the index as internally dependent on the constraint.
|
||||||
|
@ -6039,7 +6039,7 @@ ATAddForeignKeyConstraint(AlteredTableInfo *tab, Relation rel,
|
|||||||
NULL,
|
NULL,
|
||||||
true, /* islocal */
|
true, /* islocal */
|
||||||
0, /* inhcount */
|
0, /* inhcount */
|
||||||
false); /* isnoinherit */
|
true); /* isnoinherit */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create the triggers that will enforce the constraint.
|
* Create the triggers that will enforce the constraint.
|
||||||
|
@ -459,7 +459,7 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
|
|||||||
NULL,
|
NULL,
|
||||||
true, /* islocal */
|
true, /* islocal */
|
||||||
0, /* inhcount */
|
0, /* inhcount */
|
||||||
false); /* isnoinherit */
|
true); /* isnoinherit */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -53,6 +53,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* yyyymmddN */
|
/* yyyymmddN */
|
||||||
#define CATALOG_VERSION_NO 201207181
|
#define CATALOG_VERSION_NO 201207201
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -969,6 +969,123 @@ DETAIL: drop cascades to table inht2
|
|||||||
drop cascades to table inhts
|
drop cascades to table inhts
|
||||||
drop cascades to table inht3
|
drop cascades to table inht3
|
||||||
drop cascades to table inht4
|
drop cascades to table inht4
|
||||||
|
-- Test non-inheritable indices [UNIQUE, EXCLUDE] contraints
|
||||||
|
CREATE TABLE test_constraints (id int, val1 varchar, val2 int, UNIQUE(val1, val2));
|
||||||
|
CREATE TABLE test_constraints_inh () INHERITS (test_constraints);
|
||||||
|
\d+ test_constraints
|
||||||
|
Table "public.test_constraints"
|
||||||
|
Column | Type | Modifiers | Storage | Stats target | Description
|
||||||
|
--------+-------------------+-----------+----------+--------------+-------------
|
||||||
|
id | integer | | plain | |
|
||||||
|
val1 | character varying | | extended | |
|
||||||
|
val2 | integer | | plain | |
|
||||||
|
Indexes:
|
||||||
|
"test_constraints_val1_val2_key" UNIQUE CONSTRAINT, btree (val1, val2)
|
||||||
|
Child tables: test_constraints_inh
|
||||||
|
Has OIDs: no
|
||||||
|
|
||||||
|
ALTER TABLE ONLY test_constraints DROP CONSTRAINT test_constraints_val1_val2_key;
|
||||||
|
\d+ test_constraints
|
||||||
|
Table "public.test_constraints"
|
||||||
|
Column | Type | Modifiers | Storage | Stats target | Description
|
||||||
|
--------+-------------------+-----------+----------+--------------+-------------
|
||||||
|
id | integer | | plain | |
|
||||||
|
val1 | character varying | | extended | |
|
||||||
|
val2 | integer | | plain | |
|
||||||
|
Child tables: test_constraints_inh
|
||||||
|
Has OIDs: no
|
||||||
|
|
||||||
|
\d+ test_constraints_inh
|
||||||
|
Table "public.test_constraints_inh"
|
||||||
|
Column | Type | Modifiers | Storage | Stats target | Description
|
||||||
|
--------+-------------------+-----------+----------+--------------+-------------
|
||||||
|
id | integer | | plain | |
|
||||||
|
val1 | character varying | | extended | |
|
||||||
|
val2 | integer | | plain | |
|
||||||
|
Inherits: test_constraints
|
||||||
|
Has OIDs: no
|
||||||
|
|
||||||
|
DROP TABLE test_constraints_inh;
|
||||||
|
DROP TABLE test_constraints;
|
||||||
|
CREATE TABLE circles (
|
||||||
|
c circle,
|
||||||
|
EXCLUDE USING gist (c WITH &&)
|
||||||
|
);
|
||||||
|
CREATE TABLE circles_inh () INHERITS (circles);
|
||||||
|
\d+ circles
|
||||||
|
Table "public.circles"
|
||||||
|
Column | Type | Modifiers | Storage | Stats target | Description
|
||||||
|
--------+--------+-----------+---------+--------------+-------------
|
||||||
|
c | circle | | plain | |
|
||||||
|
Indexes:
|
||||||
|
"circles_c_excl" EXCLUDE USING gist (c WITH &&)
|
||||||
|
Child tables: circles_inh
|
||||||
|
Has OIDs: no
|
||||||
|
|
||||||
|
ALTER TABLE circles DROP CONSTRAINT circles_c_excl;
|
||||||
|
\d+ circles
|
||||||
|
Table "public.circles"
|
||||||
|
Column | Type | Modifiers | Storage | Stats target | Description
|
||||||
|
--------+--------+-----------+---------+--------------+-------------
|
||||||
|
c | circle | | plain | |
|
||||||
|
Child tables: circles_inh
|
||||||
|
Has OIDs: no
|
||||||
|
|
||||||
|
\d+ circles_inh
|
||||||
|
Table "public.circles_inh"
|
||||||
|
Column | Type | Modifiers | Storage | Stats target | Description
|
||||||
|
--------+--------+-----------+---------+--------------+-------------
|
||||||
|
c | circle | | plain | |
|
||||||
|
Inherits: circles
|
||||||
|
Has OIDs: no
|
||||||
|
|
||||||
|
DROP TABLE circles_inh;
|
||||||
|
DROP TABLE circles;
|
||||||
|
-- Test non-inheritable foreign key contraints
|
||||||
|
CREATE TABLE test_primary_constraints(id int PRIMARY KEY);
|
||||||
|
CREATE TABLE test_foreign_constraints(id1 int REFERENCES test_primary_constraints(id));
|
||||||
|
CREATE TABLE test_foreign_constraints_inh () INHERITS (test_foreign_constraints);
|
||||||
|
\d+ test_primary_constraints
|
||||||
|
Table "public.test_primary_constraints"
|
||||||
|
Column | Type | Modifiers | Storage | Stats target | Description
|
||||||
|
--------+---------+-----------+---------+--------------+-------------
|
||||||
|
id | integer | not null | plain | |
|
||||||
|
Indexes:
|
||||||
|
"test_primary_constraints_pkey" PRIMARY KEY, btree (id)
|
||||||
|
Referenced by:
|
||||||
|
TABLE "test_foreign_constraints" CONSTRAINT "test_foreign_constraints_id1_fkey" FOREIGN KEY (id1) REFERENCES test_primary_constraints(id)
|
||||||
|
Has OIDs: no
|
||||||
|
|
||||||
|
\d+ test_foreign_constraints
|
||||||
|
Table "public.test_foreign_constraints"
|
||||||
|
Column | Type | Modifiers | Storage | Stats target | Description
|
||||||
|
--------+---------+-----------+---------+--------------+-------------
|
||||||
|
id1 | integer | | plain | |
|
||||||
|
Foreign-key constraints:
|
||||||
|
"test_foreign_constraints_id1_fkey" FOREIGN KEY (id1) REFERENCES test_primary_constraints(id)
|
||||||
|
Child tables: test_foreign_constraints_inh
|
||||||
|
Has OIDs: no
|
||||||
|
|
||||||
|
ALTER TABLE test_foreign_constraints DROP CONSTRAINT test_foreign_constraints_id1_fkey;
|
||||||
|
\d+ test_foreign_constraints
|
||||||
|
Table "public.test_foreign_constraints"
|
||||||
|
Column | Type | Modifiers | Storage | Stats target | Description
|
||||||
|
--------+---------+-----------+---------+--------------+-------------
|
||||||
|
id1 | integer | | plain | |
|
||||||
|
Child tables: test_foreign_constraints_inh
|
||||||
|
Has OIDs: no
|
||||||
|
|
||||||
|
\d+ test_foreign_constraints_inh
|
||||||
|
Table "public.test_foreign_constraints_inh"
|
||||||
|
Column | Type | Modifiers | Storage | Stats target | Description
|
||||||
|
--------+---------+-----------+---------+--------------+-------------
|
||||||
|
id1 | integer | | plain | |
|
||||||
|
Inherits: test_foreign_constraints
|
||||||
|
Has OIDs: no
|
||||||
|
|
||||||
|
DROP TABLE test_foreign_constraints_inh;
|
||||||
|
DROP TABLE test_foreign_constraints;
|
||||||
|
DROP TABLE test_primary_constraints;
|
||||||
--
|
--
|
||||||
-- Test parameterized append plans for inheritance trees
|
-- Test parameterized append plans for inheritance trees
|
||||||
--
|
--
|
||||||
|
@ -291,6 +291,42 @@ SELECT a.attrelid::regclass, a.attname, a.attinhcount, e.expected
|
|||||||
|
|
||||||
DROP TABLE inht1, inhs1 CASCADE;
|
DROP TABLE inht1, inhs1 CASCADE;
|
||||||
|
|
||||||
|
|
||||||
|
-- Test non-inheritable indices [UNIQUE, EXCLUDE] contraints
|
||||||
|
CREATE TABLE test_constraints (id int, val1 varchar, val2 int, UNIQUE(val1, val2));
|
||||||
|
CREATE TABLE test_constraints_inh () INHERITS (test_constraints);
|
||||||
|
\d+ test_constraints
|
||||||
|
ALTER TABLE ONLY test_constraints DROP CONSTRAINT test_constraints_val1_val2_key;
|
||||||
|
\d+ test_constraints
|
||||||
|
\d+ test_constraints_inh
|
||||||
|
DROP TABLE test_constraints_inh;
|
||||||
|
DROP TABLE test_constraints;
|
||||||
|
|
||||||
|
CREATE TABLE circles (
|
||||||
|
c circle,
|
||||||
|
EXCLUDE USING gist (c WITH &&)
|
||||||
|
);
|
||||||
|
CREATE TABLE circles_inh () INHERITS (circles);
|
||||||
|
\d+ circles
|
||||||
|
ALTER TABLE circles DROP CONSTRAINT circles_c_excl;
|
||||||
|
\d+ circles
|
||||||
|
\d+ circles_inh
|
||||||
|
DROP TABLE circles_inh;
|
||||||
|
DROP TABLE circles;
|
||||||
|
|
||||||
|
-- Test non-inheritable foreign key contraints
|
||||||
|
CREATE TABLE test_primary_constraints(id int PRIMARY KEY);
|
||||||
|
CREATE TABLE test_foreign_constraints(id1 int REFERENCES test_primary_constraints(id));
|
||||||
|
CREATE TABLE test_foreign_constraints_inh () INHERITS (test_foreign_constraints);
|
||||||
|
\d+ test_primary_constraints
|
||||||
|
\d+ test_foreign_constraints
|
||||||
|
ALTER TABLE test_foreign_constraints DROP CONSTRAINT test_foreign_constraints_id1_fkey;
|
||||||
|
\d+ test_foreign_constraints
|
||||||
|
\d+ test_foreign_constraints_inh
|
||||||
|
DROP TABLE test_foreign_constraints_inh;
|
||||||
|
DROP TABLE test_foreign_constraints;
|
||||||
|
DROP TABLE test_primary_constraints;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Test parameterized append plans for inheritance trees
|
-- Test parameterized append plans for inheritance trees
|
||||||
--
|
--
|
||||||
|
Loading…
x
Reference in New Issue
Block a user