- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit14e87ff
committed
Add pg_constraint rows for not-null constraints
We now create contype='n' pg_constraint rows for not-null constraints onuser tables. Only one such constraint is allowed for a column.We propagate these constraints to other tables during operations such asadding inheritance relationships, creating and attaching partitions andcreating tables LIKE other tables. These related constraints mostlyfollow the well-known rules of conislocal and coninhcount that we havefor CHECK constraints, with some adaptations: for example, as opposed toCHECK constraints, we don't match not-null ones by name when descendinga hierarchy to alter or remove it, instead matching by the name of thecolumn that they apply to. This means we don't require the constraintnames to be identical across a hierarchy.The inheritance status of these constraints can be controlled: now wecan be sure that if a parent table has one, then all children will haveit as well. They can optionally be marked NO INHERIT, and then childrenare free not to have one. (There's currently no support for altering aNO INHERIT constraint into inheriting down the hierarchy, but that's adesirable future feature.)This also opens the door for having these constraints be marked NOTVALID, as well as allowing UNIQUE+NOT NULL to be used for functionaldependency determination, as envisioned by commite49ae8d. It'slikely possible to allow DEFERRABLE constraints as followup work, aswell.psql shows these constraints in \d+, though we may want to reconsider ifthis turns out to be too noisy. Earlier versions of this patch hidconstraints that were on the same columns of the primary key, but I'mnot sure that that's very useful. If clutter is a problem, we might bebetter off inventing a new \d++ command and not showing the constraintsin \d+.For now, we omit these constraints on system catalog columns, becausethey're unlikely to achieve anything.The main difference to the previous attempt at this (b0e96f3) isthat we now require that such a constraint always exists when a primarykey is in the column; we didn't require this previously which had anumber of unpalatable consequences. With this requirement, the code iseasier 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.pgsql1 parent075acdd commit14e87ff
File tree
57 files changed
+4246
-818
lines changed- contrib
- sepgsql/expected
- test_decoding/expected
- doc/src/sgml
- ref
- src
- backend
- catalog
- commands
- nodes
- optimizer/util
- parser
- replication/logical
- utils
- adt
- cache
- bin
- pg_dump
- t
- psql
- t
- include
- catalog
- nodes
- utils
- test
- modules/test_ddl_deparse
- expected
- regress
- expected
- sql
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
57 files changed
+4246
-818
lines changedLines changed: 0 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
164 | 164 |
| |
165 | 165 |
| |
166 | 166 |
| |
167 |
| - | |
168 | 167 |
| |
169 | 168 |
| |
170 | 169 |
| |
| |||
249 | 248 |
| |
250 | 249 |
| |
251 | 250 |
| |
252 |
| - | |
253 |
| - | |
254 | 251 |
| |
255 | 252 |
| |
256 | 253 |
| |
|
Lines changed: 12 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
492 | 492 |
| |
493 | 493 |
| |
494 | 494 |
| |
| 495 | + | |
| 496 | + | |
| 497 | + | |
495 | 498 |
| |
496 | 499 |
| |
497 | 500 |
| |
| |||
506 | 509 |
| |
507 | 510 |
| |
508 | 511 |
| |
| 512 | + | |
| 513 | + | |
| 514 | + | |
509 | 515 |
| |
510 | 516 |
| |
511 | 517 |
| |
| |||
519 | 525 |
| |
520 | 526 |
| |
521 | 527 |
| |
| 528 | + | |
| 529 | + | |
| 530 | + | |
522 | 531 |
| |
523 | 532 |
| |
524 | 533 |
| |
| |||
538 | 547 |
| |
539 | 548 |
| |
540 | 549 |
| |
| 550 | + | |
| 551 | + | |
| 552 | + | |
541 | 553 |
| |
542 | 554 |
| |
543 | 555 |
| |
|
Lines changed: 4 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1271 | 1271 |
| |
1272 | 1272 |
| |
1273 | 1273 |
| |
1274 |
| - | |
| 1274 | + | |
1275 | 1275 |
| |
1276 | 1276 |
| |
1277 | 1277 |
| |
| |||
2502 | 2502 |
| |
2503 | 2503 |
| |
2504 | 2504 |
| |
2505 |
| - | |
2506 |
| - | |
2507 |
| - | |
| 2505 | + | |
| 2506 | + | |
2508 | 2507 |
| |
2509 | 2508 |
| |
2510 |
| - | |
2511 |
| - | |
2512 |
| - | |
2513 | 2509 |
| |
2514 | 2510 |
| |
2515 | 2511 |
| |
| |||
2571 | 2567 |
| |
2572 | 2568 |
| |
2573 | 2569 |
| |
2574 |
| - | |
| 2570 | + | |
2575 | 2571 |
| |
2576 | 2572 |
| |
2577 | 2573 |
| |
|
Lines changed: 48 additions & 17 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
772 | 772 |
| |
773 | 773 |
| |
774 | 774 |
| |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
775 | 799 |
| |
776 | 800 |
| |
777 | 801 |
| |
778 |
| - | |
779 |
| - | |
| 802 | + | |
780 | 803 |
| |
781 | 804 |
| |
782 | 805 |
| |
783 |
| - | |
784 |
| - | |
785 |
| - | |
| 806 | + | |
786 | 807 |
| |
787 | 808 |
| |
788 | 809 |
| |
| |||
799 | 820 |
| |
800 | 821 |
| |
801 | 822 |
| |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
802 | 827 |
| |
803 | 828 |
| |
804 | 829 |
| |
| |||
992 | 1017 |
| |
993 | 1018 |
| |
994 | 1019 |
| |
995 |
| - | |
| 1020 | + | |
996 | 1021 |
| |
997 | 1022 |
| |
998 | 1023 |
| |
| |||
1652 | 1677 |
| |
1653 | 1678 |
| |
1654 | 1679 |
| |
1655 |
| - | |
1656 |
| - | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
1657 | 1685 |
| |
1658 | 1686 |
| |
1659 | 1687 |
| |
| 1688 | + | |
| 1689 | + | |
1660 | 1690 |
| |
1661 | 1691 |
| |
1662 | 1692 |
| |
| |||
1697 | 1727 |
| |
1698 | 1728 |
| |
1699 | 1729 |
| |
1700 |
| - | |
1701 |
| - | |
| 1730 | + | |
1702 | 1731 |
| |
1703 | 1732 |
| |
1704 | 1733 |
| |
1705 |
| - | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
1706 | 1739 |
| |
1707 | 1740 |
| |
1708 | 1741 |
| |
| |||
4446 | 4479 |
| |
4447 | 4480 |
| |
4448 | 4481 |
| |
4449 |
| - | |
4450 |
| - | |
4451 |
| - | |
4452 |
| - | |
4453 |
| - | |
4454 |
| - | |
| 4482 | + | |
| 4483 | + | |
| 4484 | + | |
| 4485 | + | |
4455 | 4486 |
| |
4456 | 4487 |
| |
4457 | 4488 |
| |
|
Lines changed: 4 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
173 | 173 |
| |
174 | 174 |
| |
175 | 175 |
| |
176 |
| - | |
| 176 | + | |
| 177 | + | |
177 | 178 |
| |
178 | 179 |
| |
179 | 180 |
| |
| |||
182 | 183 |
| |
183 | 184 |
| |
184 | 185 |
| |
185 |
| - | |
| 186 | + | |
| 187 | + | |
186 | 188 |
| |
187 | 189 |
| |
188 | 190 |
| |
|
Lines changed: 17 additions & 13 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
98 | 98 |
| |
99 | 99 |
| |
100 | 100 |
| |
101 |
| - | |
| 101 | + | |
102 | 102 |
| |
103 | 103 |
| |
104 | 104 |
| |
| |||
114 | 114 |
| |
115 | 115 |
| |
116 | 116 |
| |
| 117 | + | |
117 | 118 |
| |
118 | 119 |
| |
119 | 120 |
| |
| |||
849 | 850 |
| |
850 | 851 |
| |
851 | 852 |
| |
852 |
| - | |
853 |
| - | |
854 |
| - | |
855 |
| - | |
| 853 | + | |
856 | 854 |
| |
857 | 855 |
| |
858 | 856 |
| |
859 |
| - | |
860 |
| - | |
861 |
| - | |
862 |
| - | |
863 |
| - | |
864 |
| - | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
865 | 863 |
| |
866 | 864 |
| |
867 | 865 |
| |
| |||
1793 | 1791 |
| |
1794 | 1792 |
| |
1795 | 1793 |
| |
1796 |
| - | |
| 1794 | + | |
1797 | 1795 |
| |
1798 | 1796 |
| |
1799 | 1797 |
| |
1800 |
| - | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
1801 | 1805 |
| |
1802 | 1806 |
| |
1803 | 1807 |
| |
|
Lines changed: 8 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
43 | 43 |
| |
44 | 44 |
| |
45 | 45 |
| |
46 |
| - | |
| 46 | + | |
47 | 47 |
| |
48 | 48 |
| |
49 | 49 |
| |
| |||
52 | 52 |
| |
53 | 53 |
| |
54 | 54 |
| |
| 55 | + | |
55 | 56 |
| |
56 | 57 |
| |
57 | 58 |
| |
| |||
203 | 204 |
| |
204 | 205 |
| |
205 | 206 |
| |
206 |
| - | |
| 207 | + | |
207 | 208 |
| |
208 | 209 |
| |
209 | 210 |
| |
210 | 211 |
| |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
211 | 217 |
| |
212 | 218 |
| |
213 | 219 |
| |
|
0 commit comments
Comments
(0)