Commit 5dcf331
committed
sql/schemachanger: support ALTER TABLE DROP CONSTRAINT for UNIQUE constraints
Previously, attempting to drop a UNIQUE constraint using
`ALTER TABLE ... DROP CONSTRAINT` would fail with an error directing
users to use `DROP INDEX CASCADE` instead. This was inconvenient for
users and broke compatibility with ORMs like Liquibase and Laravel
that use the standard `ALTER TABLE DROP CONSTRAINT` syntax.
This change implements support for dropping index-backed UNIQUE
constraints via `ALTER TABLE DROP CONSTRAINT` in the declarative
schema changer. The implementation reuses the existing `dropSecondaryIndex`
logic which handles all the complex dependency management including:
- Dependent views and functions
- Dependent FK constraints (with CASCADE support)
- Sharded and expression index cleanup
- Trigger dependencies
- Regional-by-row table validation
The legacy schema changer still does not support this operation and
will continue to direct users to use `DROP INDEX CASCADE`.
Fixes #42840
Epic: CRDB-31281
Release note (sql change): `ALTER TABLE ... DROP CONSTRAINT` can now
be used to drop UNIQUE constraints. The backing UNIQUE index will also
be dropped, as CockroachDB treats the constraint and index as the same
thing.1 parent 52845e0 commit 5dcf331
6 files changed
Lines changed: 104 additions & 29 deletions
File tree
- pkg
- ccl/multiregionccl
- sql
- catalog/tabledesc
- logictest/testdata/logic_test
- schemachanger/scbuild/internal/scbuildstmt
- workload/schemachange
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
716 | 716 | | |
717 | 717 | | |
718 | 718 | | |
| 719 | + | |
719 | 720 | | |
720 | 721 | | |
721 | 722 | | |
722 | 723 | | |
723 | 724 | | |
724 | 725 | | |
| 726 | + | |
725 | 727 | | |
726 | 728 | | |
727 | 729 | | |
728 | 730 | | |
729 | 731 | | |
730 | 732 | | |
| 733 | + | |
731 | 734 | | |
732 | 735 | | |
733 | 736 | | |
734 | 737 | | |
735 | 738 | | |
736 | 739 | | |
| 740 | + | |
737 | 741 | | |
738 | 742 | | |
739 | 743 | | |
740 | 744 | | |
741 | 745 | | |
742 | 746 | | |
| 747 | + | |
743 | 748 | | |
744 | 749 | | |
745 | 750 | | |
746 | 751 | | |
747 | 752 | | |
748 | 753 | | |
| 754 | + | |
749 | 755 | | |
750 | 756 | | |
751 | 757 | | |
752 | 758 | | |
753 | 759 | | |
754 | 760 | | |
| 761 | + | |
755 | 762 | | |
756 | 763 | | |
757 | 764 | | |
758 | 765 | | |
759 | 766 | | |
760 | 767 | | |
| 768 | + | |
761 | 769 | | |
762 | 770 | | |
763 | 771 | | |
764 | 772 | | |
765 | 773 | | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
766 | 781 | | |
767 | 782 | | |
768 | 783 | | |
769 | | - | |
| 784 | + | |
| 785 | + | |
770 | 786 | | |
771 | 787 | | |
772 | | - | |
| 788 | + | |
| 789 | + | |
773 | 790 | | |
774 | 791 | | |
775 | | - | |
| 792 | + | |
| 793 | + | |
776 | 794 | | |
777 | 795 | | |
778 | 796 | | |
| |||
796 | 814 | | |
797 | 815 | | |
798 | 816 | | |
799 | | - | |
| 817 | + | |
800 | 818 | | |
801 | 819 | | |
802 | 820 | | |
| |||
862 | 880 | | |
863 | 881 | | |
864 | 882 | | |
865 | | - | |
| 883 | + | |
866 | 884 | | |
867 | 885 | | |
868 | 886 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1372 | 1372 | | |
1373 | 1373 | | |
1374 | 1374 | | |
1375 | | - | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
1376 | 1384 | | |
1377 | 1385 | | |
1378 | 1386 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
217 | 220 | | |
218 | 221 | | |
219 | 222 | | |
| 223 | + | |
220 | 224 | | |
221 | 225 | | |
222 | 226 | | |
| |||
231 | 235 | | |
232 | 236 | | |
233 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
234 | 243 | | |
235 | 244 | | |
236 | 245 | | |
| |||
240 | 249 | | |
241 | 250 | | |
242 | 251 | | |
243 | | - | |
244 | | - | |
245 | | - | |
| 252 | + | |
| 253 | + | |
246 | 254 | | |
247 | 255 | | |
248 | 256 | | |
| |||
1882 | 1890 | | |
1883 | 1891 | | |
1884 | 1892 | | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
| 1900 | + | |
1885 | 1901 | | |
1886 | 1902 | | |
1887 | 1903 | | |
| 1904 | + | |
| 1905 | + | |
| 1906 | + | |
| 1907 | + | |
1888 | 1908 | | |
1889 | 1909 | | |
1890 | 1910 | | |
| |||
1907 | 1927 | | |
1908 | 1928 | | |
1909 | 1929 | | |
1910 | | - | |
1911 | 1930 | | |
1912 | 1931 | | |
1913 | 1932 | | |
| |||
1923 | 1942 | | |
1924 | 1943 | | |
1925 | 1944 | | |
1926 | | - | |
1927 | 1945 | | |
1928 | 1946 | | |
1929 | 1947 | | |
| |||
1949 | 1967 | | |
1950 | 1968 | | |
1951 | 1969 | | |
1952 | | - | |
1953 | 1970 | | |
1954 | 1971 | | |
1955 | 1972 | | |
| |||
Lines changed: 44 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| |||
45 | 44 | | |
46 | 45 | | |
47 | 46 | | |
48 | | - | |
49 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
50 | 51 | | |
51 | 52 | | |
52 | 53 | | |
| |||
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
136 | | - | |
137 | | - | |
138 | | - | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
139 | 148 | | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
149 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
150 | 179 | | |
151 | 180 | | |
152 | 181 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2209 | 2209 | | |
2210 | 2210 | | |
2211 | 2211 | | |
| 2212 | + | |
| 2213 | + | |
2212 | 2214 | | |
2213 | 2215 | | |
2214 | 2216 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2001 | 2001 | | |
2002 | 2002 | | |
2003 | 2003 | | |
2004 | | - | |
| 2004 | + | |
| 2005 | + | |
2005 | 2006 | | |
2006 | 2007 | | |
2007 | 2008 | | |
2008 | 2009 | | |
2009 | | - | |
| 2010 | + | |
2010 | 2011 | | |
2011 | 2012 | | |
2012 | 2013 | | |
| |||
0 commit comments