postgresql/src/bin/pg_dump
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
..
po Update copyright for 2024 2024-01-03 20:49:05 -05:00
t Rearrange pg_dump's handling of large objects for better efficiency. 2024-04-01 16:25:56 -04:00
.gitignore Clean up after pg_dump test runs. 2016-05-06 22:28:01 -04:00
Makefile Update copyright for 2024 2024-01-03 20:49:05 -05:00
common.c Rearrange pg_dump's handling of large objects for better efficiency. 2024-04-01 16:25:56 -04:00
compress_gzip.c Use printf's %m format instead of strerror(errno) in more places 2024-03-12 10:02:54 +09:00
compress_gzip.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
compress_io.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
compress_io.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
compress_lz4.c Make the order of the header file includes consistent 2024-03-13 15:07:00 +01:00
compress_lz4.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
compress_none.c Use printf's %m format instead of strerror(errno) in more places 2024-03-12 10:02:54 +09:00
compress_none.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
compress_zstd.c Make the order of the header file includes consistent 2024-03-13 15:07:00 +01:00
compress_zstd.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
dumputils.c Reintroduce MAINTAIN privilege and pg_maintain predefined role. 2024-03-13 14:49:26 -05:00
dumputils.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
filter.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
filter.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
meson.build Update copyright for 2024 2024-01-03 20:49:05 -05:00
nls.mk Add missing file to nls Makefile 2023-11-30 10:56:51 +01:00
parallel.c Rename static function to avoid conflicting names 2024-02-07 22:16:21 +01:00
parallel.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_backup.h Invent --transaction-size option for pg_restore. 2024-04-01 16:46:24 -04:00
pg_backup_archiver.c Revert indexed and enlargable binary heap implementation. 2024-04-11 17:18:05 +09:00
pg_backup_archiver.h Invent --transaction-size option for pg_restore. 2024-04-01 16:46:24 -04:00
pg_backup_custom.c Rearrange pg_dump's handling of large objects for better efficiency. 2024-04-01 16:25:56 -04:00
pg_backup_db.c Invent --transaction-size option for pg_restore. 2024-04-01 16:46:24 -04:00
pg_backup_db.h Revert "pg_dump: Lock all relations, not just plain tables". 2020-11-06 15:48:04 -05:00
pg_backup_directory.c Rearrange pg_dump's handling of large objects for better efficiency. 2024-04-01 16:25:56 -04:00
pg_backup_null.c Rearrange pg_dump's handling of large objects for better efficiency. 2024-04-01 16:25:56 -04:00
pg_backup_tar.c Rearrange pg_dump's handling of large objects for better efficiency. 2024-04-01 16:25:56 -04:00
pg_backup_tar.h Fix tar files emitted by pg_dump and pg_basebackup to be POSIX conformant. 2012-09-28 15:19:15 -04:00
pg_backup_utils.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_backup_utils.h Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_dump.c Better handle indirect constraint drops 2024-04-19 12:37:33 +02:00
pg_dump.h Rearrange pg_dump's handling of large objects for better efficiency. 2024-04-01 16:25:56 -04:00
pg_dump_sort.c Revert indexed and enlargable binary heap implementation. 2024-04-11 17:18:05 +09:00
pg_dumpall.c Convert uses of hash_string_pointer to fasthash equivalent 2024-04-06 12:20:40 +07:00
pg_restore.c Invent --transaction-size option for pg_restore. 2024-04-01 16:46:24 -04:00