postgres/contrib
Álvaro Herrera 14e87ffa5c
Add pg_constraint rows for not-null constraints
We now create contype='n' pg_constraint rows for not-null constraints on
user tables.  Only one such constraint is allowed for a column.

We propagate these constraints to other tables during operations such as
adding inheritance relationships, creating and attaching partitions and
creating tables LIKE other tables.  These related constraints mostly
follow the well-known rules of conislocal and coninhcount that we have
for CHECK constraints, with some adaptations: for example, as opposed to
CHECK constraints, we don't match not-null ones by name when descending
a hierarchy to alter or remove it, instead matching by the name of the
column that they apply to.  This means we don't require the constraint
names to be identical across a hierarchy.

The inheritance status of these constraints can be controlled: now we
can be sure that if a parent table has one, then all children will have
it as well.  They can optionally be marked NO INHERIT, and then children
are free not to have one.  (There's currently no support for altering a
NO INHERIT constraint into inheriting down the hierarchy, but that's a
desirable future feature.)

This also opens the door for having these constraints be marked NOT
VALID, as well as allowing UNIQUE+NOT NULL to be used for functional
dependency determination, as envisioned by commit e49ae8d3bc.  It's
likely possible to allow DEFERRABLE constraints as followup work, as
well.

psql shows these constraints in \d+, though we may want to reconsider if
this turns out to be too noisy.  Earlier versions of this patch hid
constraints that were on the same columns of the primary key, but I'm
not sure that that's very useful.  If clutter is a problem, we might be
better off inventing a new \d++ command and not showing the constraints
in \d+.

For now, we omit these constraints on system catalog columns, because
they're unlikely to achieve anything.

The main difference to the previous attempt at this (b0e96f3119) is
that we now require that such a constraint always exists when a primary
key is in the column; we didn't require this previously which had a
number of unpalatable consequences.  With this requirement, the code is
easier to reason about.  For example:

- We no longer have "throwaway constraints" during pg_dump.  We needed
  those for the case where a table had a PK without a not-null
  underneath, to prevent a slow scan of the data during restore of the
  PK creation, which was particularly problematic for pg_upgrade.

- We no longer have to cope with attnotnull being set spuriously in
  case a primary key is dropped indirectly (e.g., via DROP COLUMN).

Some bits of code in this patch were authored by Jian He.

Author: Álvaro Herrera <alvherre@alvh.no-ip.org>
Author: Bernd Helmle <mailings@oopsware.de>
Reviewed-by: 何建 (jian he) <jian.universality@gmail.com>
Reviewed-by: 王刚 (Tender Wang) <tndrwang@gmail.com>
Reviewed-by: Justin Pryzby <pryzby@telsasoft.com>
Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>
Discussion: https://postgr.es/m/202408310358.sdhumtyuy2ht@alvherre.pgsql
2024-11-08 13:28:48 +01:00
..
amcheck Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
auth_delay Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
auto_explain Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
basebackup_to_shell Update copyright for 2024 2024-01-03 20:49:05 -05:00
basic_archive Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
bloom Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
bool_plperl Update copyright for 2024 2024-01-03 20:49:05 -05:00
btree_gin Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
btree_gist Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
citext Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
cube Include bison header files into implementation files 2024-08-02 10:25:11 +02:00
dblink Don't bother checking the result of SPI_connect[_ext] anymore. 2024-09-09 12:18:34 -04:00
dict_int Update copyright for 2024 2024-01-03 20:49:05 -05:00
dict_xsyn Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
earthdistance Update copyright for 2024 2024-01-03 20:49:05 -05:00
file_fdw file_fdw: Add on_error and log_verbosity options to file_fdw. 2024-10-03 15:57:32 +09:00
fuzzystrmatch Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
hstore Optimize escaping of JSON strings 2024-07-27 23:46:07 +12:00
hstore_plperl Update copyright for 2024 2024-01-03 20:49:05 -05:00
hstore_plpython Update copyright for 2024 2024-01-03 20:49:05 -05:00
intagg Update copyright for 2024 2024-01-03 20:49:05 -05:00
intarray Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
isn Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
jsonb_plperl Update copyright for 2024 2024-01-03 20:49:05 -05:00
jsonb_plpython Update copyright for 2024 2024-01-03 20:49:05 -05:00
lo Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
ltree Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
ltree_plpython Update copyright for 2024 2024-01-03 20:49:05 -05:00
oid2name Apply more quoting to GUC names in messages 2024-09-04 13:50:44 +09:00
pageinspect Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
passwordcheck Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_buffercache Add pg_buffercache_evict() function for testing. 2024-04-08 16:23:40 +12:00
pg_freespacemap Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
pg_logicalinspect Add contrib/pg_logicalinspect. 2024-10-14 17:22:02 -07:00
pg_prewarm Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
pg_stat_statements Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
pg_surgery Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
pg_trgm Use new overflow-safe integer comparison functions. 2024-02-16 14:05:36 -06:00
pg_visibility Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
pg_walinspect Assign error codes where missing for user-facing failures 2024-07-04 09:48:40 +09:00
pgcrypto Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
pgrowlocks Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
pgstattuple Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
postgres_fdw Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
seg Use generateClonedIndexStmt to propagate CREATE INDEX to partitions. 2024-10-05 14:46:44 -04:00
sepgsql Add pg_constraint rows for not-null constraints 2024-11-08 13:28:48 +01:00
spi Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
sslinfo Revert "Add notBefore and notAfter to SSL cert info display" 2024-03-22 22:58:41 +01:00
start-scripts Remove gratuitous references to postmaster program 2023-01-26 10:48:32 +01:00
tablefunc Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
tcn Update copyright for 2024 2024-01-03 20:49:05 -05:00
test_decoding Add pg_constraint rows for not-null constraints 2024-11-08 13:28:48 +01:00
tsm_system_rows Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
tsm_system_time Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
unaccent Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
uuid-ossp Make the order of the header file includes consistent 2024-03-13 15:07:00 +01:00
vacuumlo Apply more quoting to GUC names in messages 2024-09-04 13:50:44 +09:00
xml2 Remove unused #include's from contrib, pl, test .c files 2024-10-28 08:02:17 +01:00
Makefile Add contrib/pg_logicalinspect. 2024-10-14 17:22:02 -07:00
README Rename 'gmake' to 'make' in docs and recommended commands 2014-02-12 17:29:19 -05:00
contrib-global.mk Respect TEMP_CONFIG when pg_regress_check and friends are called 2016-02-27 12:28:21 -05:00
meson.build Add contrib/pg_logicalinspect. 2024-10-14 17:22:02 -07:00

README

The PostgreSQL contrib tree
---------------------------

This subtree contains porting tools, analysis utilities, and plug-in
features that are not part of the core PostgreSQL system, mainly
because they address a limited audience or are too experimental to be
part of the main source tree.  This does not preclude their
usefulness.

User documentation for each module appears in the main SGML
documentation.

When building from the source distribution, these modules are not
built automatically, unless you build the "world" target.  You can
also build and install them all by running "make all" and "make
install" in this directory; or to build and install just one selected
module, do the same in that module's subdirectory.

Some directories supply new user-defined functions, operators, or
types.  To make use of one of these modules, after you have installed
the code you need to register the new SQL objects in the database
system by executing a CREATE EXTENSION command.  In a fresh database,
you can simply do

    CREATE EXTENSION module_name;

See the PostgreSQL documentation for more information about this
procedure.