Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix alter table drop constraint not able to drop some constraints #2575

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/odbc-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
if: steps.install-extensions.outcome == 'success' && steps.install-unix-odbc-driver.outcome=='success'
run: |
cd ~
wget https://ftp.postgresql.org/pub/odbc/versions/src/psqlodbc-16.00.0000.tar.gz
wget https://ftp.postgresql.org/pub/odbc/versions.old/src/psqlodbc-16.00.0000.tar.gz
tar -zxvf psqlodbc-16.00.0000.tar.gz
cd psqlodbc-16.00.0000
./configure
Expand Down
7 changes: 0 additions & 7 deletions contrib/babelfishpg_tsql/src/pl_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -844,8 +844,6 @@ pltsql_post_parse_analyze(ParseState *pstate, Query *query, JumbleState *jstate)
{
Constraint *c = (Constraint *) element;

c->conname = construct_unique_index_name(c->conname, stmt->relation->relname);

if (rowversion_column_name)
validate_rowversion_table_constraint(c, rowversion_column_name);
}
Expand Down Expand Up @@ -933,8 +931,6 @@ pltsql_post_parse_analyze(ParseState *pstate, Query *query, JumbleState *jstate)
{
Constraint *c = castNode(Constraint, cmd->def);

c->conname = construct_unique_index_name(c->conname, atstmt->relation->relname);

if (escape_hatch_unique_constraint != EH_IGNORE &&
c->contype == CONSTR_UNIQUE &&
is_nullable_constraint(c, relid))
Expand Down Expand Up @@ -1024,9 +1020,6 @@ pltsql_post_parse_analyze(ParseState *pstate, Query *query, JumbleState *jstate)
}
}
break;
case AT_DropConstraint:
cmd->name = construct_unique_index_name(cmd->name, atstmt->relation->relname);
break;
default:
break;
}
Expand Down
13 changes: 5 additions & 8 deletions test/JDBC/expected/BABEL-1206-vu-prepare.out
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,10 @@ go

CREATE TABLE babel_1206_vu_prepare_t4(
[DistinctApplicationID] [bigint] IDENTITY(1,1) NOT NULL,
[Description] [nvarchar](1024) NOT NULL,
[DescriptionHash] AS (hashbytes('MD5',[Description])) PERSISTED NOT NULL,
CONSTRAINT babel_1206_vu_prepare_t4_i3 UNIQUE NONCLUSTERED
(
[DescriptionHash] ASC
)
) ON [PRIMARY]
[Description] [nvarchar](1024) NOT NULL CONSTRAINT babel_1206_vu_prepare_t4_i3 UNIQUE NONCLUSTERED,
[DescriptionHash] AS (hashbytes('MD5',[Description])) PERSISTED NOT NULL
)
ON [PRIMARY]
go

insert into babel_1206_vu_prepare_t4 values (0xaaa);
Expand All @@ -59,5 +56,5 @@ insert into babel_1206_vu_prepare_t4 values (0xaaa);
go
~~ERROR (Code: 2627)~~

~~ERROR (Message: duplicate key value violates unique constraint "babel_1206_vu_prepare_t4_i3babeaa1c56a90ff7306469195c2b5d1e115d")~~
~~ERROR (Message: duplicate key value violates unique constraint "babel_1206_vu_prepare_t4_i3")~~

2 changes: 1 addition & 1 deletion test/JDBC/expected/BABEL-1206.out
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ insert into babel_1206_t3 values (0xaaa);
go
~~ERROR (Code: 2627)~~

~~ERROR (Message: duplicate key value violates unique constraint "babel_1206_t3_i3babel_1206_t36b8d8d363edb759764e0add37a7a2ded")~~
~~ERROR (Message: duplicate key value violates unique constraint "babel_1206_t3_i3")~~


drop table babel_1265_t1;
Expand Down
4 changes: 2 additions & 2 deletions test/JDBC/expected/BABEL-1715-vu-prepare.out
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use master;
go

CREATE TABLE babel_1715_vu_prepare_t1 (a int, b int CONSTRAINT uk_a PRIMARY KEY (a));
CREATE TABLE babel_1715_vu_prepare_t1 (a int CONSTRAINT uk_a PRIMARY KEY, b int);
go

INSERT INTO babel_1715_vu_prepare_t1 VALUES (1, 1);
Expand All @@ -12,7 +12,7 @@ GO
~~ROW COUNT: 1~~


CREATE TABLE babel_1715_vu_prepare_t2 (a int, b as a+1 CONSTRAINT uk_a PRIMARY KEY (a));
CREATE TABLE babel_1715_vu_prepare_t2 (a int CONSTRAINT uk_a1 PRIMARY KEY, b as a+1);
go

INSERT INTO babel_1715_vu_prepare_t2 (a) VALUES (1);
Expand Down
4 changes: 2 additions & 2 deletions test/JDBC/expected/BABEL-1715-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ INSERT INTO babel_1715_vu_prepare_t1 VALUES (2, 3);
GO
~~ERROR (Code: 2627)~~

~~ERROR (Message: duplicate key value violates unique constraint "uk_ababel_1715_vu_prepare_t1309394cc13ed0160c093d0a0f82cb1c0")~~
~~ERROR (Message: duplicate key value violates unique constraint "uk_a")~~


INSERT INTO babel_1715_vu_prepare_t2 (a) VALUES (2);
GO
~~ERROR (Code: 2627)~~

~~ERROR (Message: duplicate key value violates unique constraint "uk_ababel_1715_vu_prepare_t2309394cc13ed0160c093d0a0f82cb1c0")~~
~~ERROR (Message: duplicate key value violates unique constraint "uk_a1")~~


CREATE TABLE babel_1715_vu_prepare_invalid1 (a int b int);
Expand Down
4 changes: 2 additions & 2 deletions test/JDBC/expected/BABEL-1715.out
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ INSERT INTO t1715 VALUES (2, 3);
go
~~ERROR (Code: 2627)~~

~~ERROR (Message: duplicate key value violates unique constraint "uk_at1715309394cc13ed0160c093d0a0f82cb1c0")~~
~~ERROR (Message: duplicate key value violates unique constraint "uk_a")~~

drop table t1715;
go
Expand All @@ -33,7 +33,7 @@ INSERT INTO t1715_2 (a) VALUES (2);
go
~~ERROR (Code: 2627)~~

~~ERROR (Message: duplicate key value violates unique constraint "uk_at1715_2309394cc13ed0160c093d0a0f82cb1c0")~~
~~ERROR (Message: duplicate key value violates unique constraint "uk_a")~~

drop table t1715_2;
go
Expand Down
45 changes: 45 additions & 0 deletions test/JDBC/expected/BABEL-621-before-14_13-vu-cleanup.out
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 test/JDBC/expected/BABEL-621-before-14_13-vu-prepare.out
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")~~

15 changes: 15 additions & 0 deletions test/JDBC/expected/BABEL-621-before-14_13-vu-verify.out
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~~

4 changes: 0 additions & 4 deletions test/JDBC/expected/BABEL-621-vu-cleanup.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ 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
Expand Down
12 changes: 0 additions & 12 deletions test/JDBC/expected/BABEL-621-vu-prepare.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,15 @@ 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ ALTER TABLE [dbo].[alter_table_check_constraint] ADD CONSTRAINT [check_col1] CHE
GO
~~ERROR (Code: 547)~~

~~ERROR (Message: check constraint "check_col1alter_table_check_con0f71bca531f50db1bd071ab46c3097ea" of relation "alter_table_check_constraint" is violated by some row)~~
~~ERROR (Message: check constraint "check_col1" of relation "alter_table_check_constraint" is violated by some row)~~

4 changes: 2 additions & 2 deletions test/JDBC/expected/BABEL-CHECK-CONSTRAINT-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ALTER TABLE [dbo].[alter_table_check_constraint] ADD CONSTRAINT [check_col1] CHE
GO
~~ERROR (Code: 547)~~

~~ERROR (Message: check constraint "check_col1alter_table_check_con0f71bca531f50db1bd071ab46c3097ea" of relation "alter_table_check_constraint" is violated by some row)~~
~~ERROR (Message: check constraint "check_col1" of relation "alter_table_check_constraint" is violated by some row)~~


ALTER TABLE check_constraint ADD CONSTRAINT [check_a] CHECK (a not like N'123%')
Expand All @@ -18,7 +18,7 @@ INSERT INTO check_constraint VALUES ('1234'), ('123123')
GO
~~ERROR (Code: 547)~~

~~ERROR (Message: new row for relation "check_constraint" violates check constraint "check_acheck_constraint719599f27c48404560d418ff018273e1")~~
~~ERROR (Message: new row for relation "check_constraint" violates check constraint "check_a")~~


INSERT INTO create_check_constraint VALUES ('abcdEFg')
Expand Down
2 changes: 1 addition & 1 deletion test/JDBC/expected/BABEL-TABLEOPTIONS-vu-prepare.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CREATE TABLE babel_tableoptions_vu_prepare_t1 (a INT, CONSTRAINT pk PRIMARY KEY CLUSTERED (a ASC)) WITH
CREATE TABLE babel_tableoptions_vu_prepare_t1 (a INT, CONSTRAINT pk_99 PRIMARY KEY CLUSTERED (a ASC)) WITH
(PAD_INDEX = OFF,
STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF,
Expand Down
Loading
Loading