Re: cataloguing NOT NULL constraints
Alvaro Herrera <alvherre@alvh.no-ip.org>
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Revert structural changes to not-null constraints
- 6f8bb7c1e961 17.0 landed
-
Fix inconsistencies in error messages
- 21ac38f498b3 17.0 landed
-
Disallow direct change of NO INHERIT of not-null constraints
- d45597f72fe5 17.0 landed
-
Disallow NO INHERIT not-null constraints on partitioned tables
- 13daa33fa5a6 17.0 landed
-
Better handle indirect constraint drops
- 0cd711271d42 17.0 cited
-
Don't try to assign smart names to constraints
- d72d32f52d26 17.0 cited
-
Fix restore of not-null constraints with inheritance
- d9f686a72ee9 17.0 landed
-
ATTACH PARTITION: Don't match a PK with a UNIQUE constraint
- cee8db3f680b 17.0 landed
-
Fix propagating attnotnull in multiple inheritance
- c3709100be73 17.0 landed
-
Check stack depth in new recursive functions
- b0f7dd915bca 17.0 landed
-
Move privilege check to the right place
- ac22a9545ca9 17.0 cited
-
Update information_schema definition for not-null constraints
- 3af721794272 17.0 landed
-
Fix not-null constraint test
- d0ec2ddbe088 17.0 landed
-
Disallow changing NO INHERIT status of a not-null constraint
- 9b581c534186 17.0 cited
-
Catalog not-null constraints
- b0e96f311985 17.0 cited
-
parallel_schedule: add comment on event_trigger test dependency
- c8e43c22be27 17.0 landed
-
Revert "Catalog NOT NULL constraints" and fallout
- 9ce04b50e120 16.0 landed
-
Adjust contrib/sepgsql regression test expected outputs.
- 76c111a7f166 16.0 landed
-
Fix table name clash in recently introduced test
- 728015a47016 16.0 landed
-
Catalog NOT NULL constraints
- e056c557aef4 16.0 landed
-
Change the rules for inherited CHECK constraints to be essentially the same
- cd902b331dc4 8.4.0 cited
On 2023-Jul-28, Alvaro Herrera wrote:
> To avoid that, one option would be to make this NN constraint
> undroppable ... but I don't see how. One option might be to add a
> pg_depend row that links the NOT NULL constraint to its PK constraint.
> But this will be a strange case that occurs nowhere else, since other
> NOT NULL constraint don't have such pg_depend rows. Also, I won't know
> how pg_dump likes this until I implement it.
I've been completing the implementation for this. It seems to work
reasonably okay; pg_dump requires somewhat strange contortions, but they
are similar to what we do in flagInhTables already, so I don't feel too
bad about that.
What *is* odd and bothersome is that it also causes a problem dropping
the child table. For example,
CREATE TABLE parent (a int primary key);
CREATE TABLE child () INHERITS (parent);
\d+ child
Tabla «public.child»
Columna │ Tipo │ Ordenamiento │ Nulable │ Por omisión │ Almacenamiento │ Compresión │ Estadísticas │ Descripción
─────────┼─────────┼──────────────┼──────────┼─────────────┼────────────────┼────────────┼──────────────┼─────────────
a │ integer │ │ not null │ │ plain │ │ │
Not null constraints:
"child_a_not_null" NOT NULL "a"
Hereda: parent
Método de acceso: heap
This is the behavior that I think we wanted to prevent drop of the child
constraint, and it seems okay to me:
=# alter table child drop constraint child_a_not_null;
ERROR: cannot drop constraint child_a_not_null on table child because constraint parent_pkey on table parent requires it
SUGERENCIA: You can drop constraint parent_pkey on table parent instead.
But the problem is this:
=# drop table child;
ERROR: cannot drop table child because other objects depend on it
DETALLE: constraint parent_pkey on table parent depends on table child
SUGERENCIA: Use DROP ... CASCADE to drop the dependent objects too.
To be clear, what my patch is doing is add one new dependency:
dep │ ref │ deptype
────────────────────────────────────────────┼────────────────────────────────────────┼─────────
type foo │ table foo │ i
table foo │ schema public │ n
constraint foo_pkey on table foo │ column a of table foo │ a
type bar │ table bar │ i
table bar │ schema public │ n
table bar │ table foo │ n
constraint bar_a_not_null on table bar │ column a of table bar │ a
constraint child_a_not_null on table child │ column a of table child │ a
constraint child_a_not_null on table child │ constraint parent_pkey on table parent │ i
the last row here is what is new. I'm not sure what's the right fix.
Maybe I need to invert the direction of that dependency.
Even with that fixed, I'd still need to write more code so that ALTER
TABLE INHERIT adds the link (I already patched the DROP INHERIT part).
Not sure what else might I be missing.
Separately, I also noticed that some code that's currently
dropconstraint_internal needs to be moved to DropConstraintById, because
if the PK is dropped for some other reason than ALTER TABLE DROP
CONSTRAINT, some ancillary actions are not taken.
Sigh.
--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
Are you not unsure you want to delete Firefox?
[Not unsure] [Not not unsure] [Cancel]
http://smylers.hates-software.com/2008/01/03/566e45b2.html