postgresql/src/backend/commands
Alvaro Herrera 0cd711271d
Better handle indirect constraint drops
It is possible for certain cases to remove not-null constraints without
maintaining the attnotnull in its correct state; for example if you drop
a column that's part of the primary key, and the other columns of the PK don't
have not-null constraints, then we should reset the attnotnull flags for
those other columns; up to this commit, we didn't.  Handle those cases
better by doing the attnotnull reset in RemoveConstraintById() instead
of in dropconstraint_internal().

However, there are some cases where we must not do so.  For example if
those other columns are in replica identity indexes or are generated
identity columns, we must keep attnotnull set, even though it results in
the catalog inconsistency that no not-null constraint supports that.

Because the attnotnull reset now happens in more places than before, for
instance when a column of the primary key changes type, we need an
additional trick to reinstate it as necessary.  Introduce a new
alter-table pass that does this, which needs simply reschedule some
AT_SetAttNotNull subcommands that were already being generated and
ignored.

Because of the exceptions in which attnotnull is not reset noted above,
we also include a pg_dump hack to include a not-null constraint when the
attnotnull flag is set even if no pg_constraint row exists.  This part
is undesirable but necessary, because failing to handle the case can
result in unrestorable dumps.

Reported-by: Tender Wang <tndrwang@gmail.com>
Co-authored-by: Tender Wang <tndrwang@gmail.com>
Reviewed-by: jian he <jian.universality@gmail.com>
Discussion: https://postgr.es/m/CAHewXN=hMbNa3d43NOR=OCgdgpTt18S-1fmueCoEGesyeK4bqw@mail.gmail.com
2024-04-19 12:37:33 +02:00
..
Makefile Revert: Implement pg_wal_replay_wait() stored procedure 2024-04-11 17:28:15 +03:00
aggregatecmds.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
alter.c Remove ObjectClass type 2024-03-26 10:08:56 +01:00
amcmds.c Fix typos and duplicate words 2024-04-18 21:28:07 +02:00
analyze.c revert: Generalize relation analyze in table AM interface 2024-04-16 13:14:20 +03:00
async.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
cluster.c Reintroduce MAINTAIN privilege and pg_maintain predefined role. 2024-03-13 14:49:26 -05:00
collationcmds.c Address more review comments on commit 2d819a08a1. 2024-03-18 11:58:13 -07:00
comment.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
constraint.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
conversioncmds.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
copy.c Disallow specifying ON_ERROR option without value. 2024-04-17 11:31:27 +09:00
copyfrom.c Fix typos and duplicate words 2024-04-18 21:28:07 +02:00
copyfromparse.c Remove obsolete comment in CopyReadLineText(). 2024-04-06 11:16:27 -04:00
copyto.c Add RETURNING support to MERGE. 2024-03-17 13:58:59 +00:00
createas.c Revert: Let table AM insertion methods control index insertion 2024-04-11 16:01:30 +03:00
dbcommands.c Fix typos and duplicate words 2024-04-18 21:28:07 +02:00
define.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
discard.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
dropcmds.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
event_trigger.c Fix typos with function name in event_trigger.c 2024-04-17 14:56:31 +09:00
explain.c Fix incorrect format placeholders 2024-04-09 14:33:06 +02:00
extension.c Explicitly list dependent types as extension members in pg_depend. 2024-03-04 14:49:36 -05:00
foreigncmds.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
functioncmds.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
indexcmds.c Add temporal FOREIGN KEY contraints 2024-03-24 07:37:13 +01:00
lockcmds.c Reintroduce MAINTAIN privilege and pg_maintain predefined role. 2024-03-13 14:49:26 -05:00
matview.c Revert: Let table AM insertion methods control index insertion 2024-04-11 16:01:30 +03:00
meson.build Revert: Implement pg_wal_replay_wait() stored procedure 2024-04-11 17:28:15 +03:00
opclasscmds.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
operatorcmds.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
policy.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
portalcmds.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
prepare.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
proclang.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
publicationcmds.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
schemacmds.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
seclabel.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
sequence.c Replace BackendIds with 0-based ProcNumbers 2024-03-03 19:38:22 +02:00
statscmds.c Initialize variables to placate compiler. 2024-03-17 20:16:15 -05:00
subscriptioncmds.c Add destroyStringInfo function for cleaning up StringInfos 2024-03-16 23:18:28 +01:00
tablecmds.c Better handle indirect constraint drops 2024-04-19 12:37:33 +02:00
tablespace.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
trigger.c Revert: Allow locking updated tuples in tuple_update() and tuple_delete() 2024-04-11 16:01:34 +03:00
tsearchcmds.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
typecmds.c Catalog domain not-null constraints 2024-03-20 10:05:37 +01:00
user.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
vacuum.c Revert: Custom reloptions for table AM 2024-04-11 15:46:35 +03:00
vacuumparallel.c Fix typos and duplicate words 2024-04-18 21:28:07 +02:00
variable.c Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
view.c Separate equalRowTypes() from equalTupleDescs() 2024-03-17 05:58:04 +01:00