diff --git a/contrib/babelfishpg_tsql/Version.config b/contrib/babelfishpg_tsql/Version.config index 22b4bf4c09..e2fb0ab18f 100644 --- a/contrib/babelfishpg_tsql/Version.config +++ b/contrib/babelfishpg_tsql/Version.config @@ -2,6 +2,6 @@ # places during the build process PGTSQL_MAJOR_VERSION=2 -PGTSQL_MINOR_VERSION=8 +PGTSQL_MINOR_VERSION=9 PGTSQL_MICRO_VERSION=0 diff --git a/contrib/babelfishpg_tsql/sql/sys_functions.sql b/contrib/babelfishpg_tsql/sql/sys_functions.sql index be580efceb..ac42472f6e 100644 --- a/contrib/babelfishpg_tsql/sql/sys_functions.sql +++ b/contrib/babelfishpg_tsql/sql/sys_functions.sql @@ -2750,36 +2750,55 @@ END; $$; GRANT EXECUTE ON FUNCTION sys.original_login() TO PUBLIC; -CREATE OR REPLACE FUNCTION sys.columnproperty(object_id oid, property name, property_name text) -RETURNS integer +CREATE OR REPLACE FUNCTION sys.columnproperty(object_id OID, property NAME, property_name TEXT) +RETURNS INTEGER LANGUAGE plpgsql STABLE STRICT AS $$ - -declare extra_bytes CONSTANT integer := 4; -declare return_value integer; -begin - return_value := ( - select - case LOWER(property_name) - when 'charmaxlen' COLLATE sys.database_default then - (select CASE WHEN a.atttypmod > 0 THEN a.atttypmod - extra_bytes ELSE NULL END from pg_catalog.pg_attribute a where a.attrelid = object_id and a.attname = property) - when 'allowsnull' COLLATE sys.database_default then - (select CASE WHEN a.attnotnull THEN 0 ELSE 1 END from pg_catalog.pg_attribute a where a.attrelid = object_id and a.attname = property) - else - null - end - ); - - RETURN return_value::integer; +DECLARE + extra_bytes CONSTANT INTEGER := 4; + return_value INTEGER; +BEGIN + return_value:= + CASE LOWER(property_name) + WHEN 'charmaxlen' COLLATE sys.database_default THEN (SELECT + CASE + WHEN a.atttypmod > 0 THEN a.atttypmod - extra_bytes + ELSE NULL + END FROM pg_catalog.pg_attribute a WHERE a.attrelid = object_id AND (a.attname = property COLLATE sys.database_default)) + WHEN 'allowsnull' COLLATE sys.database_default THEN (SELECT + CASE + WHEN a.attnotnull THEN 0 + ELSE 1 + END FROM pg_catalog.pg_attribute a WHERE a.attrelid = object_id AND (a.attname = property COLLATE sys.database_default)) + WHEN 'iscomputed' COLLATE sys.database_default THEN (SELECT + CASE + WHEN a.attgenerated != '' THEN 1 + ELSE 0 + END FROM pg_catalog.pg_attribute a WHERE a.attrelid = object_id and (a.attname = property COLLATE sys.database_default)) + WHEN 'columnid' COLLATE sys.database_default THEN + (SELECT a.attnum FROM pg_catalog.pg_attribute a + WHERE a.attrelid = object_id AND (a.attname = property COLLATE sys.database_default)) + WHEN 'ordinal' COLLATE sys.database_default THEN + (SELECT b.count FROM (SELECT attname, row_number() OVER () AS count FROM pg_catalog.pg_attribute a + WHERE a.attrelid = object_id AND attisdropped = false AND attnum > 0 ORDER BY a.attnum) AS b WHERE b.attname = property COLLATE sys.database_default) + WHEN 'isidentity' COLLATE sys.database_default THEN (SELECT + CASE + WHEN char_length(a.attidentity) > 0 THEN 1 + ELSE 0 + END FROM pg_catalog.pg_attribute a WHERE a.attrelid = object_id and (a.attname = property COLLATE sys.database_default)) + ELSE + NULL + END; + RETURN return_value::INTEGER; EXCEPTION WHEN others THEN RETURN NULL; END; $$; -GRANT EXECUTE ON FUNCTION sys.columnproperty(object_id oid, property name, property_name text) TO PUBLIC; +GRANT EXECUTE ON FUNCTION sys.columnproperty(object_id OID, property NAME, property_name TEXT) TO PUBLIC; -COMMENT ON FUNCTION sys.columnproperty +COMMENT ON FUNCTION sys.columnproperty IS 'This function returns column or parameter information. Currently only works with "charmaxlen", and "allowsnull" otherwise returns 0.'; -- substring -- diff --git a/contrib/babelfishpg_tsql/sql/sys_views.sql b/contrib/babelfishpg_tsql/sql/sys_views.sql index c765f2680c..95f859c52b 100644 --- a/contrib/babelfishpg_tsql/sql/sys_views.sql +++ b/contrib/babelfishpg_tsql/sql/sys_views.sql @@ -815,6 +815,15 @@ GRANT SELECT ON sys.identity_columns TO PUBLIC; create or replace view sys.indexes as -- Get all indexes from all system and user tables +with index_id_map as MATERIALIZED( + select + indexrelid, + case + when indisclustered then 1 + else 1+row_number() over(partition by indrelid order by indexrelid) + end as index_id + from pg_index +) select cast(X.indrelid as int) as object_id , cast(I.relname as sys.sysname) as name @@ -834,17 +843,14 @@ select , cast(0 as sys.bit) as has_filter , cast(null as sys.nvarchar) as filter_definition , cast(0 as sys.bit) as auto_created - , index_map.index_id + , cast(imap.index_id as int) as index_id from pg_index X +inner join index_id_map imap on imap.indexrelid = X.indexrelid inner join pg_class I on I.oid = X.indexrelid and I.relkind = 'i' inner join pg_namespace nsp on nsp.oid = I.relnamespace left join sys.babelfish_namespace_ext ext on (nsp.nspname = ext.nspname and ext.dbid = sys.db_id()) -- check if index is a unique constraint left join pg_constraint const on const.conindid = I.oid and const.contype = 'u' --- use rownumber to get index_id scoped on each objects -inner join -(select indexrelid, cast(case when indisclustered then 1 else 1+row_number() over(partition by indrelid) end as int) - as index_id from pg_index) as index_map on index_map.indexrelid = X.indexrelid where has_schema_privilege(I.relnamespace, 'USAGE') -- index is active and X.indislive @@ -2081,9 +2087,9 @@ SELECT out_object_id as object_id , out_graph_type_desc as graph_type_desc , cast(tsql_get_expr(d.adbin, d.adrelid) AS sys.nvarchar(4000)) AS definition , 1::sys.bit AS uses_database_collation - , 0::sys.bit AS is_persisted + , 1::sys.bit AS is_persisted FROM sys.columns_internal() sc -INNER JOIN pg_attribute a ON sc.out_name = a.attname COLLATE sys.database_default AND sc.out_column_id = a.attnum +INNER JOIN pg_attribute a ON sc.out_object_id = a.attrelid AND sc.out_column_id = a.attnum INNER JOIN pg_attrdef d ON d.adrelid = a.attrelid AND d.adnum = a.attnum WHERE a.attgenerated = 's' AND sc.out_is_computed::integer = 1; GRANT SELECT ON sys.computed_columns TO PUBLIC; @@ -2102,22 +2108,48 @@ SELECT CAST('TSQL Default TCP' AS sys.sysname) AS name , CAST(0 AS sys.bit) AS is_admin_endpoint; GRANT SELECT ON sys.endpoints TO PUBLIC; -create or replace view sys.index_columns -as -select i.indrelid::integer as object_id - , CAST(CASE WHEN i.indisclustered THEN 1 ELSE 1+row_number() OVER(PARTITION BY c.oid) END AS INTEGER) AS index_id - , a.attrelid::integer as index_column_id - , a.attnum::integer as column_id - , a.attnum::sys.tinyint as key_ordinal - , 0::sys.tinyint as partition_ordinal - , 0::sys.bit as is_descending_key - , 1::sys.bit as is_included_column -from pg_index as i -inner join pg_catalog.pg_attribute a on i.indexrelid = a.attrelid -inner join pg_class c on i.indrelid = c.oid -inner join sys.schemas sch on sch.schema_id = c.relnamespace -where has_schema_privilege(sch.schema_id, 'USAGE') -and has_table_privilege(c.oid, 'SELECT,INSERT,UPDATE,DELETE,TRUNCATE,TRIGGER'); +CREATE OR REPLACE VIEW sys.index_columns +AS +WITH index_id_map AS MATERIALIZED ( + SELECT + indexrelid, + CASE + WHEN indisclustered THEN 1 + ELSE 1+row_number() OVER(PARTITION BY indrelid ORDER BY indexrelid) + END AS index_id + FROM pg_index +) +SELECT + CAST(i.indrelid AS INT) AS object_id, + -- should match index_id of sys.indexes + CAST(imap.index_id AS INT) AS index_id, + CAST(a.index_column_id AS INT) AS index_column_id, + CAST(a.attnum AS INT) AS column_id, + CAST(CASE + WHEN a.index_column_id <= i.indnkeyatts THEN a.index_column_id + ELSE 0 + END AS SYS.TINYINT) AS key_ordinal, + CAST(0 AS SYS.TINYINT) AS partition_ordinal, + CAST(CASE + WHEN i.indoption[a.index_column_id-1] & 1 = 1 THEN 1 + ELSE 0 + END AS SYS.BIT) AS is_descending_key, + CAST(CASE + WHEN a.index_column_id > i.indnkeyatts THEN 1 + ELSE 0 + END AS SYS.BIT) AS is_included_column +FROM + pg_index i + INNER JOIN index_id_map imap ON imap.indexrelid = i.indexrelid + INNER JOIN pg_class c ON i.indrelid = c.oid + INNER JOIN pg_namespace nsp ON nsp.oid = c.relnamespace + LEFT JOIN sys.babelfish_namespace_ext ext ON (nsp.nspname = ext.nspname AND ext.dbid = sys.db_id()) + LEFT JOIN unnest(i.indkey) WITH ORDINALITY AS a(attnum, index_column_id) ON true +WHERE + has_schema_privilege(c.relnamespace, 'USAGE') AND + has_table_privilege(c.oid, 'SELECT,INSERT,UPDATE,DELETE,TRUNCATE,TRIGGER') AND + (nsp.nspname = 'sys' OR ext.nspname is not null) AND + i.indislive; GRANT SELECT ON sys.index_columns TO PUBLIC; -- internal function that returns relevant info needed diff --git a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--2.7.0--2.8.0.sql b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--2.7.0--2.8.0.sql index fa682a4c24..ec6a249c7c 100644 --- a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--2.7.0--2.8.0.sql +++ b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--2.7.0--2.8.0.sql @@ -1,5 +1,5 @@ -- complain if script is sourced in psql, rather than via ALTER EXTENSION -\echo Use "ALTER EXTENSION ""babelfishpg_tsql"" UPDATE TO '2.7.0'" to load this file. \quit +\echo Use "ALTER EXTENSION ""babelfishpg_tsql"" UPDATE TO '2.8.0'" to load this file. \quit -- add 'sys' to search path for the convenience SELECT set_config('search_path', 'sys, '||current_setting('search_path'), false); diff --git a/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--2.8.0--2.9.0.sql b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--2.8.0--2.9.0.sql new file mode 100644 index 0000000000..a2ec2e8d78 --- /dev/null +++ b/contrib/babelfishpg_tsql/sql/upgrades/babelfishpg_tsql--2.8.0--2.9.0.sql @@ -0,0 +1,279 @@ +-- complain if script is sourced in psql, rather than via ALTER EXTENSION +\echo Use "ALTER EXTENSION ""babelfishpg_tsql"" UPDATE TO '2.9.0'" to load this file. \quit + +-- add 'sys' to search path for the convenience +SELECT set_config('search_path', 'sys, '||current_setting('search_path'), false); + +-- This is a temporary procedure which is called during upgrade to update guest schema +-- for the guest users in the already existing databases +CREATE OR REPLACE PROCEDURE sys.babelfish_update_user_catalog_for_guest_schema() +LANGUAGE C +AS 'babelfishpg_tsql', 'update_user_catalog_for_guest_schema'; + +CALL sys.babelfish_update_user_catalog_for_guest_schema(); + +-- Drop this procedure after it gets executed once. +DROP PROCEDURE sys.babelfish_update_user_catalog_for_guest_schema(); + +-- Drops an object if it does not have any dependent objects. +-- Is a temporary procedure for use by the upgrade script. Will be dropped at the end of the upgrade. +-- Please have this be one of the first statements executed in this upgrade script. +CREATE OR REPLACE PROCEDURE babelfish_drop_deprecated_object(object_type varchar, schema_name varchar, object_name varchar) AS +$$ +DECLARE + error_msg text; + query1 text; + query2 text; +BEGIN + + query1 := pg_catalog.format('alter extension babelfishpg_tsql drop %s %s.%s', object_type, schema_name, object_name); + query2 := pg_catalog.format('drop %s %s.%s', object_type, schema_name, object_name); + + execute query1; + execute query2; +EXCEPTION + when object_not_in_prerequisite_state then --if 'alter extension' statement fails + GET STACKED DIAGNOSTICS error_msg = MESSAGE_TEXT; + raise warning '%', error_msg; + when dependent_objects_still_exist then --if 'drop view' statement fails + GET STACKED DIAGNOSTICS error_msg = MESSAGE_TEXT; + raise warning '%', error_msg; +end +$$ +LANGUAGE plpgsql; + +-- Please add your SQLs here +/* + * Note: These SQL statements may get executed multiple times specially when some features get backpatched. + * So make sure that any SQL statement (DDL/DML) being added here can be executed multiple times without affecting + * final behaviour. + */ + + +CREATE OR REPLACE VIEW sys.index_columns +AS +WITH index_id_map AS MATERIALIZED ( + SELECT + indexrelid, + CASE + WHEN indisclustered THEN 1 + ELSE 1+row_number() OVER(PARTITION BY indrelid ORDER BY indexrelid) + END AS index_id + FROM pg_index +) +SELECT + CAST(i.indrelid AS INT) AS object_id, + -- should match index_id of sys.indexes + CAST(imap.index_id AS INT) AS index_id, + CAST(a.index_column_id AS INT) AS index_column_id, + CAST(a.attnum AS INT) AS column_id, + CAST(CASE + WHEN a.index_column_id <= i.indnkeyatts THEN a.index_column_id + ELSE 0 + END AS SYS.TINYINT) AS key_ordinal, + CAST(0 AS SYS.TINYINT) AS partition_ordinal, + CAST(CASE + WHEN i.indoption[a.index_column_id-1] & 1 = 1 THEN 1 + ELSE 0 + END AS SYS.BIT) AS is_descending_key, + CAST(CASE + WHEN a.index_column_id > i.indnkeyatts THEN 1 + ELSE 0 + END AS SYS.BIT) AS is_included_column +FROM + pg_index i + INNER JOIN index_id_map imap ON imap.indexrelid = i.indexrelid + INNER JOIN pg_class c ON i.indrelid = c.oid + INNER JOIN pg_namespace nsp ON nsp.oid = c.relnamespace + LEFT JOIN sys.babelfish_namespace_ext ext ON (nsp.nspname = ext.nspname AND ext.dbid = sys.db_id()) + LEFT JOIN unnest(i.indkey) WITH ORDINALITY AS a(attnum, index_column_id) ON true +WHERE + has_schema_privilege(c.relnamespace, 'USAGE') AND + has_table_privilege(c.oid, 'SELECT,INSERT,UPDATE,DELETE,TRUNCATE,TRIGGER') AND + (nsp.nspname = 'sys' OR ext.nspname is not null) AND + i.indislive; +GRANT SELECT ON sys.index_columns TO PUBLIC; + + +CREATE OR REPLACE FUNCTION sys.columnproperty(object_id OID, property NAME, property_name TEXT) +RETURNS INTEGER +LANGUAGE plpgsql +STABLE STRICT +AS $$ +DECLARE + extra_bytes CONSTANT INTEGER := 4; + return_value INTEGER; +BEGIN + return_value:= + CASE LOWER(property_name) + WHEN 'charmaxlen' COLLATE sys.database_default THEN (SELECT + CASE + WHEN a.atttypmod > 0 THEN a.atttypmod - extra_bytes + ELSE NULL + END FROM pg_catalog.pg_attribute a WHERE a.attrelid = object_id AND (a.attname = property COLLATE sys.database_default)) + WHEN 'allowsnull' COLLATE sys.database_default THEN (SELECT + CASE + WHEN a.attnotnull THEN 0 + ELSE 1 + END FROM pg_catalog.pg_attribute a WHERE a.attrelid = object_id AND (a.attname = property COLLATE sys.database_default)) + WHEN 'iscomputed' COLLATE sys.database_default THEN (SELECT + CASE + WHEN a.attgenerated != '' THEN 1 + ELSE 0 + END FROM pg_catalog.pg_attribute a WHERE a.attrelid = object_id and (a.attname = property COLLATE sys.database_default)) + WHEN 'columnid' COLLATE sys.database_default THEN + (SELECT a.attnum FROM pg_catalog.pg_attribute a + WHERE a.attrelid = object_id AND (a.attname = property COLLATE sys.database_default)) + WHEN 'ordinal' COLLATE sys.database_default THEN + (SELECT b.count FROM (SELECT attname, row_number() OVER () AS count FROM pg_catalog.pg_attribute a + WHERE a.attrelid = object_id AND attisdropped = false AND attnum > 0 ORDER BY a.attnum) AS b WHERE b.attname = property COLLATE sys.database_default) + WHEN 'isidentity' COLLATE sys.database_default THEN (SELECT + CASE + WHEN char_length(a.attidentity) > 0 THEN 1 + ELSE 0 + END FROM pg_catalog.pg_attribute a WHERE a.attrelid = object_id and (a.attname = property COLLATE sys.database_default)) + ELSE + NULL + END; + RETURN return_value::INTEGER; +EXCEPTION + WHEN others THEN + RETURN NULL; +END; +$$; +GRANT EXECUTE ON FUNCTION sys.columnproperty(object_id OID, property NAME, property_name TEXT) TO PUBLIC; + +CREATE OR REPLACE VIEW sys.computed_columns +AS +SELECT out_object_id as object_id + , out_name as name + , out_column_id as column_id + , out_system_type_id as system_type_id + , out_user_type_id as user_type_id + , out_max_length as max_length + , out_precision as precision + , out_scale as scale + , out_collation_name as collation_name + , out_is_nullable as is_nullable + , out_is_ansi_padded as is_ansi_padded + , out_is_rowguidcol as is_rowguidcol + , out_is_identity as is_identity + , out_is_computed as is_computed + , out_is_filestream as is_filestream + , out_is_replicated as is_replicated + , out_is_non_sql_subscribed as is_non_sql_subscribed + , out_is_merge_published as is_merge_published + , out_is_dts_replicated as is_dts_replicated + , out_is_xml_document as is_xml_document + , out_xml_collection_id as xml_collection_id + , out_default_object_id as default_object_id + , out_rule_object_id as rule_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 + , out_encryption_type as encryption_type + , 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 + , out_graph_type_desc as graph_type_desc + , cast(tsql_get_expr(d.adbin, d.adrelid) AS sys.nvarchar(4000)) AS definition + , 1::sys.bit AS uses_database_collation + , 1::sys.bit AS is_persisted +FROM sys.columns_internal() sc +INNER JOIN pg_attribute a ON sc.out_object_id = a.attrelid AND sc.out_column_id = a.attnum +INNER JOIN pg_attrdef d ON d.adrelid = a.attrelid AND d.adnum = a.attnum +WHERE a.attgenerated = 's' AND sc.out_is_computed::integer = 1; +GRANT SELECT ON sys.computed_columns TO PUBLIC; + + +create or replace view sys.indexes as +-- Get all indexes from all system and user tables +with index_id_map as MATERIALIZED( + select + indexrelid, + case + when indisclustered then 1 + else 1+row_number() over(partition by indrelid order by indexrelid) + end as index_id + from pg_index +) +select + cast(X.indrelid as int) as object_id + , cast(I.relname as sys.sysname) as name + , cast(case when X.indisclustered then 1 else 2 end as sys.tinyint) as type + , cast(case when X.indisclustered then 'CLUSTERED' else 'NONCLUSTERED' end as sys.nvarchar(60)) as type_desc + , cast(case when X.indisunique then 1 else 0 end as sys.bit) as is_unique + , cast(I.reltablespace as int) as data_space_id + , cast(0 as sys.bit) as ignore_dup_key + , cast(case when X.indisprimary then 1 else 0 end as sys.bit) as is_primary_key + , cast(case when const.oid is null then 0 else 1 end as sys.bit) as is_unique_constraint + , cast(0 as sys.tinyint) as fill_factor + , cast(case when X.indpred is null then 0 else 1 end as sys.bit) as is_padded + , cast(case when X.indisready then 0 else 1 end as sys.bit) as is_disabled + , cast(0 as sys.bit) as is_hypothetical + , cast(1 as sys.bit) as allow_row_locks + , cast(1 as sys.bit) as allow_page_locks + , cast(0 as sys.bit) as has_filter + , cast(null as sys.nvarchar) as filter_definition + , cast(0 as sys.bit) as auto_created + , cast(imap.index_id as int) as index_id +from pg_index X +inner join index_id_map imap on imap.indexrelid = X.indexrelid +inner join pg_class I on I.oid = X.indexrelid and I.relkind = 'i' +inner join pg_namespace nsp on nsp.oid = I.relnamespace +left join sys.babelfish_namespace_ext ext on (nsp.nspname = ext.nspname and ext.dbid = sys.db_id()) +-- check if index is a unique constraint +left join pg_constraint const on const.conindid = I.oid and const.contype = 'u' +where has_schema_privilege(I.relnamespace, 'USAGE') +-- index is active +and X.indislive +-- filter to get all the objects that belong to sys or babelfish schemas +and (nsp.nspname = 'sys' or ext.nspname is not null) + +union all +-- Create HEAP entries for each system and user table +select + cast(t.oid as int) as object_id + , cast(null as sys.sysname) as name + , cast(0 as sys.tinyint) as type + , cast('HEAP' as sys.nvarchar(60)) as type_desc + , cast(0 as sys.bit) as is_unique + , cast(1 as int) as data_space_id + , cast(0 as sys.bit) as ignore_dup_key + , cast(0 as sys.bit) as is_primary_key + , cast(0 as sys.bit) as is_unique_constraint + , cast(0 as sys.tinyint) as fill_factor + , cast(0 as sys.bit) as is_padded + , cast(0 as sys.bit) as is_disabled + , cast(0 as sys.bit) as is_hypothetical + , cast(1 as sys.bit) as allow_row_locks + , cast(1 as sys.bit) as allow_page_locks + , cast(0 as sys.bit) as has_filter + , cast(null as sys.nvarchar) as filter_definition + , cast(0 as sys.bit) as auto_created + , cast(0 as int) as index_id +from pg_class t +inner join pg_namespace nsp on nsp.oid = t.relnamespace +left join sys.babelfish_namespace_ext ext on (nsp.nspname = ext.nspname and ext.dbid = sys.db_id()) +where t.relkind = 'r' +-- filter to get all the objects that belong to sys or babelfish schemas +and (nsp.nspname = 'sys' or ext.nspname is not null) +and has_schema_privilege(t.relnamespace, 'USAGE') +and has_table_privilege(t.oid, 'SELECT,INSERT,UPDATE,DELETE,TRUNCATE,TRIGGER') +order by object_id, type_desc; +GRANT SELECT ON sys.indexes TO PUBLIC; + +-- Drops the temporary procedure used by the upgrade script. +-- Please have this be one of the last statements executed in this upgrade script. +DROP PROCEDURE sys.babelfish_drop_deprecated_object(varchar, varchar, varchar); + +-- After upgrade, always run analyze for all babelfish catalogs. +CALL sys.analyze_babelfish_catalogs(); + +-- Reset search_path to not affect any subsequent scripts +SELECT set_config('search_path', trim(leading 'sys, ' from current_setting('search_path')), false); diff --git a/contrib/babelfishpg_tsql/src/babelfish_version.h b/contrib/babelfishpg_tsql/src/babelfish_version.h index 4357163b82..1764cf3e8e 100644 --- a/contrib/babelfishpg_tsql/src/babelfish_version.h +++ b/contrib/babelfishpg_tsql/src/babelfish_version.h @@ -8,7 +8,7 @@ *------------------------------------------------------------------------- */ -#define BABELFISH_VERSION_STR "2.8.0" +#define BABELFISH_VERSION_STR "2.9.0" #define BABELFISH_INTERNAL_VERSION_STR "Babelfish 14.12.0.0" #define BABEL_COMPATIBILITY_VERSION "12.0.2000.8" #define BABEL_COMPATIBILITY_MAJOR_VERSION "12" diff --git a/test/JDBC/expected/BABEL_4817-vu-cleanup.out b/test/JDBC/expected/BABEL_4817-vu-cleanup.out new file mode 100644 index 0000000000..9cea17e236 --- /dev/null +++ b/test/JDBC/expected/BABEL_4817-vu-cleanup.out @@ -0,0 +1,2 @@ +DROP TABLE IF EXISTS babel_4817_t1, babel_4817_t2, babel_4817_t3; +GO diff --git a/test/JDBC/expected/BABEL_4817-vu-prepare.out b/test/JDBC/expected/BABEL_4817-vu-prepare.out new file mode 100644 index 0000000000..d4303de388 --- /dev/null +++ b/test/JDBC/expected/BABEL_4817-vu-prepare.out @@ -0,0 +1,33 @@ +-- tsql +CREATE TABLE babel_4817_t1 (col1 INT, col2 INT NOT NULL, col3 AS col1*col2, col4 INT, col5 INT, col6 INT, col7 INT IDENTITY, col8 INT NOT NULL, PRIMARY KEY NONCLUSTERED(col3, col7 ASC), UNIQUE (col2 ASC, col8)); +GO + +CREATE NONCLUSTERED INDEX babel_4817_t1_idx_1 ON dbo.babel_4817_t1 (col5) INCLUDE (col1); +GO + +-- psql +-- do not fail if index on expression is created from psql endpoint +CREATE INDEX babel_4817_t1_idx_psql ON master_dbo.babel_4817_t1 ((col6*2)) INCLUDE (col1); +GO + + +-- tsql +CREATE TABLE babel_4817_t2 (col1 INT, col2 INT NOT NULL, col3 AS col1*col2, col4 INT, col5 INT, col6 INT, col7 INT NOT NULL IDENTITY, col8 INT NOT NULL) +GO +ALTER TABLE babel_4817_t2 ADD CONSTRAINT babel_4817_t2_pk PRIMARY KEY NONCLUSTERED (col3, col7); +GO +-- clustered is ignored +CREATE UNIQUE NONCLUSTERED INDEX babel_4817_t2_unique_index ON dbo.babel_4817_t2 (col2 DESC, col8) INCLUDE (col4); +GO +CREATE NONCLUSTERED INDEX babel_4817_t2_idx ON dbo.babel_4817_t2 (col5) INCLUDE (col1);; +GO + + +CREATE TABLE babel_4817_t3 (col1 INT IDENTITY, col2 INT, col3 INT, col4 INT, col5 AS col1*col2, col6 VARCHAR(30)) +GO + +ALTER TABLE babel_4817_t3 DROP COLUMN col4 +GO + +ALTER TABLE babel_4817_t3 ADD col4 INT +GO diff --git a/test/JDBC/expected/BABEL_4817-vu-verify.out b/test/JDBC/expected/BABEL_4817-vu-verify.out new file mode 100644 index 0000000000..825dd29555 --- /dev/null +++ b/test/JDBC/expected/BABEL_4817-vu-verify.out @@ -0,0 +1,207 @@ +SELECT CAST('Index Name fetched from sys.indexes' AS CHAR(30)), CAST('index_id' AS CHAR(7)), CAST('index_column_id' AS CHAR(14)), CAST('column_id' AS CHAR(8)), CAST('key_ordinal' AS CHAR(10)), CAST('is_descending_key' AS CHAR(15)), CAST('is_included_column' AS CHAR(15)); +SELECT CAST(i.name AS CHAR(30)), CAST(c.index_id AS CHAR(7)), CAST(c.index_column_id AS CHAR(14)), CAST(c.column_id AS CHAR(8)), CAST(c.key_ordinal AS CHAR(10)), CAST(c.is_descending_key AS CHAR(15)), CAST(c.is_included_column AS CHAR(15)) + FROM + sys.index_columns AS c + INNER JOIN sys.indexes i ON (i.object_id = c.object_id AND i.index_id = c.index_id) + WHERE + c.object_id = OBJECT_ID('babel_4817_t1') AND i.type_desc != 'HEAP' + ORDER BY c.index_id ASC, c.column_id ASC; +GO +~~START~~ +char#!#char#!#char#!#char#!#char#!#char#!#char +Index Name fetched from sys.in#!#index_i#!#index_column_i#!#column_i#!#key_ordina#!#is_descending_k#!#is_included_col +~~END~~ + +~~START~~ +char#!#char#!#char#!#char#!#char#!#char#!#char +babel_4817_t1_pkey #!#2 #!#1 #!#3 #!#1 #!#0 #!#0 +babel_4817_t1_pkey #!#2 #!#2 #!#7 #!#2 #!#0 #!#0 +babel_4817_t1_col2_col8_key #!#3 #!#1 #!#2 #!#1 #!#0 #!#0 +babel_4817_t1_col2_col8_key #!#3 #!#2 #!#8 #!#2 #!#0 #!#0 +babel_4817_t1_idx_1babel_4817_#!#4 #!#2 #!#1 #!#0 #!#0 #!#1 +babel_4817_t1_idx_1babel_4817_#!#4 #!#1 #!#5 #!#1 #!#0 #!#0 +babel_4817_t1_idx_psql #!#5 #!#1 #!#0 #!#1 #!#0 #!#0 +babel_4817_t1_idx_psql #!#5 #!#2 #!#1 #!#0 #!#0 #!#1 +~~END~~ + + + +SELECT CAST('Index Name fetched from sys.indexes' AS CHAR(30)), CAST('index_id' AS CHAR(7)), CAST('index_column_id' AS CHAR(14)), CAST('column_id' AS CHAR(8)), CAST('key_ordinal' AS CHAR(10)), CAST('is_descending_key' AS CHAR(15)), CAST('is_included_column' AS CHAR(15)); +SELECT CAST(i.name AS CHAR(30)), CAST(c.index_id AS CHAR(7)), CAST(c.index_column_id AS CHAR(14)), CAST(c.column_id AS CHAR(8)), CAST(c.key_ordinal AS CHAR(10)), CAST(c.is_descending_key AS CHAR(15)), CAST(c.is_included_column AS CHAR(15)) + FROM + sys.index_columns AS c + INNER JOIN sys.indexes i ON (i.object_id = c.object_id AND i.index_id = c.index_id) + WHERE + c.object_id = OBJECT_ID('babel_4817_t2') AND i.type_desc != 'HEAP' + ORDER BY c.index_id ASC, c.column_id ASC; +GO +~~START~~ +char#!#char#!#char#!#char#!#char#!#char#!#char +Index Name fetched from sys.in#!#index_i#!#index_column_i#!#column_i#!#key_ordina#!#is_descending_k#!#is_included_col +~~END~~ + +~~START~~ +char#!#char#!#char#!#char#!#char#!#char#!#char +babel_4817_t2_pkbabel_4817_t24#!#2 #!#1 #!#3 #!#1 #!#0 #!#0 +babel_4817_t2_pkbabel_4817_t24#!#2 #!#2 #!#7 #!#2 #!#0 #!#0 +babel_4817_t2_unique_indexbabe#!#3 #!#1 #!#2 #!#1 #!#1 #!#0 +babel_4817_t2_unique_indexbabe#!#3 #!#3 #!#4 #!#0 #!#0 #!#1 +babel_4817_t2_unique_indexbabe#!#3 #!#2 #!#8 #!#2 #!#0 #!#0 +babel_4817_t2_idxbabel_4817_t2#!#4 #!#2 #!#1 #!#0 #!#0 #!#1 +babel_4817_t2_idxbabel_4817_t2#!#4 #!#1 #!#5 #!#1 #!#0 #!#0 +~~END~~ + + + + +SELECT 'col1 --> is_computed? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col1', 'iscomputed') +SELECT 'col2 --> is_computed? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col2', 'iscomputed') +SELECT 'col3 --> is_computed? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col3', 'iscomputed') +SELECT 'col4 --> is_computed? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col4', 'iscomputed') +SELECT 'col5 --> is_computed? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col5', 'iscomputed') +SELECT 'col6 --> is_computed? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col6', 'iscomputed') +GO +~~START~~ +varchar#!#int +col1 --> is_computed? #!#0 +~~END~~ + +~~START~~ +varchar#!#int +col2 --> is_computed? #!#0 +~~END~~ + +~~START~~ +varchar#!#int +col3 --> is_computed? #!#0 +~~END~~ + +~~START~~ +varchar#!#int +col4 --> is_computed? #!#0 +~~END~~ + +~~START~~ +varchar#!#int +col5 --> is_computed? #!#1 +~~END~~ + +~~START~~ +varchar#!#int +col6 --> is_computed? #!#0 +~~END~~ + + +SELECT 'col1 --> columnid= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col1', 'columnid') +SELECT 'col2 --> columnid= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col2', 'columnid') +SELECT 'col3 --> columnid= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col3', 'columnid') +SELECT 'col4 --> columnid= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col4', 'columnid') +SELECT 'col5 --> columnid= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col5', 'columnid') +SELECT 'col6 --> columnid= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col6', 'columnid') +GO +~~START~~ +varchar#!#int +col1 --> columnid= #!#1 +~~END~~ + +~~START~~ +varchar#!#int +col2 --> columnid= #!#2 +~~END~~ + +~~START~~ +varchar#!#int +col3 --> columnid= #!#3 +~~END~~ + +~~START~~ +varchar#!#int +col4 --> columnid= #!#7 +~~END~~ + +~~START~~ +varchar#!#int +col5 --> columnid= #!#5 +~~END~~ + +~~START~~ +varchar#!#int +col6 --> columnid= #!#6 +~~END~~ + + +SELECT 'col1 --> ordinal= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col1', 'ordinal') +SELECT 'col2 --> ordinal= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col2', 'ordinal') +SELECT 'col3 --> ordinal= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col3', 'ordinal') +SELECT 'col4 --> ordinal= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col4', 'ordinal') +SELECT 'col5 --> ordinal= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col5', 'ordinal') +SELECT 'col6 --> ordinal= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col6', 'ordinal') +GO +~~START~~ +varchar#!#int +col1 --> ordinal= #!#1 +~~END~~ + +~~START~~ +varchar#!#int +col2 --> ordinal= #!#2 +~~END~~ + +~~START~~ +varchar#!#int +col3 --> ordinal= #!#3 +~~END~~ + +~~START~~ +varchar#!#int +col4 --> ordinal= #!#6 +~~END~~ + +~~START~~ +varchar#!#int +col5 --> ordinal= #!#4 +~~END~~ + +~~START~~ +varchar#!#int +col6 --> ordinal= #!#5 +~~END~~ + + +SELECT 'col1 --> isidentity? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col1', 'isidentity') +SELECT 'col3 --> isidentity? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col3', 'isidentity') +SELECT 'col2 --> isidentity? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col2', 'isidentity') +SELECT 'col4 --> isidentity? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col4', 'isidentity') +SELECT 'col5 --> isidentity? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col5', 'isidentity') +SELECT 'col6 --> isidentity? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col6', 'isidentity') +GO +~~START~~ +varchar#!#int +col1 --> isidentity? #!#1 +~~END~~ + +~~START~~ +varchar#!#int +col3 --> isidentity? #!#0 +~~END~~ + +~~START~~ +varchar#!#int +col2 --> isidentity? #!#0 +~~END~~ + +~~START~~ +varchar#!#int +col4 --> isidentity? #!#0 +~~END~~ + +~~START~~ +varchar#!#int +col5 --> isidentity? #!#0 +~~END~~ + +~~START~~ +varchar#!#int +col6 --> isidentity? #!#0 +~~END~~ + diff --git a/test/JDBC/input/BABEL_4817-vu-cleanup.sql b/test/JDBC/input/BABEL_4817-vu-cleanup.sql new file mode 100644 index 0000000000..5e5fcbd5be --- /dev/null +++ b/test/JDBC/input/BABEL_4817-vu-cleanup.sql @@ -0,0 +1,2 @@ +DROP TABLE IF EXISTS babel_4817_t1, babel_4817_t2, babel_4817_t3; +GO \ No newline at end of file diff --git a/test/JDBC/input/BABEL_4817-vu-prepare.mix b/test/JDBC/input/BABEL_4817-vu-prepare.mix new file mode 100644 index 0000000000..d4303de388 --- /dev/null +++ b/test/JDBC/input/BABEL_4817-vu-prepare.mix @@ -0,0 +1,33 @@ +-- tsql +CREATE TABLE babel_4817_t1 (col1 INT, col2 INT NOT NULL, col3 AS col1*col2, col4 INT, col5 INT, col6 INT, col7 INT IDENTITY, col8 INT NOT NULL, PRIMARY KEY NONCLUSTERED(col3, col7 ASC), UNIQUE (col2 ASC, col8)); +GO + +CREATE NONCLUSTERED INDEX babel_4817_t1_idx_1 ON dbo.babel_4817_t1 (col5) INCLUDE (col1); +GO + +-- psql +-- do not fail if index on expression is created from psql endpoint +CREATE INDEX babel_4817_t1_idx_psql ON master_dbo.babel_4817_t1 ((col6*2)) INCLUDE (col1); +GO + + +-- tsql +CREATE TABLE babel_4817_t2 (col1 INT, col2 INT NOT NULL, col3 AS col1*col2, col4 INT, col5 INT, col6 INT, col7 INT NOT NULL IDENTITY, col8 INT NOT NULL) +GO +ALTER TABLE babel_4817_t2 ADD CONSTRAINT babel_4817_t2_pk PRIMARY KEY NONCLUSTERED (col3, col7); +GO +-- clustered is ignored +CREATE UNIQUE NONCLUSTERED INDEX babel_4817_t2_unique_index ON dbo.babel_4817_t2 (col2 DESC, col8) INCLUDE (col4); +GO +CREATE NONCLUSTERED INDEX babel_4817_t2_idx ON dbo.babel_4817_t2 (col5) INCLUDE (col1);; +GO + + +CREATE TABLE babel_4817_t3 (col1 INT IDENTITY, col2 INT, col3 INT, col4 INT, col5 AS col1*col2, col6 VARCHAR(30)) +GO + +ALTER TABLE babel_4817_t3 DROP COLUMN col4 +GO + +ALTER TABLE babel_4817_t3 ADD col4 INT +GO diff --git a/test/JDBC/input/BABEL_4817-vu-verify.sql b/test/JDBC/input/BABEL_4817-vu-verify.sql new file mode 100644 index 0000000000..d83e9ac032 --- /dev/null +++ b/test/JDBC/input/BABEL_4817-vu-verify.sql @@ -0,0 +1,54 @@ +SELECT CAST('Index Name fetched from sys.indexes' AS CHAR(30)), CAST('index_id' AS CHAR(7)), CAST('index_column_id' AS CHAR(14)), CAST('column_id' AS CHAR(8)), CAST('key_ordinal' AS CHAR(10)), CAST('is_descending_key' AS CHAR(15)), CAST('is_included_column' AS CHAR(15)); +SELECT CAST(i.name AS CHAR(30)), CAST(c.index_id AS CHAR(7)), CAST(c.index_column_id AS CHAR(14)), CAST(c.column_id AS CHAR(8)), CAST(c.key_ordinal AS CHAR(10)), CAST(c.is_descending_key AS CHAR(15)), CAST(c.is_included_column AS CHAR(15)) + FROM + sys.index_columns AS c + INNER JOIN sys.indexes i ON (i.object_id = c.object_id AND i.index_id = c.index_id) + WHERE + c.object_id = OBJECT_ID('babel_4817_t1') AND i.type_desc != 'HEAP' + ORDER BY c.index_id ASC, c.column_id ASC; +GO + + +SELECT CAST('Index Name fetched from sys.indexes' AS CHAR(30)), CAST('index_id' AS CHAR(7)), CAST('index_column_id' AS CHAR(14)), CAST('column_id' AS CHAR(8)), CAST('key_ordinal' AS CHAR(10)), CAST('is_descending_key' AS CHAR(15)), CAST('is_included_column' AS CHAR(15)); +SELECT CAST(i.name AS CHAR(30)), CAST(c.index_id AS CHAR(7)), CAST(c.index_column_id AS CHAR(14)), CAST(c.column_id AS CHAR(8)), CAST(c.key_ordinal AS CHAR(10)), CAST(c.is_descending_key AS CHAR(15)), CAST(c.is_included_column AS CHAR(15)) + FROM + sys.index_columns AS c + INNER JOIN sys.indexes i ON (i.object_id = c.object_id AND i.index_id = c.index_id) + WHERE + c.object_id = OBJECT_ID('babel_4817_t2') AND i.type_desc != 'HEAP' + ORDER BY c.index_id ASC, c.column_id ASC; +GO + + + +SELECT 'col1 --> is_computed? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col1', 'iscomputed') +SELECT 'col2 --> is_computed? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col2', 'iscomputed') +SELECT 'col3 --> is_computed? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col3', 'iscomputed') +SELECT 'col4 --> is_computed? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col4', 'iscomputed') +SELECT 'col5 --> is_computed? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col5', 'iscomputed') +SELECT 'col6 --> is_computed? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col6', 'iscomputed') +GO + +SELECT 'col1 --> columnid= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col1', 'columnid') +SELECT 'col2 --> columnid= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col2', 'columnid') +SELECT 'col3 --> columnid= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col3', 'columnid') +SELECT 'col4 --> columnid= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col4', 'columnid') +SELECT 'col5 --> columnid= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col5', 'columnid') +SELECT 'col6 --> columnid= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col6', 'columnid') +GO + +SELECT 'col1 --> ordinal= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col1', 'ordinal') +SELECT 'col2 --> ordinal= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col2', 'ordinal') +SELECT 'col3 --> ordinal= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col3', 'ordinal') +SELECT 'col4 --> ordinal= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col4', 'ordinal') +SELECT 'col5 --> ordinal= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col5', 'ordinal') +SELECT 'col6 --> ordinal= ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col6', 'ordinal') +GO + +SELECT 'col1 --> isidentity? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col1', 'isidentity') +SELECT 'col3 --> isidentity? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col3', 'isidentity') +SELECT 'col2 --> isidentity? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col2', 'isidentity') +SELECT 'col4 --> isidentity? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col4', 'isidentity') +SELECT 'col5 --> isidentity? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col5', 'isidentity') +SELECT 'col6 --> isidentity? ', columnproperty(OBJECT_ID('babel_4817_t3'), 'col6', 'isidentity') +GO diff --git a/test/JDBC/upgrade/14_10/schedule b/test/JDBC/upgrade/14_10/schedule index 6deb090546..9f528464ad 100644 --- a/test/JDBC/upgrade/14_10/schedule +++ b/test/JDBC/upgrade/14_10/schedule @@ -423,3 +423,4 @@ babel-4475 BABEL-4606 babel-4517 BABEL_4553 +BABEL_4817 \ No newline at end of file diff --git a/test/JDBC/upgrade/14_11/schedule b/test/JDBC/upgrade/14_11/schedule index 6fe40b9638..989c32a4c3 100644 --- a/test/JDBC/upgrade/14_11/schedule +++ b/test/JDBC/upgrade/14_11/schedule @@ -420,4 +420,5 @@ sys_certificates sys_database_permissions babel-4475 BABEL-4606 -babel-4517 \ No newline at end of file +babel-4517 +BABEL_4817 \ No newline at end of file diff --git a/test/JDBC/upgrade/14_8/schedule b/test/JDBC/upgrade/14_8/schedule index 8ae9012aff..29e9800e92 100644 --- a/test/JDBC/upgrade/14_8/schedule +++ b/test/JDBC/upgrade/14_8/schedule @@ -411,3 +411,4 @@ AUTO_ANALYZE-before-15-5-or-14-10 BABEL_4389 BABEL-4606 babel-4517 +BABEL_4817 diff --git a/test/JDBC/upgrade/14_9/schedule b/test/JDBC/upgrade/14_9/schedule index 757b4794da..b5f7a6daf1 100644 --- a/test/JDBC/upgrade/14_9/schedule +++ b/test/JDBC/upgrade/14_9/schedule @@ -415,3 +415,4 @@ AUTO_ANALYZE-before-15-5-or-14-10 babel-4475 BABEL-4606 babel-4517 +BABEL_4817 diff --git a/test/JDBC/upgrade/latest/schedule b/test/JDBC/upgrade/latest/schedule index e35aff796e..73368356b3 100644 --- a/test/JDBC/upgrade/latest/schedule +++ b/test/JDBC/upgrade/latest/schedule @@ -424,3 +424,4 @@ babel-4475 sys_availability_groups sys_availability_replicas babel-4517 +BABEL_4817 \ No newline at end of file diff --git a/test/python/expected/pyodbc/ddl_all_objects.out b/test/python/expected/pyodbc/ddl_all_objects.out index 29e0d7d419..02374b9f03 100644 --- a/test/python/expected/pyodbc/ddl_all_objects.out +++ b/test/python/expected/pyodbc/ddl_all_objects.out @@ -6,7 +6,7 @@ CREATE TABLE [dbo].[babel_1654_vu_prepare_t]( [b] [varchar](50) NULL, CONSTRAINT [babel_1654_vu_prepare_t_pkey] PRIMARY KEY NONCLUSTERED ( - [id] + [id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ) ON [PRIMARY] @@ -71,7 +71,7 @@ CREATE TABLE [dbo].[test_tsql_const]( [c_varbinary] [varbinary](8) NULL, CONSTRAINT [test_tsql_const_pkey] PRIMARY KEY NONCLUSTERED ( - [c_int] + [c_int] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ) ON [PRIMARY] @@ -141,13 +141,13 @@ GO ALTER TABLE [dbo].[babel_1654_vu_prepare_t] ADD CONSTRAINT [babel_1654_vu_prepare_t_pkey] PRIMARY KEY NONCLUSTERED ( - [id] + [id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) GO ALTER TABLE [dbo].[test_tsql_const] ADD CONSTRAINT [test_tsql_const_pkey] PRIMARY KEY NONCLUSTERED ( - [c_int] + [c_int] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) GO diff --git a/test/python/expected/pyodbc/ddl_func_proc.out b/test/python/expected/pyodbc/ddl_func_proc.out index b1825a2efd..18668576b8 100644 --- a/test/python/expected/pyodbc/ddl_func_proc.out +++ b/test/python/expected/pyodbc/ddl_func_proc.out @@ -9,7 +9,7 @@ CREATE TABLE [dbo].[routines_customers]( [zip_code] [char](10) NULL, CONSTRAINT [customers_pkroutines_customers248e85dd01b015e3396e8567c240879b] PRIMARY KEY NONCLUSTERED ( - [customer_id] + [customer_id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ) ON [PRIMARY] @@ -199,7 +199,7 @@ GO ALTER TABLE [dbo].[routines_customers] ADD CONSTRAINT [customers_pkroutines_customers248e85dd01b015e3396e8567c240879b] PRIMARY KEY NONCLUSTERED ( - [customer_id] + [customer_id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) GO diff --git a/test/python/expected/pyodbc/ddl_tables_index.out b/test/python/expected/pyodbc/ddl_tables_index.out index e3756f7087..c8140963e2 100644 --- a/test/python/expected/pyodbc/ddl_tables_index.out +++ b/test/python/expected/pyodbc/ddl_tables_index.out @@ -1,3 +1,92 @@ +SET ANSI_NULLS ON +SET QUOTED_IDENTIFIER ON +CREATE TABLE [dbo].[babel_4817_t1]( + [col1] [int] NULL, + [col2] [int] NOT NULL, + [col3] AS (col1 * col2) PERSISTED NOT NULL, + [col4] [int] NULL, + [col5] [int] NULL, + [col6] [int] NULL, + [col7] [int] NOT NULL, + [col8] [int] NOT NULL, + CONSTRAINT [babel_4817_t1_pkey] PRIMARY KEY NONCLUSTERED +( + [col3] ASC, + [col7] DESC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON), + CONSTRAINT [babel_4817_t1_col2_col8_key] UNIQUE NONCLUSTERED +( + [col2] DESC, + [col8] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) +) ON [PRIMARY] + +GO + +SET ANSI_NULLS ON +SET QUOTED_IDENTIFIER ON +CREATE TABLE [dbo].[babel_4817_t2]( + [col1] [int] NULL, + [col2] [int] NOT NULL, + [col3] AS (col1 * col2) PERSISTED NOT NULL, + [col4] [int] NULL, + [col5] [int] NULL, + [col6] [int] NULL, + [col7] [int] IDENTITY(1,1) NOT NULL, + [col8] [int] NOT NULL, + CONSTRAINT [babel_4817_t2_pkbabel_4817_t2405f712bf0a4067d413068dcbaf9fc11] PRIMARY KEY NONCLUSTERED +( + [col3] ASC, + [col7] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) +) ON [PRIMARY] + +GO + +SET ANSI_NULLS ON +SET QUOTED_IDENTIFIER ON +CREATE TABLE [dbo].[babel_4817_t3]( + [col1] [int] IDENTITY(1,1) NOT NULL, + [col2] [int] NULL, + [col3] [int] NULL, + [col5] AS (col1 * col2) PERSISTED, + [col6] [varchar](30) NULL, + [col4] [int] NULL +) ON [PRIMARY] + +GO + +SET ANSI_NULLS ON +SET QUOTED_IDENTIFIER ON +CREATE TABLE [dbo].[babel_4817_t4]( + [id] [int] NULL, + [filename] [varchar](200) NOT NULL, + [commited_dt] [datetime] NOT NULL, + [commited_sql] [ntext] NULL, + CONSTRAINT [babel_4817_t4_pkey] PRIMARY KEY NONCLUSTERED +( + [filename] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) +) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] + +GO + +SET ANSI_NULLS ON +SET QUOTED_IDENTIFIER ON +CREATE TABLE [dbo].[babel_4817_t5]( + [id] [int] NOT NULL, + [filename] [varchar](200) NOT NULL, + [commited_dt] [datetime] NOT NULL, + [commited_sql] [ntext] NULL, + CONSTRAINT [babel_4817_t5_pkey] PRIMARY KEY NONCLUSTERED +( + [filename] ASC, + [id] DESC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) +) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] + +GO + SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON CREATE TABLE [dbo].[isc_check_constraints_t1]( @@ -28,7 +117,7 @@ CREATE TABLE [dbo].[table_foreign]( [a] [int] NULL, CONSTRAINT [table_foreign_pkey] PRIMARY KEY NONCLUSTERED ( - [aa] + [aa] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ) ON [PRIMARY] @@ -44,7 +133,7 @@ CREATE TABLE [dbo].[table_primary]( [c] [int] NULL, CONSTRAINT [table_primary_pkey] PRIMARY KEY NONCLUSTERED ( - [a] + [a] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ) ON [PRIMARY] @@ -58,7 +147,7 @@ CREATE TABLE [dbo].[table_unique]( [c] [int] NULL, CONSTRAINT [table_unique_a_key] UNIQUE NONCLUSTERED ( - [a] + [a] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ) ON [PRIMARY] @@ -128,7 +217,7 @@ CREATE TABLE [dbo].[test_tsql_const]( [c_varbinary] [varbinary](8) NULL, CONSTRAINT [test_tsql_const_pkey] PRIMARY KEY NONCLUSTERED ( - [c_int] + [c_int] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ) ON [PRIMARY] @@ -154,39 +243,107 @@ ALTER TABLE [dbo].[test_upper] WITH CHECK ADD CONSTRAINT [test_upper_a_check] ALTER TABLE [dbo].[test_upper] CHECK CONSTRAINT [test_upper_a_check] GO +ALTER TABLE [dbo].[babel_4817_t1] ADD CONSTRAINT [babel_4817_t1_col2_col8_key] UNIQUE NONCLUSTERED +( + [col2] DESC, + [col8] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) +GO + +CREATE NONCLUSTERED INDEX [babel_4817_t1_idx_1babel_4817_t54b9390e1f9ca15d901db11774c8a339] ON [dbo].[babel_4817_t1] +( + [col5] ASC +) +INCLUDE([col1]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) +GO + +SET ANSI_PADDING ON + +ALTER TABLE [dbo].[babel_4817_t1] ADD CONSTRAINT [babel_4817_t1_pkey] PRIMARY KEY NONCLUSTERED +( + [col3] ASC, + [col7] DESC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) +GO + +CREATE NONCLUSTERED INDEX [babel_4817_t2_idxbabel_4817_t2ee980ac887cd6b2f46cd1527808a3a02] ON [dbo].[babel_4817_t2] +( + [col5] ASC +) +INCLUDE([col1]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) +GO + +SET ANSI_PADDING ON + +ALTER TABLE [dbo].[babel_4817_t2] ADD CONSTRAINT [babel_4817_t2_pkbabel_4817_t2405f712bf0a4067d413068dcbaf9fc11] PRIMARY KEY NONCLUSTERED +( + [col3] ASC, + [col7] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) +GO + +CREATE UNIQUE NONCLUSTERED INDEX [babel_4817_t2_unique_indexbabel58db3c54b7c753629ed4fc2951061d2a] ON [dbo].[babel_4817_t2] +( + [col2] DESC, + [col8] ASC +) +INCLUDE([col4]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) +GO + +ALTER TABLE [dbo].[babel_4817_t4] ADD CONSTRAINT [babel_4817_t4_pkey] PRIMARY KEY NONCLUSTERED +( + [filename] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) +GO + +ALTER TABLE [dbo].[babel_4817_t5] ADD CONSTRAINT [babel_4817_t5_pkey] PRIMARY KEY NONCLUSTERED +( + [filename] ASC, + [id] DESC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) +GO + +CREATE NONCLUSTERED INDEX [ix_testbabel_4817_t53c84a25c8e10b5bd55950897f8ca76a1] ON [dbo].[babel_4817_t5] +( + [filename] ASC +) +INCLUDE([id],[commited_dt]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) +GO + ALTER TABLE [dbo].[table_foreign] ADD CONSTRAINT [table_foreign_pkey] PRIMARY KEY NONCLUSTERED ( - [aa] + [aa] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) GO ALTER TABLE [dbo].[table_primary] ADD CONSTRAINT [table_primary_pkey] PRIMARY KEY NONCLUSTERED ( - [a] + [a] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) GO ALTER TABLE [dbo].[table_unique] ADD CONSTRAINT [table_unique_a_key] UNIQUE NONCLUSTERED ( - [a] + [a] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) GO CREATE NONCLUSTERED INDEX [test_comp_indextable_unique54256857b8bed086a06f91b550a3a65b] ON [dbo].[table_unique] ( - [a] + [a] ASC, + [b] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) GO ALTER TABLE [dbo].[test_tsql_const] ADD CONSTRAINT [test_tsql_const_pkey] PRIMARY KEY NONCLUSTERED ( - [c_int] + [c_int] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) GO CREATE NONCLUSTERED INDEX [test_indextest_upper8e0335bba8a0f780c0c12b75ae201ead] ON [dbo].[test_upper] ( - [a] + [a] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) GO diff --git a/test/python/expected/pyodbc/ddl_triggers.out b/test/python/expected/pyodbc/ddl_triggers.out index 034cae9ca5..5a98de5f1e 100644 --- a/test/python/expected/pyodbc/ddl_triggers.out +++ b/test/python/expected/pyodbc/ddl_triggers.out @@ -14,7 +14,7 @@ CREATE TABLE [dbo].[babel_1654_vu_prepare_employeedata]( [f] [varchar](50) NULL, CONSTRAINT [babel_1654_vu_prepare_employeedata_pkey] PRIMARY KEY NONCLUSTERED ( - [id] + [id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ) ON [PRIMARY] @@ -29,7 +29,7 @@ CREATE TABLE [dbo].[babel_1654_vu_prepare_t]( [b] [varchar](50) NULL, CONSTRAINT [babel_1654_vu_prepare_t_pkey] PRIMARY KEY NONCLUSTERED ( - [id] + [id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ) ON [PRIMARY] @@ -40,20 +40,20 @@ SET QUOTED_IDENTIFIER ON CREATE TABLE [dbo].[sys_computed_columns_vu_prepare_t1]( [scc_first_number] [smallint] NULL, [scc_second_number] [money] NULL, - [scc_multiplied] AS (scc_first_number * scc_second_number) + [scc_multiplied] AS (scc_first_number * scc_second_number) PERSISTED ) ON [PRIMARY] GO ALTER TABLE [dbo].[babel_1654_vu_prepare_employeedata] ADD CONSTRAINT [babel_1654_vu_prepare_employeedata_pkey] PRIMARY KEY NONCLUSTERED ( - [id] + [id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) GO ALTER TABLE [dbo].[babel_1654_vu_prepare_t] ADD CONSTRAINT [babel_1654_vu_prepare_t_pkey] PRIMARY KEY NONCLUSTERED ( - [id] + [id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) GO diff --git a/test/python/expected/sql_validation_framework/expected_drop.out b/test/python/expected/sql_validation_framework/expected_drop.out index 0d6f9c020e..1d22c25213 100644 --- a/test/python/expected/sql_validation_framework/expected_drop.out +++ b/test/python/expected/sql_validation_framework/expected_drop.out @@ -27,6 +27,7 @@ Unexpected drop found for procedure sys.babelfish_drop_deprecated_object in file Unexpected drop found for procedure sys.babelfish_drop_deprecated_object in file babelfishpg_tsql--2.4.0--2.5.0.sql Unexpected drop found for procedure sys.babelfish_drop_deprecated_object in file babelfishpg_tsql--2.6.0--2.7.0.sql Unexpected drop found for procedure sys.babelfish_drop_deprecated_object in file babelfishpg_tsql--2.7.0--2.8.0.sql +Unexpected drop found for procedure sys.babelfish_drop_deprecated_object in file babelfishpg_tsql--2.8.0--2.9.0.sql Unexpected drop found for procedure sys.babelfish_drop_deprecated_table in file babelfishpg_tsql--2.1.0--2.2.0.sql Unexpected drop found for procedure sys.babelfish_drop_deprecated_view in file babelfishpg_tsql--1.0.0--1.1.0.sql Unexpected drop found for procedure sys.babelfish_drop_deprecated_view in file babelfishpg_tsql--2.1.0--2.2.0.sql @@ -36,5 +37,6 @@ Unexpected drop found for procedure sys.babelfish_update_collation_to_default in Unexpected drop found for procedure sys.babelfish_update_user_catalog_for_guest in file babelfishpg_tsql--2.2.0--2.3.0.sql Unexpected drop found for procedure sys.babelfish_update_user_catalog_for_guest_schema in file babelfishpg_tsql--2.6.0--2.7.0.sql Unexpected drop found for procedure sys.babelfish_update_user_catalog_for_guest_schema in file babelfishpg_tsql--2.7.0--2.8.0.sql +Unexpected drop found for procedure sys.babelfish_update_user_catalog_for_guest_schema in file babelfishpg_tsql--2.8.0--2.9.0.sql Unexpected drop found for procedure sys.create_xp_qv_in_master_dbo in file babelfishpg_tsql--1.1.0--1.2.0.sql Unexpected drop found for procedure sys.sp_babelfish_grant_usage_to_all in file babelfishpg_tsql--1.1.0--1.2.0.sql diff --git a/test/python/input/ddl_tables_index.sql b/test/python/input/ddl_tables_index.sql index 4e67727d39..357277aa0c 100644 --- a/test/python/input/ddl_tables_index.sql +++ b/test/python/input/ddl_tables_index.sql @@ -24,6 +24,8 @@ DROP TABLE IF EXISTS test_null GO DROP TABLE IF EXISTS test_upper GO +DROP TABLE IF EXISTS babel_4817_t1, babel_4817_t2, babel_4817_t3, babel_4817_t4, babel_4817_t5; +GO Create table table_unique (a int NOT NULL UNIQUE , b int NOT NULL,c int ) GO Create table table_primary (a int NOT NULL , b int NOT NULL,c int, PRIMARY KEY(a) ) @@ -66,8 +68,64 @@ Create index test_index on test_upper(a) GO Create index test_comp_index on table_unique(a,b) GO + +CREATE TABLE babel_4817_t1 (col1 INT, col2 INT NOT NULL, col3 AS col1*col2, col4 INT, col5 INT, col6 INT, col7 INT, col8 INT NOT NULL, PRIMARY KEY NONCLUSTERED(col3, col7 DESC), UNIQUE (col2 DESC, col8)); +GO +CREATE INDEX babel_4817_t1_idx_1 ON dbo.babel_4817_t1 (col5) INCLUDE (col1); +GO + +CREATE TABLE babel_4817_t2 (col1 INT, col2 INT NOT NULL, col3 AS col1*col2, col4 INT, col5 INT, col6 INT, col7 INT NOT NULL IDENTITY, col8 INT NOT NULL) +GO +ALTER TABLE babel_4817_t2 ADD CONSTRAINT babel_4817_t2_pk PRIMARY KEY NONCLUSTERED (col3, col7); +GO +CREATE UNIQUE NONCLUSTERED INDEX babel_4817_t2_unique_index ON dbo.babel_4817_t2 (col2 DESC, col8) INCLUDE (col4); +GO +CREATE NONCLUSTERED INDEX babel_4817_t2_idx ON dbo.babel_4817_t2 (col5) INCLUDE (col1); +GO +CREATE TABLE babel_4817_t3 (col1 INT IDENTITY, col2 INT, col3 INT, col4 INT, col5 AS col1*col2, col6 VARCHAR(30)) +GO +ALTER TABLE babel_4817_t3 DROP COLUMN col4 +GO +ALTER TABLE babel_4817_t3 ADD col4 INT +GO + +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +CREATE TABLE [dbo].[babel_4817_t4]( + [id] [int] NULL, + [filename] [varchar](200) NOT NULL, + [commited_dt] [datetime] NOT NULL, + [commited_sql] [ntext] NULL, +PRIMARY KEY CLUSTERED +( + [filename] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] +GO + +CREATE TABLE [dbo].[babel_4817_t5] +( + [id] [int] NOT NULL, + [filename] [varchar](200) NOT NULL, + [commited_dt] [datetime] NOT NULL, + [commited_sql] [ntext] NULL, + PRIMARY KEY CLUSTERED +( + [filename] ASC, [ID] DESC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] +) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] +GO +CREATE NONCLUSTERED INDEX ix_test ON [dbo].[babel_4817_t5] ([filename]) INCLUDE ([id],[commited_dt]) +GO + --DROP +DROP TABLE IF EXISTS babel_4817_3, babel_4817_4; +GO +DROP TABLE IF EXISTS babel_4817_t1, babel_4817_t2, babel_4817_t3, babel_4817_t4, babel_4817_t5; +GO DROP TABLE IF EXISTS table_check GO DROP TABLE IF EXISTS table_foreign