From b1d086ef86adaad9c70dbe70e2c863e6e9ead62c Mon Sep 17 00:00:00 2001 From: ANJU BHARTI Date: Wed, 13 Nov 2024 10:11:13 +0000 Subject: [PATCH] Revert "Block cross-db 'SELECT ... INTO table FROM ...' statement (#2744) (#2780)" This reverts commit 0b401ee7b3b08eb84903ac283b65d6d071c77d06. --- contrib/babelfishpg_tsql/src/tsqlIface.cpp | 16 -- test/JDBC/expected/BABEL-CROSS-DB.out | 203 ---------------- .../expected/single_db/BABEL-CROSS-DB.out | 223 ------------------ test/JDBC/input/BABEL-CROSS-DB.mix | 139 ----------- 4 files changed, 581 deletions(-) diff --git a/contrib/babelfishpg_tsql/src/tsqlIface.cpp b/contrib/babelfishpg_tsql/src/tsqlIface.cpp index e131415420..3968085313 100644 --- a/contrib/babelfishpg_tsql/src/tsqlIface.cpp +++ b/contrib/babelfishpg_tsql/src/tsqlIface.cpp @@ -1790,22 +1790,6 @@ class tsqlBuilder : public tsqlCommonMutator if (is_schema_specified) stmt->is_schema_specified = true; - if (is_cross_db) - { - if (ctx->select_statement_standalone() && - ctx->select_statement_standalone()->select_statement() && - ctx->select_statement_standalone()->select_statement()->query_expression() && - ctx->select_statement_standalone()->select_statement()->query_expression()->query_specification() && - ctx->select_statement_standalone()->select_statement()->query_expression()->query_specification()->INTO() && - ctx->select_statement_standalone()->select_statement()->query_expression()->query_specification()->table_name()) - { - throw PGErrorWrapperException(ERROR, - ERRCODE_FEATURE_NOT_SUPPORTED, - "cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.", - getLineAndPos(ctx->select_statement_standalone())); - } - } - if (is_compiling_create_function()) { /* select without destination should be blocked. We can use already information about desitnation, which is already processed. */ diff --git a/test/JDBC/expected/BABEL-CROSS-DB.out b/test/JDBC/expected/BABEL-CROSS-DB.out index 6ef99326ca..9da8dc2c1e 100644 --- a/test/JDBC/expected/BABEL-CROSS-DB.out +++ b/test/JDBC/expected/BABEL-CROSS-DB.out @@ -523,206 +523,3 @@ GO DROP DATABASE db2; GO - --- BABEL-4934 Test blocking cross-db SELECT-INTO statement -CREATE DATABASE db_4934_1; -GO - -CREATE DATABASE db_4934_2; -GO - -USE master; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_1; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_2; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_1; -GO - --- #4934.1 It should be blocked -SELECT * INTO t222 FROM master.dbo.t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM master..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM db_4934_2.dbo.t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM db_4934_2..t1, t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM t1, db_4934_1..t2; -GO - -SELECT * INTO t222 FROM master..t1, db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT * FROM master..t1) AS Subquery; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT * FROM t1, master..t1) AS Subquery; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM master..t1) FROM t1) AS Subquery; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM t1) FROM master..t3) AS Subquery; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO master..t222 FROM db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO db_4934_1..t222 FROM db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO master..t222 FROM master..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - --- #4934.2 Following statements will succeed across same database -SELECT * INTO t3 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO t4 FROM dbo.t1; -GO - -SELECT * INTO t5 FROM db_4934_1..t1; -GO - -SELECT * INTO t6 FROM db_4934_1..t1, db_4934_1..t2; -GO - -SELECT * INTO t7 FROM (SELECT * FROM db_4934_1..t1) AS Subquery; -GO - -SELECT * INTO t8 FROM (SELECT *, (SELECT * FROM db_4934_1..t2) FROM db_4934_1..t1) AS Subquery; -GO - --- validate the access -SELECT * FROM t3, t4, t5, t6, t7, t8; -GO -~~START~~ -int#!#int#!#int#!#int#!#int#!#int#!#int#!#int -~~END~~ - - -DROP TABLE t3, t4, t5, t6, t7, t8; -GO - --- #4934.3 Temporary table should not be blocked -SELECT * INTO #t1 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO #t2 FROM (SELECT * FROM db_4934_1.dbo.t1) AS Subquery; -GO - --- validate the access -SELECT * FROM #t1, #t2; -GO -~~START~~ -int#!#int -~~END~~ - - -DROP TABLE #t1, #t2; -GO - --- Even though this is same as above statement, this will still fail since --- internally it considers as cross-db statement (This behaviour is general to --- all of the applicable DMLs) -SELECT * INTO tempdb..#t3 FROM db_4934_1.dbo.t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - - -USE master; -GO - -DROP TABLE t1, t2; -GO - -DROP DATABASE db_4934_1; -GO - -DROP DATABASE db_4934_2; -GO diff --git a/test/JDBC/expected/single_db/BABEL-CROSS-DB.out b/test/JDBC/expected/single_db/BABEL-CROSS-DB.out index 6a22e060fc..6d96ce1c0c 100644 --- a/test/JDBC/expected/single_db/BABEL-CROSS-DB.out +++ b/test/JDBC/expected/single_db/BABEL-CROSS-DB.out @@ -545,226 +545,3 @@ GO ~~ERROR (Message: database "db2" does not exist)~~ - --- BABEL-4934 Test blocking cross-db SELECT-INTO statement -CREATE DATABASE db_4934_1; -GO - -CREATE DATABASE db_4934_2; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: Only one user database allowed under single-db mode. User database "db_4934_1" already exists)~~ - - -USE master; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_1; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_2; -GO -~~ERROR (Code: 911)~~ - -~~ERROR (Message: database "db_4934_2" does not exist)~~ - - -CREATE TABLE t1(a int); -GO -~~ERROR (Code: 2714)~~ - -~~ERROR (Message: relation "t1" already exists)~~ - - -CREATE TABLE t2(b int); -GO -~~ERROR (Code: 2714)~~ - -~~ERROR (Message: relation "t2" already exists)~~ - - -USE db_4934_1; -GO - --- #4934.1 It should be blocked -SELECT * INTO t222 FROM master.dbo.t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM master..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM db_4934_2.dbo.t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM db_4934_2..t1, t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM t1, db_4934_1..t2; -GO - -SELECT * INTO t222 FROM master..t1, db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT * FROM master..t1) AS Subquery; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT * FROM t1, master..t1) AS Subquery; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM master..t1) FROM t1) AS Subquery; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM t1) FROM master..t3) AS Subquery; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO master..t222 FROM db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO db_4934_1..t222 FROM db_4934_2..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - -SELECT * INTO master..t222 FROM master..t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - --- #4934.2 Following statements will succeed across same database -SELECT * INTO t3 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO t4 FROM dbo.t1; -GO - -SELECT * INTO t5 FROM db_4934_1..t1; -GO - -SELECT * INTO t6 FROM db_4934_1..t1, db_4934_1..t2; -GO - -SELECT * INTO t7 FROM (SELECT * FROM db_4934_1..t1) AS Subquery; -GO - -SELECT * INTO t8 FROM (SELECT *, (SELECT * FROM db_4934_1..t2) FROM db_4934_1..t1) AS Subquery; -GO - --- validate the access -SELECT * FROM t3, t4, t5, t6, t7, t8; -GO -~~START~~ -int#!#int#!#int#!#int#!#int#!#int#!#int#!#int -~~END~~ - - -DROP TABLE t3, t4, t5, t6, t7, t8; -GO - --- #4934.3 Temporary table should not be blocked -SELECT * INTO #t1 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO #t2 FROM (SELECT * FROM db_4934_1.dbo.t1) AS Subquery; -GO - --- validate the access -SELECT * FROM #t1, #t2; -GO -~~START~~ -int#!#int -~~END~~ - - -DROP TABLE #t1, #t2; -GO - --- Even though this is same as above statement, this will still fail since --- internally it considers as cross-db statement (This behaviour is general to --- all of the applicable DMLs) -SELECT * INTO tempdb..#t3 FROM db_4934_1.dbo.t1; -GO -~~ERROR (Code: 33557097)~~ - -~~ERROR (Message: cross-db 'SELECT INTO' statement is not supported in Babelfish. As a workaround, consider running CREATE TABLE and INSERT-SELECT statements.)~~ - - - -USE master; -GO - -DROP TABLE t1, t2; -GO - -DROP DATABASE db_4934_1; -GO - -DROP DATABASE db_4934_2; -GO -~~ERROR (Code: 911)~~ - -~~ERROR (Message: database "db_4934_2" does not exist)~~ - diff --git a/test/JDBC/input/BABEL-CROSS-DB.mix b/test/JDBC/input/BABEL-CROSS-DB.mix index 6e5317afd5..92084d58c0 100644 --- a/test/JDBC/input/BABEL-CROSS-DB.mix +++ b/test/JDBC/input/BABEL-CROSS-DB.mix @@ -352,142 +352,3 @@ GO DROP DATABASE db2; GO - --- BABEL-4934 Test blocking cross-db SELECT-INTO statement -CREATE DATABASE db_4934_1; -GO - -CREATE DATABASE db_4934_2; -GO - -USE master; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_1; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_2; -GO - -CREATE TABLE t1(a int); -GO - -CREATE TABLE t2(b int); -GO - -USE db_4934_1; -GO - --- #4934.1 It should be blocked -SELECT * INTO t222 FROM master.dbo.t1; -GO - -SELECT * INTO t222 FROM master..t1; -GO - -SELECT * INTO t222 FROM db_4934_2..t1; -GO - -SELECT * INTO t222 FROM db_4934_2.dbo.t1; -GO - -SELECT * INTO t222 FROM db_4934_2..t1, t1; -GO - -SELECT * INTO t222 FROM t1, db_4934_1..t2; -GO - -SELECT * INTO t222 FROM master..t1, db_4934_2..t1; -GO - -SELECT * INTO t222 FROM (SELECT * FROM master..t1) AS Subquery; -GO - -SELECT * INTO t222 FROM (SELECT * FROM t1, master..t1) AS Subquery; -GO - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM master..t1) FROM t1) AS Subquery; -GO - -SELECT * INTO t222 FROM (SELECT *, (SELECT * FROM t1) FROM master..t3) AS Subquery; -GO - -SELECT * INTO master..t222 FROM db_4934_2..t1; -GO - -SELECT * INTO db_4934_1..t222 FROM db_4934_2..t1; -GO - -SELECT * INTO master..t222 FROM master..t1; -GO - --- #4934.2 Following statements will succeed across same database -SELECT * INTO t3 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO t4 FROM dbo.t1; -GO - -SELECT * INTO t5 FROM db_4934_1..t1; -GO - -SELECT * INTO t6 FROM db_4934_1..t1, db_4934_1..t2; -GO - -SELECT * INTO t7 FROM (SELECT * FROM db_4934_1..t1) AS Subquery; -GO - -SELECT * INTO t8 FROM (SELECT *, (SELECT * FROM db_4934_1..t2) FROM db_4934_1..t1) AS Subquery; -GO - --- validate the access -SELECT * FROM t3, t4, t5, t6, t7, t8; -GO - -DROP TABLE t3, t4, t5, t6, t7, t8; -GO - --- #4934.3 Temporary table should not be blocked -SELECT * INTO #t1 FROM db_4934_1.dbo.t1; -GO - -SELECT * INTO #t2 FROM (SELECT * FROM db_4934_1.dbo.t1) AS Subquery; -GO - --- validate the access -SELECT * FROM #t1, #t2; -GO - -DROP TABLE #t1, #t2; -GO - --- Even though this is same as above statement, this will still fail since --- internally it considers as cross-db statement (This behaviour is general to --- all of the applicable DMLs) -SELECT * INTO tempdb..#t3 FROM db_4934_1.dbo.t1; -GO - - -USE master; -GO - -DROP TABLE t1, t2; -GO - -DROP DATABASE db_4934_1; -GO - -DROP DATABASE db_4934_2; -GO