postgresql/src/backend
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
..
access Fix typos and duplicate words 2024-04-18 21:28:07 +02:00
archive Add built-in ERROR handling for archive callbacks. 2024-04-02 22:28:11 -05:00
backup Fix unnecessary padding in incremental backups 2024-04-14 20:37:49 +02:00
bootstrap Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
catalog Better handle indirect constraint drops 2024-04-19 12:37:33 +02:00
commands Better handle indirect constraint drops 2024-04-19 12:37:33 +02:00
executor Fix typos and duplicate words 2024-04-18 21:28:07 +02:00
foreign Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
jit Remove dead code 2024-04-17 10:48:04 +02:00
lib Revert: Implement pg_wal_replay_wait() stored procedure 2024-04-11 17:28:15 +03:00
libpq Fix check for 'outlen' return from SSL_select_next_proto() 2024-04-08 05:03:17 +03:00
main Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
nodes revert: Transform OR clauses to ANY expression 2024-04-10 02:28:09 +03:00
optimizer Use macro NUM_MERGE_MATCH_KINDS instead of '3' in MERGE code. 2024-04-19 09:40:20 +01:00
parser Use macro NUM_MERGE_MATCH_KINDS instead of '3' in MERGE code. 2024-04-19 09:40:20 +01:00
partitioning Fix typos and duplicate words 2024-04-18 21:28:07 +02:00
po Update copyright for 2024 2024-01-03 20:49:05 -05:00
port Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
postmaster Fix typos and duplicate words 2024-04-18 21:28:07 +02:00
regex Support C.UTF-8 locale in the new builtin collation provider. 2024-03-19 15:24:41 -07:00
replication Fix typos and duplicate words 2024-04-18 21:28:07 +02:00
rewrite Add RETURNING support to MERGE. 2024-03-17 13:58:59 +00:00
snowball Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
statistics Fix typos and duplicate words 2024-04-18 21:28:07 +02:00
storage Fix typos and duplicate words 2024-04-18 21:28:07 +02:00
tcop Revert: Custom reloptions for table AM 2024-04-11 15:46:35 +03:00
tsearch Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
utils Fix typos and duplicate words 2024-04-18 21:28:07 +02:00
.gitignore
Makefile Rework lwlocknames.txt to become lwlocklist.h 2024-03-20 11:55:20 +01:00
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
meson.build Remove AIX support 2024-02-28 15:17:23 +04:00
nls.mk Remove distprep 2023-11-06 15:18:04 +01:00