- Notifications
You must be signed in to change notification settings - Fork4.9k
Commitb0e96f3
committed
Catalog not-null constraints
We now create contype='n' pg_constraint rows for not-null constraints.We propagate these constraints to other tables during operations such asadding inheritance relationships, creating and attaching partitions andcreating tables LIKE other tables. We also spawn not-null constraintsfor inheritance child tables when their parents have primary keys.These related constraints mostly follow the well-known rules ofconislocal and coninhcount that we have for CHECK constraints, with someadaptations: for example, as opposed to CHECK constraints, we don'tmatch not-null ones by name when descending a hierarchy to alter it,instead matching by column name that they apply to. This means we don'trequire the constraint names to be identical across a hierarchy.For now, we omit them for system catalogs. Maybe this is worthreconsidering. We don't support NOT VALID nor DEFERRABLE clauseseither; these can be added as separate features later (this patch isalready large and complicated enough.)psql shows these constraints in \d+.pg_dump requires some ad-hoc hacks, particularly when dumping a primarykey. We now create one "throwaway" not-null constraint for each columnin the PK together with the CREATE TABLE command, and once the PK iscreated, all those throwaway constraints are removed. This avoidshaving to check each tuple for nullness when the dump restores theprimary key creation.pg_upgrading from an older release requires a somewhat brittle procedureto create a constraint state that matches what would be created if thedatabase were being created fresh in Postgres 17. I have tested all thescenarios I could think of, and it works correctly as far as I can tell,but I could have neglected weird cases.This patch has been very long in the making. The first patch waswritten by Bernd Helmle in 2010 to add a new pg_constraint.contype value('n'), which I (Álvaro) then hijacked in 2011 and 2012, until that onewas killed by the realization that we ought to use contype='c' instead:manufactured CHECK constraints. However, later SQL standarddevelopment, as well as nonobvious emergent properties of that design(mostly, failure to distinguish them from "normal" CHECK constraints aswell as the performance implication of having to test the CHECKexpression) led us to reconsider this choice, so now the currentimplementation uses contype='n' again. During Postgres 16 this hadalready been introduced by commite056c55, but there were someproblems mainly with the pg_upgrade procedure that couldn't be fixed inreasonable time, so it was reverted.In 2016 Vitaly Burovoy also worked on this feature[1] but found noconsensus for his proposed approach, which was claimed to be closer tothe letter of the standard, requiring an additional pg_attribute columnto track the OID of the not-null constraint for that column.[1]https://postgr.es/m/CAKOSWNkN6HSyatuys8xZxzRCR-KL1OkHS5-b9qd9bf1Rad3PLA@mail.gmail.comAuthor: Álvaro Herrera <alvherre@alvh.no-ip.org>Author: Bernd Helmle <mailings@oopsware.de>Reviewed-by: Justin Pryzby <pryzby@telsasoft.com>Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com>1 parent9c13b68 commitb0e96f3
File tree
50 files changed
+3928
-764
lines changed- contrib
- sepgsql/expected
- test_decoding/expected
- doc/src/sgml
- ref
- src
- backend
- catalog
- commands
- nodes
- optimizer/util
- parser
- utils
- adt
- cache
- bin
- pg_dump
- t
- psql
- include
- catalog
- nodes
- 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.
50 files changed
+3928
-764
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: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
49 | 49 |
| |
50 | 50 |
| |
51 | 51 |
| |
| 52 | + | |
52 | 53 |
| |
53 | 54 |
| |
54 | 55 |
| |
| |||
269 | 270 |
| |
270 | 271 |
| |
271 | 272 |
| |
| 273 | + | |
272 | 274 |
| |
273 | 275 |
| |
274 | 276 |
| |
|
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: 5 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1270 | 1270 |
| |
1271 | 1271 |
| |
1272 | 1272 |
| |
1273 |
| - | |
| 1273 | + | |
| 1274 | + | |
1274 | 1275 |
| |
1275 | 1276 |
| |
1276 | 1277 |
| |
| |||
2484 | 2485 |
| |
2485 | 2486 |
| |
2486 | 2487 |
| |
2487 |
| - | |
2488 |
| - | |
| 2488 | + | |
| 2489 | + | |
2489 | 2490 |
| |
2490 | 2491 |
| |
2491 |
| - | |
2492 |
| - | |
2493 |
| - | |
2494 | 2492 |
| |
2495 | 2493 |
| |
2496 | 2494 |
| |
| |||
2552 | 2550 |
| |
2553 | 2551 |
| |
2554 | 2552 |
| |
| 2553 | + | |
2555 | 2554 |
| |
2556 | 2555 |
| |
2557 | 2556 |
| |
|
Lines changed: 44 additions & 11 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
651 | 651 |
| |
652 | 652 |
| |
653 | 653 |
| |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
654 | 678 |
| |
655 | 679 |
| |
656 | 680 |
| |
657 |
| - | |
658 |
| - | |
| 681 | + | |
659 | 682 |
| |
660 | 683 |
| |
661 | 684 |
| |
662 |
| - | |
663 |
| - | |
664 |
| - | |
| 685 | + | |
665 | 686 |
| |
666 | 687 |
| |
667 | 688 |
| |
| |||
678 | 699 |
| |
679 | 700 |
| |
680 | 701 |
| |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
681 | 706 |
| |
682 | 707 |
| |
683 | 708 |
| |
| |||
871 | 896 |
| |
872 | 897 |
| |
873 | 898 |
| |
874 |
| - | |
| 899 | + | |
875 | 900 |
| |
876 | 901 |
| |
877 | 902 |
| |
| |||
1531 | 1556 |
| |
1532 | 1557 |
| |
1533 | 1558 |
| |
1534 |
| - | |
1535 |
| - | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
1536 | 1564 |
| |
1537 | 1565 |
| |
1538 | 1566 |
| |
| 1567 | + | |
| 1568 | + | |
1539 | 1569 |
| |
1540 | 1570 |
| |
1541 | 1571 |
| |
| |||
1576 | 1606 |
| |
1577 | 1607 |
| |
1578 | 1608 |
| |
1579 |
| - | |
1580 |
| - | |
| 1609 | + | |
1581 | 1610 |
| |
1582 | 1611 |
| |
1583 | 1612 |
| |
1584 |
| - | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
1585 | 1618 |
| |
1586 | 1619 |
| |
1587 | 1620 |
| |
|
Lines changed: 9 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
113 | 113 |
| |
114 | 114 |
| |
115 | 115 |
| |
| 116 | + | |
116 | 117 |
| |
117 | 118 |
| |
118 | 119 |
| |
| |||
1763 | 1764 |
| |
1764 | 1765 |
| |
1765 | 1766 |
| |
1766 |
| - | |
| 1767 | + | |
1767 | 1768 |
| |
1768 | 1769 |
| |
1769 | 1770 |
| |
1770 |
| - | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
1771 | 1778 |
| |
1772 | 1779 |
| |
1773 | 1780 |
| |
|
Lines changed: 1 addition & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
77 | 77 |
| |
78 | 78 |
| |
79 | 79 |
| |
| 80 | + | |
80 | 81 |
| |
81 | 82 |
| |
82 | 83 |
| |
| |||
2314 | 2315 |
| |
2315 | 2316 |
| |
2316 | 2317 |
| |
2317 |
| - | |
2318 |
| - | |
2319 |
| - | |
2320 |
| - | |
2321 |
| - | |
2322 |
| - | |
2323 |
| - | |
2324 | 2318 |
| |
2325 | 2319 |
| |
2326 | 2320 |
| |
|
0 commit comments
Comments
(0)