- Notifications
You must be signed in to change notification settings - Fork28
Commitfb466d7
committed
Fully enforce uniqueness of constraint names.
It's been true for a long time that we expect names of table and domainconstraints to be unique among the constraints of that table or domain.However, the enforcement of that has been pretty haphazard, and it missedsome corner cases such as creating a CHECK constraint and then an indexconstraint of the same name (as per recent report from André Hänsel).Also, due to the lack of an actual unique index enforcing this, duplicatescould be created through race conditions.Moreover, the code that searches pg_constraint has been quite inconsistentabout how to handle duplicate names if one did occur: some places checkedand threw errors if there was more than one match, while others justprocessed the first match they came to.To fix, create a unique index on (conrelid, contypid, conname). Sinceeither conrelid or contypid is zero, this will separately enforceuniqueness of constraint names among constraints of any one table and anyone domain. (If we ever implement SQL assertions, and put them into thiscatalog, more thought might be needed. But it'd be at least as reasonableto put them into a new catalog; having overloaded this one catalog withtwo kinds of constraints was a mistake already IMO.) This index can replacethe existing non-unique index on conrelid, though we need to keep the oneon contypid for query performance reasons.Having done that, we can simplify the logic in various places that eithercoped with duplicates or neglected to, as well as potentially improvelookup performance when searching for a constraint by name.Also, as per our usual practice, install a preliminary check so that youget something more friendly than a unique-index violation report in thecase complained of by André. And teach ChooseIndexName to avoid choosingautogenerated names that would draw such a failure.While it's not possible to make such a change in the back branches,it doesn't seem quite too late to put this into v11, so do so.Discussion:https://postgr.es/m/0c1001d4428f$0942b430$1bc81c90$@webkr.de1 parent2ce253c commitfb466d7
File tree
17 files changed
+494
-366
lines changed- doc/src/sgml/ref
- src
- backend
- catalog
- commands
- parser
- utils/cache
- include
- catalog
- commands
- test/regress
- expected
- sql
17 files changed
+494
-366
lines changedLines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
48 | 48 |
| |
49 | 49 |
| |
50 | 50 |
| |
| 51 | + | |
| 52 | + | |
| 53 | + | |
51 | 54 |
| |
52 | 55 |
| |
53 | 56 |
| |
|
Lines changed: 21 additions & 16 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
474 | 474 |
| |
475 | 475 |
| |
476 | 476 |
| |
477 |
| - | |
| 477 | + | |
| 478 | + | |
478 | 479 |
| |
479 | 480 |
| |
480 | 481 |
| |
| |||
822 | 823 |
| |
823 | 824 |
| |
824 | 825 |
| |
825 |
| - | |
826 |
| - | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
827 | 830 |
| |
828 | 831 |
| |
829 | 832 |
| |
| |||
1270 | 1273 |
| |
1271 | 1274 |
| |
1272 | 1275 |
| |
1273 |
| - | |
1274 |
| - | |
1275 |
| - | |
1276 |
| - | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
1277 | 1282 |
| |
1278 | 1283 |
| |
1279 | 1284 |
| |
| |||
1481 | 1486 |
| |
1482 | 1487 |
| |
1483 | 1488 |
| |
1484 |
| - | |
| 1489 | + | |
1485 | 1490 |
| |
1486 | 1491 |
| |
1487 | 1492 |
| |
1488 | 1493 |
| |
1489 | 1494 |
| |
1490 | 1495 |
| |
1491 |
| - | |
| 1496 | + | |
1492 | 1497 |
| |
1493 | 1498 |
| |
1494 | 1499 |
| |
1495 | 1500 |
| |
1496 | 1501 |
| |
1497 | 1502 |
| |
1498 |
| - | |
| 1503 | + | |
1499 | 1504 |
| |
1500 |
| - | |
1501 |
| - | |
| 1505 | + | |
| 1506 | + | |
1502 | 1507 |
| |
1503 | 1508 |
| |
1504 | 1509 |
| |
1505 |
| - | |
| 1510 | + | |
1506 | 1511 |
| |
1507 |
| - | |
1508 |
| - | |
| 1512 | + | |
| 1513 | + | |
1509 | 1514 |
| |
1510 | 1515 |
| |
1511 | 1516 |
| |
1512 |
| - | |
| 1517 | + | |
1513 | 1518 |
| |
1514 | 1519 |
| |
1515 | 1520 |
| |
|
Lines changed: 24 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1946 | 1946 |
| |
1947 | 1947 |
| |
1948 | 1948 |
| |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
| 1963 | + | |
| 1964 | + | |
| 1965 | + | |
| 1966 | + | |
| 1967 | + | |
| 1968 | + | |
| 1969 | + | |
| 1970 | + | |
| 1971 | + | |
| 1972 | + | |
1949 | 1973 |
| |
1950 | 1974 |
| |
1951 | 1975 |
| |
|
Lines changed: 95 additions & 95 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2707 | 2707 |
| |
2708 | 2708 |
| |
2709 | 2709 |
| |
2710 |
| - | |
| 2710 | + | |
2711 | 2711 |
| |
2712 | 2712 |
| |
2713 | 2713 |
| |
| |||
2716 | 2716 |
| |
2717 | 2717 |
| |
2718 | 2718 |
| |
| 2719 | + | |
| 2720 | + | |
| 2721 | + | |
| 2722 | + | |
| 2723 | + | |
| 2724 | + | |
| 2725 | + | |
| 2726 | + | |
2719 | 2727 |
| |
2720 | 2728 |
| |
2721 | 2729 |
| |
2722 | 2730 |
| |
2723 |
| - | |
2724 |
| - | |
2725 |
| - | |
2726 |
| - | |
2727 |
| - | |
2728 |
| - | |
2729 |
| - | |
| 2731 | + | |
| 2732 | + | |
2730 | 2733 |
| |
2731 |
| - | |
| 2734 | + | |
| 2735 | + | |
2732 | 2736 |
| |
2733 | 2737 |
| |
2734 | 2738 |
| |
2735 |
| - | |
| 2739 | + | |
| 2740 | + | |
2736 | 2741 |
| |
2737 |
| - | |
2738 |
| - | |
2739 |
| - | |
2740 |
| - | |
2741 |
| - | |
2742 |
| - | |
2743 |
| - | |
2744 |
| - | |
2745 |
| - | |
2746 |
| - | |
2747 |
| - | |
2748 |
| - | |
2749 |
| - | |
2750 |
| - | |
2751 |
| - | |
| 2742 | + | |
| 2743 | + | |
| 2744 | + | |
| 2745 | + | |
| 2746 | + | |
| 2747 | + | |
| 2748 | + | |
| 2749 | + | |
| 2750 | + | |
| 2751 | + | |
| 2752 | + | |
| 2753 | + | |
2752 | 2754 |
| |
2753 |
| - | |
2754 |
| - | |
2755 |
| - | |
2756 |
| - | |
2757 |
| - | |
2758 |
| - | |
2759 |
| - | |
2760 |
| - | |
2761 |
| - | |
2762 |
| - | |
2763 |
| - | |
| 2755 | + | |
| 2756 | + | |
| 2757 | + | |
| 2758 | + | |
| 2759 | + | |
| 2760 | + | |
| 2761 | + | |
| 2762 | + | |
| 2763 | + | |
| 2764 | + | |
2764 | 2765 |
| |
2765 |
| - | |
2766 |
| - | |
2767 |
| - | |
2768 |
| - | |
2769 |
| - | |
| 2766 | + | |
| 2767 | + | |
| 2768 | + | |
| 2769 | + | |
| 2770 | + | |
2770 | 2771 |
| |
2771 |
| - | |
2772 |
| - | |
2773 |
| - | |
2774 |
| - | |
2775 |
| - | |
2776 |
| - | |
| 2772 | + | |
| 2773 | + | |
| 2774 | + | |
| 2775 | + | |
| 2776 | + | |
| 2777 | + | |
2777 | 2778 |
| |
2778 |
| - | |
2779 |
| - | |
2780 |
| - | |
2781 |
| - | |
2782 |
| - | |
2783 |
| - | |
2784 |
| - | |
2785 |
| - | |
2786 |
| - | |
2787 |
| - | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
2788 | 2789 |
| |
2789 |
| - | |
2790 |
| - | |
2791 |
| - | |
2792 |
| - | |
2793 |
| - | |
2794 |
| - | |
2795 |
| - | |
2796 |
| - | |
2797 |
| - | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
| 2793 | + | |
| 2794 | + | |
| 2795 | + | |
| 2796 | + | |
| 2797 | + | |
| 2798 | + | |
2798 | 2799 |
| |
2799 |
| - | |
2800 |
| - | |
2801 |
| - | |
2802 |
| - | |
| 2800 | + | |
| 2801 | + | |
| 2802 | + | |
| 2803 | + | |
2803 | 2804 |
| |
2804 |
| - | |
2805 |
| - | |
| 2805 | + | |
| 2806 | + | |
2806 | 2807 |
| |
2807 |
| - | |
2808 |
| - | |
2809 |
| - | |
2810 |
| - | |
2811 |
| - | |
2812 |
| - | |
2813 |
| - | |
2814 |
| - | |
2815 |
| - | |
2816 |
| - | |
| 2808 | + | |
| 2809 | + | |
| 2810 | + | |
| 2811 | + | |
| 2812 | + | |
| 2813 | + | |
| 2814 | + | |
| 2815 | + | |
| 2816 | + | |
| 2817 | + | |
| 2818 | + | |
| 2819 | + | |
| 2820 | + | |
| 2821 | + | |
2817 | 2822 |
| |
2818 |
| - | |
2819 |
| - | |
2820 |
| - | |
2821 |
| - | |
2822 |
| - | |
2823 |
| - | |
| 2823 | + | |
| 2824 | + | |
2824 | 2825 |
| |
2825 |
| - | |
2826 |
| - | |
2827 |
| - | |
2828 |
| - | |
2829 |
| - | |
2830 |
| - | |
2831 |
| - | |
| 2826 | + | |
| 2827 | + | |
| 2828 | + | |
| 2829 | + | |
2832 | 2830 |
| |
| 2831 | + | |
| 2832 | + | |
2833 | 2833 |
| |
2834 | 2834 |
| |
2835 | 2835 |
| |
|
Lines changed: 20 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
847 | 847 |
| |
848 | 848 |
| |
849 | 849 |
| |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
850 | 856 |
| |
851 | 857 |
| |
852 | 858 |
| |
| |||
865 | 871 |
| |
866 | 872 |
| |
867 | 873 |
| |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
868 | 888 |
| |
869 | 889 |
| |
870 | 890 |
| |
|
0 commit comments
Comments
(0)