Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6f8bb7c

Browse files
committed
Revert structural changes to not-null constraints
There are some problems with the new way to handle these constraints that were detected at the last minute, and require fixes that appear too invasive to be doing this late in the cycle. Revert this (again) for now, we'll try again with these problems fixed. The following commits are reverted: b0e96f3 Catalog not-null constraints 9b581c5 Disallow changing NO INHERIT status of a not-null constraint d0ec2dd Fix not-null constraint test ac22a95 Move privilege check to the right place b0f7dd9 Check stack depth in new recursive functions 3af7217 Update information_schema definition for not-null constraints c370910 Fix propagating attnotnull in multiple inheritance d9f686a Fix restore of not-null constraints with inheritance d72d32f Don't try to assign smart names to constraints 0cd7112 Better handle indirect constraint drops 13daa33 Disallow NO INHERIT not-null constraints on partitioned tables d45597f Disallow direct change of NO INHERIT of not-null constraints 21ac38f Fix inconsistencies in error messages Discussion: https://postgr.es/m/202405110940.joxlqcx4dogd@alvherre.pgsql
1 parent e89f4c6 commit 6f8bb7c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+709
-4600
lines changed

contrib/sepgsql/expected/alter.out

+3
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ LOG: SELinux: allowed { setattr } scontext=unconfined_u:unconfined_r:sepgsql_re
164164
LOG: SELinux: allowed { setattr } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="regtest_schema.regtest_table_2.b" permissive=0
165165
ALTER TABLE regtest_table ALTER b DROP NOT NULL;
166166
LOG: SELinux: allowed { setattr } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="regtest_schema_2.regtest_table.b" permissive=0
167+
LOG: SELinux: allowed { setattr } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="regtest_schema.regtest_table_2.b" permissive=0
167168
ALTER TABLE regtest_table ALTER b SET STATISTICS -1;
168169
LOG: SELinux: allowed { setattr } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="regtest_schema_2.regtest_table.b" permissive=0
169170
LOG: SELinux: allowed { setattr } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="regtest_schema.regtest_table_2.b" permissive=0
@@ -248,6 +249,8 @@ LOG: SELinux: allowed { setattr } scontext=unconfined_u:unconfined_r:sepgsql_re
248249
LOG: SELinux: allowed { setattr } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="regtest_schema.regtest_ptable_1_tens.p" permissive=0
249250
ALTER TABLE regtest_ptable ALTER p DROP NOT NULL;
250251
LOG: SELinux: allowed { setattr } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="regtest_schema_2.regtest_ptable.p" permissive=0
252+
LOG: SELinux: allowed { setattr } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="regtest_schema_2.regtest_table_part.p" permissive=0
253+
LOG: SELinux: allowed { setattr } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="regtest_schema.regtest_ptable_1_tens.p" permissive=0
251254
ALTER TABLE regtest_ptable ALTER p SET STATISTICS -1;
252255
LOG: SELinux: allowed { setattr } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="regtest_schema_2.regtest_ptable.p" permissive=0
253256
LOG: SELinux: allowed { setattr } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="regtest_schema_2.regtest_table_part.p" permissive=0

contrib/sepgsql/expected/ddl.out

-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ LOG: SELinux: allowed { search } scontext=unconfined_u:unconfined_r:sepgsql_reg
4949
LOG: SELinux: allowed { search } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_schema_t:s0 tclass=db_schema name="regtest_schema" permissive=0
5050
LOG: SELinux: allowed { search } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=system_u:object_r:sepgsql_schema_t:s0 tclass=db_schema name="pg_catalog" permissive=0
5151
LOG: SELinux: allowed { search } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_schema_t:s0 tclass=db_schema name="regtest_schema" permissive=0
52-
LOG: SELinux: allowed { search } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_schema_t:s0 tclass=db_schema name="regtest_schema" permissive=0
5352
LOG: SELinux: allowed { add_name } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_schema_t:s0 tclass=db_schema name="regtest_schema" permissive=0
5453
LOG: SELinux: allowed { setattr } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_table name="regtest_schema.regtest_table" permissive=0
5554
LOG: SELinux: allowed { search } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_schema_t:s0 tclass=db_schema name="regtest_schema" permissive=0
@@ -285,7 +284,6 @@ LOG: SELinux: allowed { create } scontext=unconfined_u:unconfined_r:sepgsql_reg
285284
LOG: SELinux: allowed { create } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="regtest_schema.regtest_table_4.y" permissive=0
286285
LOG: SELinux: allowed { create } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_column name="regtest_schema.regtest_table_4.z" permissive=0
287286
LOG: SELinux: allowed { search } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_schema_t:s0 tclass=db_schema name="regtest_schema" permissive=0
288-
LOG: SELinux: allowed { search } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_schema_t:s0 tclass=db_schema name="regtest_schema" permissive=0
289287
LOG: SELinux: allowed { add_name } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_schema_t:s0 tclass=db_schema name="regtest_schema" permissive=0
290288
LOG: SELinux: allowed { setattr } scontext=unconfined_u:unconfined_r:sepgsql_regtest_superuser_t:s0 tcontext=unconfined_u:object_r:sepgsql_table_t:s0 tclass=db_table name="regtest_schema.regtest_table_4" permissive=0
291289
CREATE INDEX regtest_index_tbl4_y ON regtest_table_4(y);

contrib/test_decoding/expected/ddl.out

-12
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,6 @@ WITH (user_catalog_table = true)
492492
options | text[] | | | | extended | |
493493
Indexes:
494494
"replication_metadata_pkey" PRIMARY KEY, btree (id)
495-
Not-null constraints:
496-
"replication_metadata_id_not_null" NOT NULL "id"
497-
"replication_metadata_relation_not_null" NOT NULL "relation"
498495
Options: user_catalog_table=true
499496

500497
INSERT INTO replication_metadata(relation, options)
@@ -509,9 +506,6 @@ ALTER TABLE replication_metadata RESET (user_catalog_table);
509506
options | text[] | | | | extended | |
510507
Indexes:
511508
"replication_metadata_pkey" PRIMARY KEY, btree (id)
512-
Not-null constraints:
513-
"replication_metadata_id_not_null" NOT NULL "id"
514-
"replication_metadata_relation_not_null" NOT NULL "relation"
515509

516510
INSERT INTO replication_metadata(relation, options)
517511
VALUES ('bar', ARRAY['a', 'b']);
@@ -525,9 +519,6 @@ ALTER TABLE replication_metadata SET (user_catalog_table = true);
525519
options | text[] | | | | extended | |
526520
Indexes:
527521
"replication_metadata_pkey" PRIMARY KEY, btree (id)
528-
Not-null constraints:
529-
"replication_metadata_id_not_null" NOT NULL "id"
530-
"replication_metadata_relation_not_null" NOT NULL "relation"
531522
Options: user_catalog_table=true
532523

533524
INSERT INTO replication_metadata(relation, options)
@@ -547,9 +538,6 @@ ALTER TABLE replication_metadata SET (user_catalog_table = false);
547538
rewritemeornot | integer | | | | plain | |
548539
Indexes:
549540
"replication_metadata_pkey" PRIMARY KEY, btree (id)
550-
Not-null constraints:
551-
"replication_metadata_id_not_null" NOT NULL "id"
552-
"replication_metadata_relation_not_null" NOT NULL "relation"
553541
Options: user_catalog_table=false
554542

555543
INSERT INTO replication_metadata(relation, options)

doc/src/sgml/catalogs.sgml

+8-5
Original file line numberDiff line numberDiff line change
@@ -1270,8 +1270,7 @@
12701270
<structfield>attnotnull</structfield> <type>bool</type>
12711271
</para>
12721272
<para>
1273-
This column is marked not-null, either by a not-null constraint
1274-
or a primary key.
1273+
This represents a not-null constraint.
12751274
</para></entry>
12761275
</row>
12771276

@@ -2502,10 +2501,14 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
25022501
</indexterm>
25032502

25042503
<para>
2505-
The catalog <structname>pg_constraint</structname> stores check, not-null,
2506-
primary key, unique, foreign key, and exclusion constraints on tables.
2504+
The catalog <structname>pg_constraint</structname> stores check, primary
2505+
key, unique, foreign key, and exclusion constraints on tables, as well as
2506+
not-null constraints on domains.
25072507
(Column constraints are not treated specially. Every column constraint is
25082508
equivalent to some table constraint.)
2509+
Not-null constraints on relations are represented in the
2510+
<link linkend="catalog-pg-attribute"><structname>pg_attribute</structname></link>
2511+
catalog, not here.
25092512
</para>
25102513

25112514
<para>
@@ -2567,7 +2570,7 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
25672570
<para>
25682571
<literal>c</literal> = check constraint,
25692572
<literal>f</literal> = foreign key constraint,
2570-
<literal>n</literal> = not-null constraint,
2573+
<literal>f</literal> = not-null constraint (domains only),
25712574
<literal>p</literal> = primary key constraint,
25722575
<literal>u</literal> = unique constraint,
25732576
<literal>t</literal> = constraint trigger,

doc/src/sgml/ddl.sgml

+11-44
Original file line numberDiff line numberDiff line change
@@ -763,38 +763,17 @@ CREATE TABLE products (
763763
price numeric
764764
);
765765
</programlisting>
766-
An explicit constraint name can also be specified, for example:
767-
<programlisting>
768-
CREATE TABLE products (
769-
product_no integer NOT NULL,
770-
name text <emphasis>CONSTRAINT products_name_not_null</emphasis> NOT NULL,
771-
price numeric
772-
);
773-
</programlisting>
774-
</para>
775-
776-
<para>
777-
A not-null constraint is usually written as a column constraint. The
778-
syntax for writing it as a table constraint is
779-
<programlisting>
780-
CREATE TABLE products (
781-
product_no integer,
782-
name text,
783-
price numeric,
784-
<emphasis>NOT NULL product_no</emphasis>,
785-
<emphasis>NOT NULL name</emphasis>
786-
);
787-
</programlisting>
788-
But this syntax is not standard and mainly intended for use by
789-
<application>pg_dump</application>.
790766
</para>
791767

792768
<para>
793-
A not-null constraint is functionally equivalent to creating a check
769+
A not-null constraint is always written as a column constraint. A
770+
not-null constraint is functionally equivalent to creating a check
794771
constraint <literal>CHECK (<replaceable>column_name</replaceable>
795772
IS NOT NULL)</literal>, but in
796773
<productname>PostgreSQL</productname> creating an explicit
797-
not-null constraint is more efficient.
774+
not-null constraint is more efficient. The drawback is that you
775+
cannot give explicit names to not-null constraints created this
776+
way.
798777
</para>
799778

800779
<para>
@@ -811,10 +790,6 @@ CREATE TABLE products (
811790
order the constraints are checked.
812791
</para>
813792

814-
<para>
815-
However, a column can have at most one explicit not-null constraint.
816-
</para>
817-
818793
<para>
819794
The <literal>NOT NULL</literal> constraint has an inverse: the
820795
<literal>NULL</literal> constraint. This does not mean that the
@@ -1008,7 +983,7 @@ CREATE TABLE example (
1008983

1009984
<para>
1010985
A table can have at most one primary key. (There can be any number
1011-
of unique constraints, which combined with not-null constraints are functionally almost the
986+
of unique and not-null constraints, which are functionally almost the
1012987
same thing, but only one can be identified as the primary key.)
1013988
Relational database theory
1014989
dictates that every table must have a primary key. This rule is
@@ -1668,16 +1643,11 @@ ALTER TABLE products ADD CHECK (name &lt;&gt; '');
16681643
ALTER TABLE products ADD CONSTRAINT some_name UNIQUE (product_no);
16691644
ALTER TABLE products ADD FOREIGN KEY (product_group_id) REFERENCES product_groups;
16701645
</programlisting>
1671-
</para>
1672-
1673-
<para>
1674-
To add a not-null constraint, which is normally not written as a table
1675-
constraint, this special syntax is available:
1646+
To add a not-null constraint, which cannot be written as a table
1647+
constraint, use this syntax:
16761648
<programlisting>
16771649
ALTER TABLE products ALTER COLUMN product_no SET NOT NULL;
16781650
</programlisting>
1679-
This command silently does nothing if the column already has a
1680-
not-null constraint.
16811651
</para>
16821652

16831653
<para>
@@ -1718,15 +1688,12 @@ ALTER TABLE products DROP CONSTRAINT some_name;
17181688
</para>
17191689

17201690
<para>
1721-
Simplified syntax is available to drop a not-null constraint:
1691+
This works the same for all constraint types except not-null
1692+
constraints. To drop a not-null constraint use:
17221693
<programlisting>
17231694
ALTER TABLE products ALTER COLUMN product_no DROP NOT NULL;
17241695
</programlisting>
1725-
This mirrors the <literal>SET NOT NULL</literal> syntax for adding a
1726-
not-null constraint. This command will silently do nothing if the column
1727-
does not have a not-null constraint. (Recall that a column can have at
1728-
most one not-null constraint, so it is never ambiguous which constraint
1729-
this command acts on.)
1696+
(Recall that not-null constraints do not have names.)
17301697
</para>
17311698
</sect2>
17321699

doc/src/sgml/ref/alter_table.sgml

+3-10
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
105105
<phrase>and <replaceable class="parameter">column_constraint</replaceable> is:</phrase>
106106

107107
[ CONSTRAINT <replaceable class="parameter">constraint_name</replaceable> ]
108-
{ NOT NULL [ NO INHERIT ] |
108+
{ NOT NULL |
109109
NULL |
110110
CHECK ( <replaceable class="parameter">expression</replaceable> ) [ NO INHERIT ] |
111111
DEFAULT <replaceable>default_expr</replaceable> |
@@ -121,7 +121,6 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
121121

122122
[ CONSTRAINT <replaceable class="parameter">constraint_name</replaceable> ]
123123
{ CHECK ( <replaceable class="parameter">expression</replaceable> ) [ NO INHERIT ] |
124-
NOT NULL <replaceable class="parameter">column_name</replaceable> [ NO INHERIT ] |
125124
UNIQUE [ NULLS [ NOT ] DISTINCT ] ( <replaceable class="parameter">column_name</replaceable> [, ... ] ) <replaceable class="parameter">index_parameters</replaceable> |
126125
PRIMARY KEY ( <replaceable class="parameter">column_name</replaceable> [, ... ] ) <replaceable class="parameter">index_parameters</replaceable> |
127126
EXCLUDE [ USING <replaceable class="parameter">index_method</replaceable> ] ( <replaceable class="parameter">exclude_element</replaceable> WITH <replaceable class="parameter">operator</replaceable> [, ... ] ) <replaceable class="parameter">index_parameters</replaceable> [ WHERE ( <replaceable class="parameter">predicate</replaceable> ) ] |
@@ -1942,17 +1941,11 @@ ALTER TABLE sales_list MERGE PARTITIONS (sales_west, sales_east, sales_central)
19421941
<title>Compatibility</title>
19431942

19441943
<para>
1945-
The forms <literal>ADD [COLUMN]</literal>,
1944+
The forms <literal>ADD</literal> (without <literal>USING INDEX</literal>),
19461945
<literal>DROP [COLUMN]</literal>, <literal>DROP IDENTITY</literal>, <literal>RESTART</literal>,
19471946
<literal>SET DEFAULT</literal>, <literal>SET DATA TYPE</literal> (without <literal>USING</literal>),
19481947
<literal>SET GENERATED</literal>, and <literal>SET <replaceable>sequence_option</replaceable></literal>
1949-
conform with the SQL standard.
1950-
The form <literal>ADD <replaceable>table_constraint</replaceable></literal>
1951-
conforms with the SQL standard when the <literal>USING INDEX</literal> and
1952-
<literal>NOT VALID</literal> clauses are omitted and the constraint type is
1953-
one of <literal>CHECK</literal>, <literal>UNIQUE</literal>, <literal>PRIMARY KEY</literal>,
1954-
or <literal>REFERENCES</literal>.
1955-
The other forms are
1948+
conform with the SQL standard. The other forms are
19561949
<productname>PostgreSQL</productname> extensions of the SQL standard.
19571950
Also, the ability to specify more than one manipulation in a single
19581951
<command>ALTER TABLE</command> command is an extension.

doc/src/sgml/ref/create_table.sgml

+7-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
7777

7878
[ CONSTRAINT <replaceable class="parameter">constraint_name</replaceable> ]
7979
{ CHECK ( <replaceable class="parameter">expression</replaceable> ) [ NO INHERIT ] |
80-
NOT NULL <replaceable class="parameter">column_name</replaceable> [ NO INHERIT ] |
8180
UNIQUE [ NULLS [ NOT ] DISTINCT ] ( <replaceable class="parameter">column_name</replaceable> [, ... ] [, <replaceable class="parameter">column_name</replaceable> WITHOUT OVERLAPS ] ) <replaceable class="parameter">index_parameters</replaceable> |
8281
PRIMARY KEY ( <replaceable class="parameter">column_name</replaceable> [, ... ] [, <replaceable class="parameter">column_name</replaceable> WITHOUT OVERLAPS ] ) <replaceable class="parameter">index_parameters</replaceable> |
8382
EXCLUDE [ USING <replaceable class="parameter">index_method</replaceable> ] ( <replaceable class="parameter">exclude_element</replaceable> WITH <replaceable class="parameter">operator</replaceable> [, ... ] ) <replaceable class="parameter">index_parameters</replaceable> [ WHERE ( <replaceable class="parameter">predicate</replaceable> ) ] |
@@ -2392,6 +2391,13 @@ CREATE TABLE cities_partdef
23922391
constraint, and index names must be unique across all relations within
23932392
the same schema.
23942393
</para>
2394+
2395+
<para>
2396+
Currently, <productname>PostgreSQL</productname> does not record names
2397+
for not-null constraints at all, so they are not
2398+
subject to the uniqueness restriction. This might change in a future
2399+
release.
2400+
</para>
23952401
</refsect2>
23962402

23972403
<refsect2>

0 commit comments

Comments
 (0)