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

Test changes for 'Fix error when trying to drop columns from temp tables.' #2753

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
74 changes: 74 additions & 0 deletions test/JDBC/expected/temp_table.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
-- BABEL-4912 test ALTER TABLE for temp tables
CREATE TABLE #t1 (a INT IDENTITY PRIMARY KEY NOT NULL, b INT)
GO

INSERT INTO #t1 (b) values (1)
GO
~~ROW COUNT: 1~~


SELECT * FROM #t1
GO
~~START~~
int#!#int
1#!#1
~~END~~


ALTER TABLE #t1 DROP COLUMN b
GO

SELECT * FROM #t1
GO
~~START~~
int
1
~~END~~


ALTER TABLE #t1 ADD b varchar(20)
GO

SELECT * FROM #t1
GO
~~START~~
int#!#varchar
1#!#<NULL>
~~END~~


ALTER TABLE #t1 ADD c AS a + 1
GO

SELECT * FROM #t1
GO
~~START~~
int#!#varchar#!#int
1#!#<NULL>#!#2
~~END~~


ALTER TABLE #t1 DROP COLUMN b
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add more tests, such as

  • dropping then recreating the same column multiple times
  • make sure that dependencies aren't broken (so if the column depends on another object, or an object depends on the column that the proper behavior happens)
  • more complicated dependencies such as with toast/index/identity etc
  • ensure that the table also works (i can select, update, drop from it normally)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added more test cases. Note that foreign key constraints are not allowed for temp tables, so I can't test that.

GO

SELECT * FROM #t1
GO
~~START~~
int#!#int
1#!#2
~~END~~


ALTER TABLE #t1 DROP COLUMN c
GO

SELECT * FROM #t1
GO
~~START~~
int
1
~~END~~


DROP TABLE #t1
GO
22 changes: 3 additions & 19 deletions test/JDBC/expected/temp_table_rollback-vu-verify.out
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ COMMIT
GO

----------------------------------------------------------
-- ALTER TABLE (should fail due to BABEL-4912)
-- ALTER TABLE (BABEL-4912)
----------------------------------------------------------
CREATE TABLE #temp_table_rollback_t1 (a int, b int)
GO
Expand All @@ -153,37 +153,21 @@ BEGIN TRAN
ALTER TABLE #temp_table_rollback_t1 DROP COLUMN b
ROLLBACK
GO
~~ERROR (Code: 3726)~~

~~ERROR (Message: cannot drop column b of table "#temp_table_rollback_t1" because other objects depend on it)~~

Comment on lines -156 to -159
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for handling this.
Do we have tests for scenarios where it's supposed to fail with this error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added an extra test case, that while not reproducing this exact error, produces a similar error due to a dependency.


BEGIN TRAN
ALTER TABLE #temp_table_rollback_t1 ALTER COLUMN b VARCHAR
ROLLBACK
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: unexpected object depending on column: type "#temp_table_rollback_t1")~~


BEGIN TRAN
ALTER TABLE #temp_table_rollback_t1 DROP COLUMN b
ALTER TABLE #temp_table_rollback_t1 ALTER COLUMN b VARCHAR
COMMIT
GO
~~ERROR (Code: 3726)~~

~~ERROR (Message: cannot drop column b of table "#temp_table_rollback_t1" because other objects depend on it)~~


BEGIN TRAN
ALTER TABLE #temp_table_rollback_t1 ALTER COLUMN b VARCHAR
ALTER TABLE #temp_table_rollback_t1 DROP COLUMN b
COMMIT
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: unexpected object depending on column: type "#temp_table_rollback_t1")~~


DROP TABLE #temp_table_rollback_t1
GO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ COMMIT
GO

----------------------------------------------------------
-- ALTER TABLE (should fail due to BABEL-4912)
-- ALTER TABLE (BABEL-4912)
----------------------------------------------------------
CREATE TABLE #temp_table_rollback_t1 (a int, b int)
GO
Expand All @@ -221,37 +221,21 @@ BEGIN TRAN
ALTER TABLE #temp_table_rollback_t1 DROP COLUMN b
ROLLBACK
GO
~~ERROR (Code: 3726)~~

~~ERROR (Message: cannot drop column b of table "#temp_table_rollback_t1" because other objects depend on it)~~


BEGIN TRAN
ALTER TABLE #temp_table_rollback_t1 ALTER COLUMN b VARCHAR
ROLLBACK
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: unexpected object depending on column: type "#temp_table_rollback_t1")~~


BEGIN TRAN
ALTER TABLE #temp_table_rollback_t1 DROP COLUMN b
ALTER TABLE #temp_table_rollback_t1 ALTER COLUMN b VARCHAR
COMMIT
GO
~~ERROR (Code: 3726)~~

~~ERROR (Message: cannot drop column b of table "#temp_table_rollback_t1" because other objects depend on it)~~


BEGIN TRAN
ALTER TABLE #temp_table_rollback_t1 ALTER COLUMN b VARCHAR
ALTER TABLE #temp_table_rollback_t1 DROP COLUMN b
COMMIT
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: unexpected object depending on column: type "#temp_table_rollback_t1")~~


DROP TABLE #temp_table_rollback_t1
GO
Expand Down
22 changes: 3 additions & 19 deletions test/JDBC/expected/temp_table_rollback_isolation_snapshot.out
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ COMMIT
GO

----------------------------------------------------------
-- ALTER TABLE (should fail due to BABEL-4912)
-- ALTER TABLE (BABEL-4912)
----------------------------------------------------------
CREATE TABLE #temp_table_rollback_t1 (a int, b int)
GO
Expand All @@ -221,37 +221,21 @@ BEGIN TRAN
ALTER TABLE #temp_table_rollback_t1 DROP COLUMN b
ROLLBACK
GO
~~ERROR (Code: 3726)~~

~~ERROR (Message: cannot drop column b of table "#temp_table_rollback_t1" because other objects depend on it)~~


BEGIN TRAN
ALTER TABLE #temp_table_rollback_t1 ALTER COLUMN b VARCHAR
ROLLBACK
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: unexpected object depending on column: type "#temp_table_rollback_t1")~~


BEGIN TRAN
ALTER TABLE #temp_table_rollback_t1 DROP COLUMN b
ALTER TABLE #temp_table_rollback_t1 ALTER COLUMN b VARCHAR
COMMIT
GO
~~ERROR (Code: 3726)~~

~~ERROR (Message: cannot drop column b of table "#temp_table_rollback_t1" because other objects depend on it)~~


BEGIN TRAN
ALTER TABLE #temp_table_rollback_t1 ALTER COLUMN b VARCHAR
ALTER TABLE #temp_table_rollback_t1 DROP COLUMN b
COMMIT
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: unexpected object depending on column: type "#temp_table_rollback_t1")~~


DROP TABLE #temp_table_rollback_t1
GO
Expand Down
22 changes: 3 additions & 19 deletions test/JDBC/expected/temp_table_rollback_xact_abort_on.out
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ COMMIT
GO

----------------------------------------------------------
-- ALTER TABLE (should fail due to BABEL-4912)
-- ALTER TABLE (BABEL-4912)
----------------------------------------------------------
CREATE TABLE #temp_table_rollback_t1 (a int, b int)
GO
Expand All @@ -221,37 +221,21 @@ BEGIN TRAN
ALTER TABLE #temp_table_rollback_t1 DROP COLUMN b
ROLLBACK
GO
~~ERROR (Code: 3726)~~

~~ERROR (Message: cannot drop column b of table "#temp_table_rollback_t1" because other objects depend on it)~~


BEGIN TRAN
ALTER TABLE #temp_table_rollback_t1 ALTER COLUMN b VARCHAR
ROLLBACK
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: unexpected object depending on column: type "#temp_table_rollback_t1")~~


BEGIN TRAN
ALTER TABLE #temp_table_rollback_t1 DROP COLUMN b
ALTER TABLE #temp_table_rollback_t1 ALTER COLUMN b VARCHAR
COMMIT
GO
~~ERROR (Code: 3726)~~

~~ERROR (Message: cannot drop column b of table "#temp_table_rollback_t1" because other objects depend on it)~~


BEGIN TRAN
ALTER TABLE #temp_table_rollback_t1 ALTER COLUMN b VARCHAR
ALTER TABLE #temp_table_rollback_t1 DROP COLUMN b
COMMIT
GO
~~ERROR (Code: 33557097)~~

~~ERROR (Message: unexpected object depending on column: type "#temp_table_rollback_t1")~~


DROP TABLE #temp_table_rollback_t1
GO
Expand Down
42 changes: 42 additions & 0 deletions test/JDBC/input/temp_tables/temp_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
-- BABEL-4912 test ALTER TABLE for temp tables
CREATE TABLE #t1 (a INT IDENTITY PRIMARY KEY NOT NULL, b INT)
GO

INSERT INTO #t1 (b) values (1)
GO

SELECT * FROM #t1
GO

ALTER TABLE #t1 DROP COLUMN b
GO

SELECT * FROM #t1
GO

ALTER TABLE #t1 ADD b varchar(20)
GO

SELECT * FROM #t1
GO

ALTER TABLE #t1 ADD c AS a + 1
GO

SELECT * FROM #t1
GO

ALTER TABLE #t1 DROP COLUMN b
GO

SELECT * FROM #t1
GO

ALTER TABLE #t1 DROP COLUMN c
GO

SELECT * FROM #t1
GO

DROP TABLE #t1
GO
6 changes: 3 additions & 3 deletions test/JDBC/input/temp_tables/temp_table_rollback-vu-verify.sql
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ COMMIT
GO

----------------------------------------------------------
-- ALTER TABLE (should fail due to BABEL-4912)
-- ALTER TABLE (BABEL-4912)
----------------------------------------------------------
CREATE TABLE #temp_table_rollback_t1 (a int, b int)
GO
Expand All @@ -95,12 +95,12 @@ ROLLBACK
GO

BEGIN TRAN
ALTER TABLE #temp_table_rollback_t1 DROP COLUMN b
ALTER TABLE #temp_table_rollback_t1 ALTER COLUMN b VARCHAR
COMMIT
GO

BEGIN TRAN
ALTER TABLE #temp_table_rollback_t1 ALTER COLUMN b VARCHAR
ALTER TABLE #temp_table_rollback_t1 DROP COLUMN b
COMMIT
GO

Expand Down
Loading