From cc4a6f5edf7fcddd64aaefabbfa69263de958517 Mon Sep 17 00:00:00 2001 From: Dipesh Dhameliya Date: Thu, 26 Dec 2024 14:03:34 +0000 Subject: [PATCH 01/10] clean up left over objects properly --- test/JDBC/input/BABEL-3952-vu-verify.sql | 5 ++++- test/JDBC/input/Test-Identity-vu-cleanup.sql | 3 +++ test/JDBC/input/babel_ddl.sql | 4 +++- test/JDBC/input/babel_unicode_charset.sql | 2 ++ test/JDBC/input/functions/BABEL-3953-datetrunc-vu-verify.sql | 3 +++ test/JDBC/input/functions/sys-eomonth-vu-cleanup.sql | 3 +++ .../input/table_variables/table_variable_xact_errors.sql | 3 +++ test/JDBC/input/todatetimeoffset.sql | 2 ++ test/JDBC/input/views/sys-index_columns-vu-cleanup.sql | 3 +++ test/JDBC/parallel_query_jdbc_schedule | 2 -- 10 files changed, 26 insertions(+), 4 deletions(-) diff --git a/test/JDBC/input/BABEL-3952-vu-verify.sql b/test/JDBC/input/BABEL-3952-vu-verify.sql index b60101ef34d..448054ea1a7 100644 --- a/test/JDBC/input/BABEL-3952-vu-verify.sql +++ b/test/JDBC/input/BABEL-3952-vu-verify.sql @@ -261,4 +261,7 @@ Create table dbucket(a time) insert into dbucket (a) values(date_bucket(minute,12, CAST('12:32:23.23' as time))) Select * from dbucket Select date_bucket(second,10, a) from dbucket -GO \ No newline at end of file +GO + +DROP TABLE IF EXISTS dbucket +GO diff --git a/test/JDBC/input/Test-Identity-vu-cleanup.sql b/test/JDBC/input/Test-Identity-vu-cleanup.sql index 75afc12aa63..e4520c81207 100644 --- a/test/JDBC/input/Test-Identity-vu-cleanup.sql +++ b/test/JDBC/input/Test-Identity-vu-cleanup.sql @@ -28,6 +28,9 @@ GO DROP PROCEDURE test_identity_vu_prepare_p5 GO +DROP VIEW scope_identity_view +GO + DROP TABLE test_identity_vu_prepare_t1 GO diff --git a/test/JDBC/input/babel_ddl.sql b/test/JDBC/input/babel_ddl.sql index 72015f2b777..d5367fdd353 100644 --- a/test/JDBC/input/babel_ddl.sql +++ b/test/JDBC/input/babel_ddl.sql @@ -253,4 +253,6 @@ GO drop table computed_column_t1; GO drop table computed_column_t2; -GO \ No newline at end of file +GO +drop table computed_column_error; +GO diff --git a/test/JDBC/input/babel_unicode_charset.sql b/test/JDBC/input/babel_unicode_charset.sql index 8cc45cbfdd3..ff56f55eff8 100644 --- a/test/JDBC/input/babel_unicode_charset.sql +++ b/test/JDBC/input/babel_unicode_charset.sql @@ -18,3 +18,5 @@ select "你好世界" from unicode_test with(nolock); go select 中文列名 from unicode_test with(nolock); go +drop table if exists unicode_test; +go diff --git a/test/JDBC/input/functions/BABEL-3953-datetrunc-vu-verify.sql b/test/JDBC/input/functions/BABEL-3953-datetrunc-vu-verify.sql index ebefb274629..224197178f2 100644 --- a/test/JDBC/input/functions/BABEL-3953-datetrunc-vu-verify.sql +++ b/test/JDBC/input/functions/BABEL-3953-datetrunc-vu-verify.sql @@ -168,6 +168,9 @@ Select * from dtrunc Select datetrunc(second, a) from dtrunc GO +DROP TABLE IF EXISTS dtrunc +GO + SET DATEFIRST 1 SELECT DATETRUNC(ISO_WEEK, CAST('2020-09-13 21:32:32.23' as datetime2)) SELECT DATETRUNC(WEEK, CAST('2020-09-13 21:32:32.23' as datetime2)) diff --git a/test/JDBC/input/functions/sys-eomonth-vu-cleanup.sql b/test/JDBC/input/functions/sys-eomonth-vu-cleanup.sql index 0a998c56df2..41a60d99ce6 100644 --- a/test/JDBC/input/functions/sys-eomonth-vu-cleanup.sql +++ b/test/JDBC/input/functions/sys-eomonth-vu-cleanup.sql @@ -9,3 +9,6 @@ GO DROP PROCEDURE IF EXISTS GetEndOfNextMonthDate_EOMONTH; GO + +DROP Table eomonth_datestable +GO diff --git a/test/JDBC/input/table_variables/table_variable_xact_errors.sql b/test/JDBC/input/table_variables/table_variable_xact_errors.sql index e5abf4577b5..19ce8c08717 100644 --- a/test/JDBC/input/table_variables/table_variable_xact_errors.sql +++ b/test/JDBC/input/table_variables/table_variable_xact_errors.sql @@ -484,6 +484,9 @@ GO EXECUTE myproc2 GO +DROP TABLE mytab +GO + DROP PROCEDURE myproc GO diff --git a/test/JDBC/input/todatetimeoffset.sql b/test/JDBC/input/todatetimeoffset.sql index cd0ccffa38f..5ab1db217f8 100644 --- a/test/JDBC/input/todatetimeoffset.sql +++ b/test/JDBC/input/todatetimeoffset.sql @@ -241,3 +241,5 @@ GO Select todatetimeoffset('10000-12-31 23:12:00.123 +00:00',743) GO +drop table tem +GO diff --git a/test/JDBC/input/views/sys-index_columns-vu-cleanup.sql b/test/JDBC/input/views/sys-index_columns-vu-cleanup.sql index 388239e528c..3e56be98ec6 100644 --- a/test/JDBC/input/views/sys-index_columns-vu-cleanup.sql +++ b/test/JDBC/input/views/sys-index_columns-vu-cleanup.sql @@ -7,6 +7,9 @@ GO USE master GO +DROP table sys_index_columns_vu_prepare_t1 +GO + DROP TABLE sys_index_columns_vu_prepare_t3; GO diff --git a/test/JDBC/parallel_query_jdbc_schedule b/test/JDBC/parallel_query_jdbc_schedule index 2a5f9ba88d7..84997b38889 100644 --- a/test/JDBC/parallel_query_jdbc_schedule +++ b/test/JDBC/parallel_query_jdbc_schedule @@ -28,6 +28,4 @@ ignore#!#BABEL-3013 ignore#!#BABEL-SP_TABLE_PRIVILEGES ignore#!#ISC-Columns-vu-verify ignore#!#four-part-names-vu-verify -#TODO: BABEL-5472 -ignore#!#sp_columns_100 From 42ca242117086f47e9fbf55c0b683f3e6a173837 Mon Sep 17 00:00:00 2001 From: Dipesh Dhameliya Date: Mon, 30 Dec 2024 06:13:31 +0000 Subject: [PATCH 02/10] disable bitmap heap scan temporary --- test/JDBC/input/sp_columns_100.sql | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/JDBC/input/sp_columns_100.sql b/test/JDBC/input/sp_columns_100.sql index 534eb5881cc..1f74b2b039c 100644 --- a/test/JDBC/input/sp_columns_100.sql +++ b/test/JDBC/input/sp_columns_100.sql @@ -1,5 +1,9 @@ -- sla_for_parallel_query_enforced 2000000 -- create tables with most of the datatypes + +SELECT set_config('enable_bitmapscan', 0, false); +GO + create table var(a char(10), b nchar(9), c nvarchar(8), d varchar(7), e text, f ntext, g varbinary(10), h binary(9), i image, j xml) go @@ -527,3 +531,6 @@ GO DROP SCHEMA [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_LongSchema] GO + +SELECT set_config('enable_bitmapscan', 1, false); +GO From 7585c31d88dc49346b5526600bb3e365efdb11f4 Mon Sep 17 00:00:00 2001 From: Dipesh Dhameliya Date: Mon, 30 Dec 2024 07:10:36 +0000 Subject: [PATCH 03/10] temp --- test/JDBC/expected/sp_columns_100.out | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/JDBC/expected/sp_columns_100.out b/test/JDBC/expected/sp_columns_100.out index dcf4a0d3d25..ac385246be1 100644 --- a/test/JDBC/expected/sp_columns_100.out +++ b/test/JDBC/expected/sp_columns_100.out @@ -1,4 +1,13 @@ + -- create tables with most of the datatypes +SELECT set_config('enable_bitmapscan', 0, false); +GO +~~START~~ +text +off +~~END~~ + + create table var(a char(10), b nchar(9), c nvarchar(8), d varchar(7), e text, f ntext, g varbinary(10), h binary(9), i image, j xml) go @@ -1044,3 +1053,11 @@ GO DROP SCHEMA [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_LongSchema] GO + +SELECT set_config('enable_bitmapscan', 1, false); +GO +~~START~~ +text +on +~~END~~ + From a514fd3f84050231cccb4fde37d55dac4b31061e Mon Sep 17 00:00:00 2001 From: Dipesh Dhameliya Date: Mon, 30 Dec 2024 11:25:52 +0000 Subject: [PATCH 04/10] get rid of column_internal() --- contrib/babelfishpg_tsql/sql/sys_views.sql | 160 ++++++++++++++++++++- 1 file changed, 156 insertions(+), 4 deletions(-) diff --git a/contrib/babelfishpg_tsql/sql/sys_views.sql b/contrib/babelfishpg_tsql/sql/sys_views.sql index e6394e17ff7..4318a708e6a 100644 --- a/contrib/babelfishpg_tsql/sql/sys_views.sql +++ b/contrib/babelfishpg_tsql/sql/sys_views.sql @@ -657,6 +657,157 @@ END; $$ language plpgsql STABLE; +CREATE OR REPLACE VIEW sys.columns_internal_view AS + SELECT CAST(c.oid AS int) as out_object_id, + CAST(a.attname AS sys.sysname) as out_name, + CAST(a.attnum AS int) as out_column_id, + CASE + WHEN tsql_type_name IS NOT NULL OR t.typbasetype = 0 THEN + -- either tsql or PG base type + CAST(a.atttypid AS int) + ELSE + CAST(t.typbasetype AS int) + END as out_system_type_id, + CAST(a.atttypid AS int) as out_user_type_id, + CASE + WHEN a.atttypmod != -1 THEN + sys.tsql_type_max_length_helper(coalesce(tsql_type_name, tsql_base_type_name), a.attlen, a.atttypmod) + ELSE + sys.tsql_type_max_length_helper(coalesce(tsql_type_name, tsql_base_type_name), a.attlen, t.typtypmod) + END as out_max_length, + CASE + WHEN a.atttypmod != -1 THEN + sys.tsql_type_precision_helper(coalesce(tsql_type_name, tsql_base_type_name), a.atttypmod) + ELSE + sys.tsql_type_precision_helper(coalesce(tsql_type_name, tsql_base_type_name), t.typtypmod) + END as out_precision, + CASE + WHEN a.atttypmod != -1 THEN + sys.tsql_type_scale_helper(coalesce(tsql_type_name, tsql_base_type_name), a.atttypmod, false) + ELSE + sys.tsql_type_scale_helper(coalesce(tsql_type_name, tsql_base_type_name), t.typtypmod, false) + END as out_scale, + CAST(coll.collname AS sys.sysname) as out_collation_name, + CAST(a.attcollation AS int) as out_collation_id, + CAST(a.attnum AS smallint) as out_offset, + CAST(case when a.attnotnull then 0 else 1 end AS sys.bit) as out_is_nullable, + CAST(t.typname in ('bpchar', 'nchar', 'binary') AS sys.bit) as out_is_ansi_padded, + CAST(0 AS sys.bit) as out_is_rowguidcol, + CAST(a.attidentity <> ''::"char" AS sys.bit) as out_is_identity, + CAST(a.attgenerated <> ''::"char" AS sys.bit) as out_is_computed, + CAST(0 AS sys.bit) as out_is_filestream, + CAST(0 AS sys.bit) as out_is_replicated, + CAST(0 AS sys.bit) as out_is_non_sql_subscribed, + CAST(0 AS sys.bit) as out_is_merge_published, + CAST(0 AS sys.bit) as out_is_dts_replicated, + CAST(0 AS sys.bit) as out_is_xml_document, + CAST(0 AS int) as out_xml_collection_id, + CAST(coalesce(d.oid, 0) AS int) as out_default_object_id, + CAST(coalesce((select oid from pg_constraint where conrelid = t.oid + and contype = 'c' and a.attnum = any(conkey) limit 1), 0) AS int) as out_rule_object_id, + CAST(0 AS sys.bit) as out_is_sparse, + CAST(0 AS sys.bit) as out_is_column_set, + CAST(0 AS sys.tinyint) as out_generated_always_type, + CAST('NOT_APPLICABLE' AS sys.nvarchar(60)) as out_generated_always_type_desc, + CAST(null AS int) as out_encryption_type, + CAST(null AS sys.nvarchar(64)) as out_encryption_type_desc, + CAST(null AS sys.sysname) as out_encryption_algorithm_name, + CAST(null AS int) as out_column_encryption_key_id, + CAST(null AS sys.sysname) as out_column_encryption_key_database_name, + CAST(0 AS sys.bit) as out_is_hidden, + CAST(0 AS sys.bit) as out_is_masked, + CAST(null AS int) as out_graph_type, + CAST(null AS sys.nvarchar(60)) as out_graph_type_desc +FROM pg_attribute a +INNER JOIN pg_class c ON c.oid = a.attrelid +INNER JOIN pg_type t ON t.oid = a.atttypid +INNER JOIN sys.schemas sch on c.relnamespace = sch.schema_id +INNER JOIN sys.pg_namespace_ext ext on sch.schema_id = ext.oid +LEFT JOIN pg_attrdef d ON c.oid = d.adrelid AND a.attnum = d.adnum AND a.attnum > 0 +LEFT JOIN pg_collation coll ON coll.oid = a.attcollation +, sys.translate_pg_type_to_tsql(a.atttypid) AS tsql_type_name +, sys.translate_pg_type_to_tsql(t.typbasetype) AS tsql_base_type_name +WHERE NOT a.attisdropped +-- r = ordinary table, i = index, S = sequence, t = TOAST table, v = view, m = materialized view, c = composite type, f = foreign table, p = partitioned table +AND c.relkind IN ('r', 'v', 'm', 'f', 'p') +AND c.relispartition = false +AND has_column_privilege(a.attrelid, a.attname, 'SELECT,INSERT,UPDATE,REFERENCES') +union all +-- system tables information +SELECT CAST(c.oid AS int) as out_object_id, + CAST(a.attname AS sys.sysname) as out_name, + CAST(a.attnum AS int) as out_column_id, + CASE + WHEN tsql_type_name IS NOT NULL OR t.typbasetype = 0 THEN + -- either tsql or PG base type + CAST(a.atttypid AS int) + ELSE + CAST(t.typbasetype AS int) + END as out_system_type_id, + CAST(a.atttypid AS int) as out_user_type_id, + CASE + WHEN a.atttypmod != -1 THEN + sys.tsql_type_max_length_helper(coalesce(tsql_type_name, tsql_base_type_name), a.attlen, a.atttypmod) + ELSE + sys.tsql_type_max_length_helper(coalesce(tsql_type_name, tsql_base_type_name), a.attlen, t.typtypmod) + END as out_max_length, + CASE + WHEN a.atttypmod != -1 THEN + sys.tsql_type_precision_helper(coalesce(tsql_type_name, tsql_base_type_name), a.atttypmod) + ELSE + sys.tsql_type_precision_helper(coalesce(tsql_type_name, tsql_base_type_name), t.typtypmod) + END as out_precision, + CASE + WHEN a.atttypmod != -1 THEN + sys.tsql_type_scale_helper(coalesce(tsql_type_name, tsql_base_type_name), a.atttypmod, false) + ELSE + sys.tsql_type_scale_helper(coalesce(tsql_type_name, tsql_base_type_name), t.typtypmod, false) + END as out_scale, + CAST(coll.collname AS sys.sysname) as out_collation_name, + CAST(a.attcollation AS int) as out_collation_id, + CAST(a.attnum AS smallint) as out_offset, + CAST(case when a.attnotnull then 0 else 1 end AS sys.bit) as out_is_nullable, + CAST(t.typname in ('bpchar', 'nchar', 'binary') AS sys.bit) as out_is_ansi_padded, + CAST(0 AS sys.bit) as out_is_rowguidcol, + CAST(a.attidentity <> ''::"char" AS sys.bit) as out_is_identity, + CAST(a.attgenerated <> ''::"char" AS sys.bit) as out_is_computed, + CAST(0 AS sys.bit) as out_is_filestream, + CAST(0 AS sys.bit) as out_is_replicated, + CAST(0 AS sys.bit) as out_is_non_sql_subscribed, + CAST(0 AS sys.bit) as out_is_merge_published, + CAST(0 AS sys.bit) as out_is_dts_replicated, + CAST(0 AS sys.bit) as out_is_xml_document, + CAST(0 AS int) as out_xml_collection_id, + CAST(coalesce(d.oid, 0) AS int) as out_default_object_id, + CAST(coalesce((select oid from pg_constraint where conrelid = t.oid + and contype = 'c' and a.attnum = any(conkey) limit 1), 0) AS int) as out_rule_object_id, + CAST(0 AS sys.bit) as out_is_sparse, + CAST(0 AS sys.bit) as out_is_column_set, + CAST(0 AS sys.tinyint) as out_generated_always_type, + CAST('NOT_APPLICABLE' AS sys.nvarchar(60)) as out_generated_always_type_desc, + CAST(null AS int) as out_encryption_type, + CAST(null AS sys.nvarchar(64)) as out_encryption_type_desc, + CAST(null AS sys.sysname) as out_encryption_algorithm_name, + CAST(null AS int) as out_column_encryption_key_id, + CAST(null AS sys.sysname) as out_column_encryption_key_database_name, + CAST(0 AS sys.bit) as out_is_hidden, + CAST(0 AS sys.bit) as out_is_masked, + CAST(null AS int) as out_graph_type, + CAST(null AS sys.nvarchar(60)) as out_graph_type_desc +FROM pg_attribute a +INNER JOIN pg_class c ON c.oid = a.attrelid +INNER JOIN pg_type t ON t.oid = a.atttypid +INNER JOIN pg_namespace nsp ON (nsp.oid = c.relnamespace and nsp.nspname = 'sys') +LEFT JOIN pg_attrdef d ON c.oid = d.adrelid AND a.attnum = d.adnum AND a.attnum > 0 +LEFT JOIN pg_collation coll ON coll.oid = a.attcollation +, sys.translate_pg_type_to_tsql(a.atttypid) AS tsql_type_name +, sys.translate_pg_type_to_tsql(t.typbasetype) AS tsql_base_type_name +WHERE NOT a.attisdropped +AND c.relkind = 'r' +AND has_column_privilege(a.attrelid, a.attname, 'SELECT,INSERT,UPDATE,REFERENCES'); + +GRANT SELECT on sys.columns_internal_view TO PUBLIC; + create or replace view sys.columns AS select out_object_id as object_id , out_name as name @@ -684,17 +835,18 @@ select out_object_id as object_id , out_is_sparse as is_sparse , out_is_column_set as is_column_set , out_generated_always_type as generated_always_type - , out_generated_always_type_desc as generated_always_type_desc + , cast(out_generated_always_type_desc as sys.NVARCHAR) as generated_always_type_desc , out_encryption_type as encryption_type - , out_encryption_type_desc as encryption_type_desc + , cast(out_encryption_type_desc as sys.NVARCHAR) as encryption_type_desc , out_encryption_algorithm_name as encryption_algorithm_name , out_column_encryption_key_id as column_encryption_key_id , out_column_encryption_key_database_name as column_encryption_key_database_name , out_is_hidden as is_hidden , out_is_masked as is_masked , out_graph_type as graph_type - , out_graph_type_desc as graph_type_desc -from sys.columns_internal(); + , cast(out_graph_type_desc as sys.NVARCHAR) as graph_type_desc +from sys.columns_internal_view; + GRANT SELECT ON sys.columns TO PUBLIC; CREATE OR replace view sys.foreign_key_columns as From cae2063ab3124a381233b8c5b155eb1a4f6d6b06 Mon Sep 17 00:00:00 2001 From: Dipesh Dhameliya Date: Wed, 8 Jan 2025 08:36:18 +0000 Subject: [PATCH 05/10] Just run only one test --- test/JDBC/jdbc_schedule | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/JDBC/jdbc_schedule b/test/JDBC/jdbc_schedule index ddb43e7efd2..d02fe400ddb 100644 --- a/test/JDBC/jdbc_schedule +++ b/test/JDBC/jdbc_schedule @@ -8,7 +8,8 @@ # new line # 6. If you want the framework to not run certain files, use: ignore#!# -all +# all +sp_columns_100 ignore#!#BABEL-1435 ignore#!#BABEL-1446 From 23d72cc2fb99a2195f668642d578a1a9a2353371 Mon Sep 17 00:00:00 2001 From: Dipesh Dhameliya Date: Wed, 8 Jan 2025 08:46:14 +0000 Subject: [PATCH 06/10] Revert unnecessary changes --- contrib/babelfishpg_tsql/sql/sys_views.sql | 160 +-------------------- 1 file changed, 4 insertions(+), 156 deletions(-) diff --git a/contrib/babelfishpg_tsql/sql/sys_views.sql b/contrib/babelfishpg_tsql/sql/sys_views.sql index 4318a708e6a..e6394e17ff7 100644 --- a/contrib/babelfishpg_tsql/sql/sys_views.sql +++ b/contrib/babelfishpg_tsql/sql/sys_views.sql @@ -657,157 +657,6 @@ END; $$ language plpgsql STABLE; -CREATE OR REPLACE VIEW sys.columns_internal_view AS - SELECT CAST(c.oid AS int) as out_object_id, - CAST(a.attname AS sys.sysname) as out_name, - CAST(a.attnum AS int) as out_column_id, - CASE - WHEN tsql_type_name IS NOT NULL OR t.typbasetype = 0 THEN - -- either tsql or PG base type - CAST(a.atttypid AS int) - ELSE - CAST(t.typbasetype AS int) - END as out_system_type_id, - CAST(a.atttypid AS int) as out_user_type_id, - CASE - WHEN a.atttypmod != -1 THEN - sys.tsql_type_max_length_helper(coalesce(tsql_type_name, tsql_base_type_name), a.attlen, a.atttypmod) - ELSE - sys.tsql_type_max_length_helper(coalesce(tsql_type_name, tsql_base_type_name), a.attlen, t.typtypmod) - END as out_max_length, - CASE - WHEN a.atttypmod != -1 THEN - sys.tsql_type_precision_helper(coalesce(tsql_type_name, tsql_base_type_name), a.atttypmod) - ELSE - sys.tsql_type_precision_helper(coalesce(tsql_type_name, tsql_base_type_name), t.typtypmod) - END as out_precision, - CASE - WHEN a.atttypmod != -1 THEN - sys.tsql_type_scale_helper(coalesce(tsql_type_name, tsql_base_type_name), a.atttypmod, false) - ELSE - sys.tsql_type_scale_helper(coalesce(tsql_type_name, tsql_base_type_name), t.typtypmod, false) - END as out_scale, - CAST(coll.collname AS sys.sysname) as out_collation_name, - CAST(a.attcollation AS int) as out_collation_id, - CAST(a.attnum AS smallint) as out_offset, - CAST(case when a.attnotnull then 0 else 1 end AS sys.bit) as out_is_nullable, - CAST(t.typname in ('bpchar', 'nchar', 'binary') AS sys.bit) as out_is_ansi_padded, - CAST(0 AS sys.bit) as out_is_rowguidcol, - CAST(a.attidentity <> ''::"char" AS sys.bit) as out_is_identity, - CAST(a.attgenerated <> ''::"char" AS sys.bit) as out_is_computed, - CAST(0 AS sys.bit) as out_is_filestream, - CAST(0 AS sys.bit) as out_is_replicated, - CAST(0 AS sys.bit) as out_is_non_sql_subscribed, - CAST(0 AS sys.bit) as out_is_merge_published, - CAST(0 AS sys.bit) as out_is_dts_replicated, - CAST(0 AS sys.bit) as out_is_xml_document, - CAST(0 AS int) as out_xml_collection_id, - CAST(coalesce(d.oid, 0) AS int) as out_default_object_id, - CAST(coalesce((select oid from pg_constraint where conrelid = t.oid - and contype = 'c' and a.attnum = any(conkey) limit 1), 0) AS int) as out_rule_object_id, - CAST(0 AS sys.bit) as out_is_sparse, - CAST(0 AS sys.bit) as out_is_column_set, - CAST(0 AS sys.tinyint) as out_generated_always_type, - CAST('NOT_APPLICABLE' AS sys.nvarchar(60)) as out_generated_always_type_desc, - CAST(null AS int) as out_encryption_type, - CAST(null AS sys.nvarchar(64)) as out_encryption_type_desc, - CAST(null AS sys.sysname) as out_encryption_algorithm_name, - CAST(null AS int) as out_column_encryption_key_id, - CAST(null AS sys.sysname) as out_column_encryption_key_database_name, - CAST(0 AS sys.bit) as out_is_hidden, - CAST(0 AS sys.bit) as out_is_masked, - CAST(null AS int) as out_graph_type, - CAST(null AS sys.nvarchar(60)) as out_graph_type_desc -FROM pg_attribute a -INNER JOIN pg_class c ON c.oid = a.attrelid -INNER JOIN pg_type t ON t.oid = a.atttypid -INNER JOIN sys.schemas sch on c.relnamespace = sch.schema_id -INNER JOIN sys.pg_namespace_ext ext on sch.schema_id = ext.oid -LEFT JOIN pg_attrdef d ON c.oid = d.adrelid AND a.attnum = d.adnum AND a.attnum > 0 -LEFT JOIN pg_collation coll ON coll.oid = a.attcollation -, sys.translate_pg_type_to_tsql(a.atttypid) AS tsql_type_name -, sys.translate_pg_type_to_tsql(t.typbasetype) AS tsql_base_type_name -WHERE NOT a.attisdropped --- r = ordinary table, i = index, S = sequence, t = TOAST table, v = view, m = materialized view, c = composite type, f = foreign table, p = partitioned table -AND c.relkind IN ('r', 'v', 'm', 'f', 'p') -AND c.relispartition = false -AND has_column_privilege(a.attrelid, a.attname, 'SELECT,INSERT,UPDATE,REFERENCES') -union all --- system tables information -SELECT CAST(c.oid AS int) as out_object_id, - CAST(a.attname AS sys.sysname) as out_name, - CAST(a.attnum AS int) as out_column_id, - CASE - WHEN tsql_type_name IS NOT NULL OR t.typbasetype = 0 THEN - -- either tsql or PG base type - CAST(a.atttypid AS int) - ELSE - CAST(t.typbasetype AS int) - END as out_system_type_id, - CAST(a.atttypid AS int) as out_user_type_id, - CASE - WHEN a.atttypmod != -1 THEN - sys.tsql_type_max_length_helper(coalesce(tsql_type_name, tsql_base_type_name), a.attlen, a.atttypmod) - ELSE - sys.tsql_type_max_length_helper(coalesce(tsql_type_name, tsql_base_type_name), a.attlen, t.typtypmod) - END as out_max_length, - CASE - WHEN a.atttypmod != -1 THEN - sys.tsql_type_precision_helper(coalesce(tsql_type_name, tsql_base_type_name), a.atttypmod) - ELSE - sys.tsql_type_precision_helper(coalesce(tsql_type_name, tsql_base_type_name), t.typtypmod) - END as out_precision, - CASE - WHEN a.atttypmod != -1 THEN - sys.tsql_type_scale_helper(coalesce(tsql_type_name, tsql_base_type_name), a.atttypmod, false) - ELSE - sys.tsql_type_scale_helper(coalesce(tsql_type_name, tsql_base_type_name), t.typtypmod, false) - END as out_scale, - CAST(coll.collname AS sys.sysname) as out_collation_name, - CAST(a.attcollation AS int) as out_collation_id, - CAST(a.attnum AS smallint) as out_offset, - CAST(case when a.attnotnull then 0 else 1 end AS sys.bit) as out_is_nullable, - CAST(t.typname in ('bpchar', 'nchar', 'binary') AS sys.bit) as out_is_ansi_padded, - CAST(0 AS sys.bit) as out_is_rowguidcol, - CAST(a.attidentity <> ''::"char" AS sys.bit) as out_is_identity, - CAST(a.attgenerated <> ''::"char" AS sys.bit) as out_is_computed, - CAST(0 AS sys.bit) as out_is_filestream, - CAST(0 AS sys.bit) as out_is_replicated, - CAST(0 AS sys.bit) as out_is_non_sql_subscribed, - CAST(0 AS sys.bit) as out_is_merge_published, - CAST(0 AS sys.bit) as out_is_dts_replicated, - CAST(0 AS sys.bit) as out_is_xml_document, - CAST(0 AS int) as out_xml_collection_id, - CAST(coalesce(d.oid, 0) AS int) as out_default_object_id, - CAST(coalesce((select oid from pg_constraint where conrelid = t.oid - and contype = 'c' and a.attnum = any(conkey) limit 1), 0) AS int) as out_rule_object_id, - CAST(0 AS sys.bit) as out_is_sparse, - CAST(0 AS sys.bit) as out_is_column_set, - CAST(0 AS sys.tinyint) as out_generated_always_type, - CAST('NOT_APPLICABLE' AS sys.nvarchar(60)) as out_generated_always_type_desc, - CAST(null AS int) as out_encryption_type, - CAST(null AS sys.nvarchar(64)) as out_encryption_type_desc, - CAST(null AS sys.sysname) as out_encryption_algorithm_name, - CAST(null AS int) as out_column_encryption_key_id, - CAST(null AS sys.sysname) as out_column_encryption_key_database_name, - CAST(0 AS sys.bit) as out_is_hidden, - CAST(0 AS sys.bit) as out_is_masked, - CAST(null AS int) as out_graph_type, - CAST(null AS sys.nvarchar(60)) as out_graph_type_desc -FROM pg_attribute a -INNER JOIN pg_class c ON c.oid = a.attrelid -INNER JOIN pg_type t ON t.oid = a.atttypid -INNER JOIN pg_namespace nsp ON (nsp.oid = c.relnamespace and nsp.nspname = 'sys') -LEFT JOIN pg_attrdef d ON c.oid = d.adrelid AND a.attnum = d.adnum AND a.attnum > 0 -LEFT JOIN pg_collation coll ON coll.oid = a.attcollation -, sys.translate_pg_type_to_tsql(a.atttypid) AS tsql_type_name -, sys.translate_pg_type_to_tsql(t.typbasetype) AS tsql_base_type_name -WHERE NOT a.attisdropped -AND c.relkind = 'r' -AND has_column_privilege(a.attrelid, a.attname, 'SELECT,INSERT,UPDATE,REFERENCES'); - -GRANT SELECT on sys.columns_internal_view TO PUBLIC; - create or replace view sys.columns AS select out_object_id as object_id , out_name as name @@ -835,18 +684,17 @@ select out_object_id as object_id , out_is_sparse as is_sparse , out_is_column_set as is_column_set , out_generated_always_type as generated_always_type - , cast(out_generated_always_type_desc as sys.NVARCHAR) as generated_always_type_desc + , out_generated_always_type_desc as generated_always_type_desc , out_encryption_type as encryption_type - , cast(out_encryption_type_desc as sys.NVARCHAR) as encryption_type_desc + , out_encryption_type_desc as encryption_type_desc , out_encryption_algorithm_name as encryption_algorithm_name , out_column_encryption_key_id as column_encryption_key_id , out_column_encryption_key_database_name as column_encryption_key_database_name , out_is_hidden as is_hidden , out_is_masked as is_masked , out_graph_type as graph_type - , cast(out_graph_type_desc as sys.NVARCHAR) as graph_type_desc -from sys.columns_internal_view; - + , out_graph_type_desc as graph_type_desc +from sys.columns_internal(); GRANT SELECT ON sys.columns TO PUBLIC; CREATE OR replace view sys.foreign_key_columns as From 54269e738e15b181620a3e4458a235beeb4e9f3e Mon Sep 17 00:00:00 2001 From: Dipesh Dhameliya Date: Wed, 8 Jan 2025 09:03:17 +0000 Subject: [PATCH 07/10] figure out all the left over objects --- test/JDBC/input/sp_columns_100.sql | 8 ++------ test/JDBC/jdbc_schedule | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/test/JDBC/input/sp_columns_100.sql b/test/JDBC/input/sp_columns_100.sql index 1f74b2b039c..047957ab398 100644 --- a/test/JDBC/input/sp_columns_100.sql +++ b/test/JDBC/input/sp_columns_100.sql @@ -1,8 +1,7 @@ -- sla_for_parallel_query_enforced 2000000 -- create tables with most of the datatypes - -SELECT set_config('enable_bitmapscan', 0, false); -GO +select relname, (select nspname from pg_namespace where oid = relnamespace) from pg_class where relnamespace in (select oid from pg_namespace where nspname in (select nspname from sys.babelfish_namespace_ext)) +go create table var(a char(10), b nchar(9), c nvarchar(8), d varchar(7), e text, f ntext, g varbinary(10), h binary(9), i image, j xml) go @@ -531,6 +530,3 @@ GO DROP SCHEMA [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_LongSchema] GO - -SELECT set_config('enable_bitmapscan', 1, false); -GO diff --git a/test/JDBC/jdbc_schedule b/test/JDBC/jdbc_schedule index d02fe400ddb..cd80ab85ed1 100644 --- a/test/JDBC/jdbc_schedule +++ b/test/JDBC/jdbc_schedule @@ -8,8 +8,8 @@ # new line # 6. If you want the framework to not run certain files, use: ignore#!# -# all -sp_columns_100 +all +# sp_columns_100 ignore#!#BABEL-1435 ignore#!#BABEL-1446 From 22559be2ea101412521f781a707728ea3976a0e7 Mon Sep 17 00:00:00 2001 From: Dipesh Dhameliya Date: Wed, 8 Jan 2025 09:49:07 +0000 Subject: [PATCH 08/10] Fixed missing cleanup --- test/JDBC/input/BABEL-3156.sql | 2 +- test/JDBC/input/storedProcedures/Test-sp_reset_connection.mix | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test/JDBC/input/BABEL-3156.sql b/test/JDBC/input/BABEL-3156.sql index 70cf1689c51..3881a0838ab 100644 --- a/test/JDBC/input/BABEL-3156.sql +++ b/test/JDBC/input/BABEL-3156.sql @@ -56,7 +56,7 @@ GO exec sp_describe_undeclared_parameters N'UPDATE BABEL_3156 SET a=@P1 WHERE not_a_col=@P2'; -G +GO DROP TABLE BABEL_3156; GO diff --git a/test/JDBC/input/storedProcedures/Test-sp_reset_connection.mix b/test/JDBC/input/storedProcedures/Test-sp_reset_connection.mix index 57cc553bc77..b6c0be07312 100644 --- a/test/JDBC/input/storedProcedures/Test-sp_reset_connection.mix +++ b/test/JDBC/input/storedProcedures/Test-sp_reset_connection.mix @@ -24,6 +24,8 @@ COMMIT TRANSACTION GO SELECT * FROM sp_reset_connection_test_table GO +DROP TABLE IF EXISTS sp_reset_connection_test_table; +GO -- 3. Test temp tables are deleted on reset CREATE TABLE #babel_temp_table (ID INT identity(1,1), Data INT) From 99fef4a8642e07a62137b8c3be7146f1c37f5b9a Mon Sep 17 00:00:00 2001 From: Dipesh Dhameliya Date: Wed, 8 Jan 2025 10:29:32 +0000 Subject: [PATCH 09/10] run_vacuum --- test/JDBC/input/sp_columns_000.mix | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 test/JDBC/input/sp_columns_000.mix diff --git a/test/JDBC/input/sp_columns_000.mix b/test/JDBC/input/sp_columns_000.mix new file mode 100644 index 00000000000..c4064d8fc57 --- /dev/null +++ b/test/JDBC/input/sp_columns_000.mix @@ -0,0 +1,3 @@ +-- psql +VACUUM ANALYZE +GO \ No newline at end of file From 8ff868987334c6dc694aef8f375c1a5adc1ff855 Mon Sep 17 00:00:00 2001 From: Dipesh Dhameliya Date: Mon, 13 Jan 2025 07:03:20 +0000 Subject: [PATCH 10/10] clean up pg_namespace --- test/JDBC/input/sp_columns_000.mix | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/test/JDBC/input/sp_columns_000.mix b/test/JDBC/input/sp_columns_000.mix index c4064d8fc57..ab860ee68cd 100644 --- a/test/JDBC/input/sp_columns_000.mix +++ b/test/JDBC/input/sp_columns_000.mix @@ -1,3 +1,26 @@ -- psql VACUUM ANALYZE -GO \ No newline at end of file +GO + +-- psql +CREATE OR REPLACE FUNCTION drop_orphaned_temp_schemas() RETURNS void AS $$ +DECLARE + schema_record RECORD; +BEGIN + FOR schema_record IN + SELECT nspname + FROM pg_namespace + WHERE nspname LIKE 'pg_temp%' + OR nspname LIKE 'pg_toast_temp%' + LOOP + EXECUTE 'DROP SCHEMA IF EXISTS ' || quote_ident(schema_record.nspname) || ' CASCADE'; + RAISE NOTICE 'Dropped schema: %', schema_record.nspname; + END LOOP; +END; +$$ LANGUAGE plpgsql; +GO + +-- psql +select drop_orphaned_temp_schemas() +GO +