-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix alter table drop constraint not able to drop some constraints (#2575
) Babelfish was hashing the constraint name for named table constraints. But no hashing was done for unnamed table constraints, unnamed column constraints or named column constraints. On the other hand the constraint name in DROP CONSTRAINT was always hashed without exception. This means we were failing DROP for all constraints which were not hashed during creation. As a fix, we have removed the hashing step from named table constraints creation, making creation of constraints consistent for babelfish. This also allows us to remove hashing from DROP CONSTRAINT command. Not hashing constraint name has one repercussion, Users can now create a PRIMARY KEY/UNIQUE constraint with same name as an existing Index on the same table. This was previously blocked for named table constraints but not for other types of constraints. We could block this in the future in a more complete way. Issues Resolved: BABEL-2047 Signed-off-by: Tanzeel Khan [email protected]
- Loading branch information
1 parent
eda23ea
commit 9727955
Showing
49 changed files
with
1,698 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
DROP INDEX idx on babel_621_vu_prepare_table_1; | ||
DROP INDEX idx on babel_621_vu_prepare_table_2; | ||
GO | ||
|
||
DROP INDEX uniq on babel_621_vu_prepare_table_3; | ||
GO | ||
~~ERROR (Code: 3723)~~ | ||
|
||
~~ERROR (Message: cannot drop index uniqbabel_621_vu_prepare_table_d6716c55a366d04accd1036436eb2a86 because constraint uniqbabel_621_vu_prepare_table_d6716c55a366d04accd1036436eb2a86 on table babel_621_vu_prepare_table_3 requires it)~~ | ||
|
||
|
||
DROP INDEX very_long_index_name_on_a_table_1234567890_1234567890_1234567890_1234567890_1234567890 on babel_621_vu_prepare_table_with_long_index_name; | ||
GO | ||
|
||
DROP INDEX very_long_index_name_on_a_table_1234567890_1234567890_1234567890_1234567890_1234567890 on babel_621_table_with_long_name_1234567890_1234567890_1234567890_1234567890_1234567890; | ||
GO | ||
|
||
DROP TABLE babel_621_vu_prepare_table_1; | ||
GO | ||
DROP TABLE babel_621_vu_prepare_table_2; | ||
GO | ||
DROP TABLE babel_621_vu_prepare_table_3; | ||
GO | ||
DROP TABLE babel_621_vu_prepare_table_4; | ||
GO | ||
DROP TABLE babel_621_vu_prepare_table_with_long_index_name; | ||
GO | ||
DROP TABLE babel_621_vu_prepare_second_table_with_long_index_name; | ||
GO | ||
DROP TABLE babel_621_table_with_long_name_1234567890_1234567890_1234567890_1234567890_1234567890; | ||
GO | ||
DROP TABLE babel_621_second_table_with_long_name_1234567890_1234567890_1234567890_1234567890_1234567890; | ||
GO | ||
DROP TABLE babel_621_vu_prepare_table_6; | ||
GO | ||
DROP TABLE table_6; | ||
GO | ||
DROP TABLE table_7; | ||
GO | ||
DROP TABLE babel_621_vu_prepare_table_7; | ||
GO | ||
DROP TABLE babel_621_vu_prepare_table_8; | ||
GO | ||
DROP TABLE babel_621_vu_prepare_table_10; | ||
GO |
126 changes: 126 additions & 0 deletions
126
test/JDBC/expected/BABEL-621-before-14_13-vu-prepare.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
EXECUTE sp_babelfish_configure 'escape_hatch_unique_constraint', 'ignore' | ||
go | ||
|
||
create table babel_621_vu_prepare_table_1 (a int); | ||
go | ||
create table babel_621_vu_prepare_table_2 (a int); | ||
go | ||
create index idx on babel_621_vu_prepare_table_1(a); | ||
go | ||
create index idx on babel_621_vu_prepare_table_2(a); | ||
go | ||
|
||
create table babel_621_vu_prepare_table_3 (a int); | ||
go | ||
alter table babel_621_vu_prepare_table_3 add constraint uniq unique (a); | ||
go | ||
create index uniq on babel_621_vu_prepare_table_3(a); | ||
go | ||
~~ERROR (Code: 2714)~~ | ||
|
||
~~ERROR (Message: relation "uniqbabel_621_vu_prepare_table_d6716c55a366d04accd1036436eb2a86" already exists)~~ | ||
|
||
|
||
create table babel_621_vu_prepare_table_4 (a int); | ||
go | ||
create index uniq_table_4 on babel_621_vu_prepare_table_4(a); | ||
go | ||
alter table babel_621_vu_prepare_table_4 add constraint uniq_table_4 unique (a); | ||
go | ||
~~ERROR (Code: 2714)~~ | ||
|
||
~~ERROR (Message: relation "uniq_table_4babel_621_vu_prepardeacd0a0f930dee973c93a41c32c3ffc" already exists)~~ | ||
|
||
alter table babel_621_vu_prepare_table_4 drop constraint uniq_table_4; | ||
go | ||
~~ERROR (Code: 3728)~~ | ||
|
||
~~ERROR (Message: constraint "uniq_table_4babel_621_vu_prepardeacd0a0f930dee973c93a41c32c3ffc" of relation "babel_621_vu_prepare_table_4" does not exist)~~ | ||
|
||
|
||
-- Very long index name | ||
create table babel_621_vu_prepare_table_with_long_index_name (a int); | ||
go | ||
create index very_long_index_name_on_a_table_1234567890_1234567890_1234567890_1234567890_1234567890 on babel_621_vu_prepare_table_with_long_index_name(a); | ||
go | ||
|
||
create table babel_621_vu_prepare_second_table_with_long_index_name (a int); | ||
go | ||
create index very_long_index_name_on_a_table_1234567890_1234567890_1234567890_1234567890_1234567890 on babel_621_vu_prepare_second_table_with_long_index_name(a); | ||
go | ||
|
||
-- Very long table name and very long index name | ||
create table babel_621_table_with_long_name_1234567890_1234567890_1234567890_1234567890_1234567890 (a int); | ||
go | ||
create index very_long_index_name_on_a_table_1234567890_1234567890_1234567890_1234567890_1234567890 on babel_621_table_with_long_name_1234567890_1234567890_1234567890_1234567890_1234567890(a); | ||
go | ||
|
||
create table babel_621_second_table_with_long_name_1234567890_1234567890_1234567890_1234567890_1234567890 (a int); | ||
go | ||
create index very_long_index_name_on_a_table_1234567890_1234567890_1234567890_1234567890_1234567890 on babel_621_second_table_with_long_name_1234567890_1234567890_1234567890_1234567890_1234567890(a); | ||
go | ||
|
||
-- Situation where simple concatenation of table and index name does not work | ||
-- E.g. table_a + index_a == table_b + index_b | ||
create table babel_621_vu_prepare_table_6 (a int); | ||
go | ||
create index idx_ on babel_621_vu_prepare_table_6(a); | ||
go | ||
|
||
create table table_6 (a int); | ||
go | ||
create index idx_babel_621_vu_prepare_ on table_6(a); | ||
go | ||
-- Situation where simple concatenation of index and table name does not work (reverse of previous) | ||
-- E.g. index_a + table_a == index_b + table_b | ||
create table table_7 (a int); | ||
go | ||
create index idx_babel_621_vu_prepare_ on table_7(a); | ||
go | ||
|
||
create table babel_621_vu_prepare_table_7 (a int); | ||
go | ||
create index idx_ on babel_621_vu_prepare_table_7(a); | ||
go | ||
|
||
-- | ||
create table babel_621_vu_prepare_table_8 ( | ||
a int, | ||
value int, | ||
constraint constraint_8 unique nonclustered | ||
( | ||
value asc | ||
) | ||
) | ||
go | ||
alter table babel_621_vu_prepare_table_8 drop constraint constraint_8; | ||
go | ||
insert into babel_621_vu_prepare_table_8 values(1, 1); | ||
insert into babel_621_vu_prepare_table_8 values(2, 1); | ||
go | ||
~~ROW COUNT: 1~~ | ||
|
||
~~ROW COUNT: 1~~ | ||
|
||
|
||
create table babel_621_vu_prepare_table_10 | ||
( | ||
a int, | ||
b int, | ||
c int | ||
) | ||
go | ||
create unique index idx on babel_621_vu_prepare_table_10 (a, b); | ||
go | ||
insert into babel_621_vu_prepare_table_10 values(1, 1, 1); | ||
insert into babel_621_vu_prepare_table_10 values(1, 2, 1); | ||
insert into babel_621_vu_prepare_table_10 values(1, 2, 2); | ||
go | ||
~~ROW COUNT: 1~~ | ||
|
||
~~ROW COUNT: 1~~ | ||
|
||
~~ERROR (Code: 2627)~~ | ||
|
||
~~ERROR (Message: duplicate key value violates unique constraint "idxbabel_621_vu_prepare_table_147dc0d6e295169e8ba6e11ebeb1c6472")~~ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
select a, value from babel_621_vu_prepare_table_8 order by a; | ||
go | ||
~~START~~ | ||
int#!#int | ||
1#!#1 | ||
2#!#1 | ||
~~END~~ | ||
|
||
|
||
drop index idx on babel_621_vu_prepare_table_10; | ||
go | ||
insert into babel_621_vu_prepare_table_10 values(1, 2, 2); | ||
go | ||
~~ROW COUNT: 1~~ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.