Skip to content

Commit

Permalink
Reporting unique nulls not distinct in analyze schema and assessment …
Browse files Browse the repository at this point in the history
…report (#2125)
  • Loading branch information
ShivanshGahlot authored Jan 9, 2025
1 parent a6b5e4c commit ac37160
Show file tree
Hide file tree
Showing 15 changed files with 592 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,9 @@ CREATE INDEX idx_udt1 on test_udt(home_address1);

CREATE INDEX idx_enum on test_udt(some_field);

CREATE INDEX "idx&_enum2" on test_udt((some_field::non_public.enum_test));
CREATE INDEX "idx&_enum2" on test_udt((some_field::non_public.enum_test));

-- Create a unique index on a column with NULLs with the NULLS NOT DISTINCT option
CREATE UNIQUE INDEX users_unique_nulls_not_distinct_index_email
ON users_unique_nulls_not_distinct_index (email)
NULLS NOT DISTINCT;
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,39 @@ CREATE TABLE timestamptz_multirange_table (
global_event_times tstzmultirange
);

-- Testing tables with unique nulls not distinct constraints

-- Control case
CREATE TABLE users_unique_nulls_distinct (
id SERIAL PRIMARY KEY,
email TEXT,
UNIQUE (email)
);

CREATE TABLE users_unique_nulls_not_distinct (
id SERIAL PRIMARY KEY,
email TEXT,
UNIQUE NULLS NOT DISTINCT (email)
);

CREATE TABLE sales_unique_nulls_not_distinct (
store_id INT,
product_id INT,
sale_date DATE,
UNIQUE NULLS NOT DISTINCT (store_id, product_id, sale_date)
);

CREATE TABLE sales_unique_nulls_not_distinct_alter (
store_id INT,
product_id INT,
sale_date DATE
);

ALTER TABLE sales_unique_nulls_not_distinct_alter
ADD CONSTRAINT sales_unique_nulls_not_distinct_alter_unique UNIQUE NULLS NOT DISTINCT (store_id, product_id, sale_date);

-- Create a unique index on a column with NULLs with the NULLS NOT DISTINCT option
CREATE TABLE users_unique_nulls_not_distinct_index (
id INTEGER PRIMARY KEY,
email TEXT
);
40 changes: 40 additions & 0 deletions migtests/tests/analyze-schema/expected_issues.json
Original file line number Diff line number Diff line change
Expand Up @@ -2060,5 +2060,45 @@
"Suggestion": "Multirange data type is not yet supported in YugabyteDB, no workaround available currently",
"GH": "",
"MinimumVersionsFixedIn": null
},
{
"IssueType": "unsupported_features",
"ObjectType": "TABLE",
"ObjectName": "users_unique_nulls_not_distinct",
"Reason": "Unique Nulls Not Distinct",
"SqlStatement": "CREATE TABLE users_unique_nulls_not_distinct (\n id SERIAL PRIMARY KEY,\n email TEXT,\n UNIQUE NULLS NOT DISTINCT (email)\n);",
"Suggestion": "",
"GH": "",
"MinimumVersionsFixedIn": null
},
{
"IssueType": "unsupported_features",
"ObjectType": "TABLE",
"ObjectName": "sales_unique_nulls_not_distinct",
"Reason": "Unique Nulls Not Distinct",
"SqlStatement": "CREATE TABLE sales_unique_nulls_not_distinct (\n store_id INT,\n product_id INT,\n sale_date DATE,\n UNIQUE NULLS NOT DISTINCT (store_id, product_id, sale_date)\n);",
"Suggestion": "",
"GH": "",
"MinimumVersionsFixedIn": null
},
{
"IssueType": "unsupported_features",
"ObjectType": "TABLE",
"ObjectName": "sales_unique_nulls_not_distinct_alter",
"Reason": "Unique Nulls Not Distinct",
"SqlStatement": "ALTER TABLE sales_unique_nulls_not_distinct_alter\n\tADD CONSTRAINT sales_unique_nulls_not_distinct_alter_unique UNIQUE NULLS NOT DISTINCT (store_id, product_id, sale_date);",
"Suggestion": "",
"GH": "",
"MinimumVersionsFixedIn": null
},
{
"IssueType": "unsupported_features",
"ObjectType": "INDEX",
"ObjectName": "users_unique_nulls_not_distinct_index_email ON users_unique_nulls_not_distinct_index",
"Reason": "Unique Nulls Not Distinct",
"SqlStatement": "CREATE UNIQUE INDEX users_unique_nulls_not_distinct_index_email\n ON users_unique_nulls_not_distinct_index (email)\n NULLS NOT DISTINCT;",
"Suggestion": "",
"GH": "",
"MinimumVersionsFixedIn": null
}
]
13 changes: 6 additions & 7 deletions migtests/tests/analyze-schema/summary.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@
},
{
"ObjectType": "TABLE",
"TotalCount": 59,
"InvalidCount": 50,
"ObjectNames": "public.json_data, employees, image, public.xml_data_example, combined_tbl1, test_arr_enum, public.locations, test_udt, combined_tbl, public.ts_query_table, public.documents, public.citext_type, public.inet_type, public.test_jsonb, test_xml_type, test_xid_type, public.range_columns_partition_test_copy, anydata_test, uritype_test, public.foreign_def_test, test_4, enum_example.bugs, table_abc, anydataset_test, unique_def_test1, test_2, table_1, public.range_columns_partition_test, table_xyz, public.users, test_3, test_5, test_7, foreign_def_test2, unique_def_test, sales_data, table_test, test_interval, test_non_pk_multi_column_list, test_9, test_8, order_details, public.employees4, anytype_test, public.meeting, test_table_in_type_file, sales, test_1, \"Test\", foreign_def_test1, salaries2, test_6, public.pr, bigint_multirange_table, date_multirange_table, int_multirange_table, numeric_multirange_table, timestamp_multirange_table, timestamptz_multirange_table" },

"TotalCount": 64,
"InvalidCount": 53,
"ObjectNames": "test_table_in_type_file, sales_data, salaries2, sales, test_1, test_2, test_non_pk_multi_column_list, test_3, test_4, test_5, test_6, test_7, test_8, test_9, order_details, public.employees4, enum_example.bugs, table_xyz, table_abc, table_1, table_test, test_interval, public.range_columns_partition_test, public.range_columns_partition_test_copy, anydata_test, anydataset_test, anytype_test, uritype_test, \"Test\", public.meeting, public.pr, public.foreign_def_test, public.users, foreign_def_test1, foreign_def_test2, unique_def_test, unique_def_test1, test_xml_type, test_xid_type, public.test_jsonb, public.inet_type, public.citext_type, public.documents, public.ts_query_table, combined_tbl, combined_tbl1, test_udt, test_arr_enum, public.locations, public.xml_data_example, image, public.json_data, employees, bigint_multirange_table, date_multirange_table, int_multirange_table, numeric_multirange_table, timestamp_multirange_table, timestamptz_multirange_table, users_unique_nulls_distinct, users_unique_nulls_not_distinct, sales_unique_nulls_not_distinct, sales_unique_nulls_not_distinct_alter, users_unique_nulls_not_distinct_index" },
{
"ObjectType": "INDEX",
"TotalCount": 43,
"InvalidCount": 39,
"ObjectNames": "idx1 ON combined_tbl1, idx2 ON combined_tbl1, idx3 ON combined_tbl1, idx4 ON combined_tbl1, idx5 ON combined_tbl1, idx6 ON combined_tbl1, idx7 ON combined_tbl1, idx8 ON combined_tbl1, film_fulltext_idx ON public.film, idx_actor_last_name ON public.actor, idx_name1 ON table_name, idx_name2 ON table_name, idx_name3 ON schema_name.table_name, idx_fileinfo_name_splitted ON public.fileinfo, abc ON public.example, abc ON schema2.example, tsvector_idx ON public.documents, tsquery_idx ON public.ts_query_table, idx_citext ON public.citext_type, idx_inet ON public.inet_type, idx_json ON public.test_jsonb, idx_json2 ON public.test_jsonb, idx_valid ON public.test_jsonb, idx_array ON public.documents, idx1 ON combined_tbl, idx2 ON combined_tbl, idx3 ON combined_tbl, idx4 ON combined_tbl, idx5 ON combined_tbl, idx6 ON combined_tbl, idx7 ON combined_tbl, idx8 ON combined_tbl, idx9 ON combined_tbl, idx10 ON combined_tbl, idx11 ON combined_tbl, idx12 ON combined_tbl, idx13 ON combined_tbl, idx14 ON combined_tbl, idx15 ON combined_tbl, idx_udt ON test_udt, idx_udt1 ON test_udt, idx_enum ON test_udt, \"idx\u0026_enum2\" ON test_udt",
"TotalCount": 44,
"InvalidCount": 40,
"ObjectNames": "film_fulltext_idx ON public.film, idx_actor_last_name ON public.actor, idx_name1 ON table_name, idx_name2 ON table_name, idx_name3 ON schema_name.table_name, idx_fileinfo_name_splitted ON public.fileinfo, abc ON public.example, abc ON schema2.example, tsvector_idx ON public.documents, tsquery_idx ON public.ts_query_table, idx_citext ON public.citext_type, idx_inet ON public.inet_type, idx_json ON public.test_jsonb, idx_json2 ON public.test_jsonb, idx_valid ON public.test_jsonb, idx_array ON public.documents, idx1 ON combined_tbl, idx2 ON combined_tbl, idx3 ON combined_tbl, idx4 ON combined_tbl, idx5 ON combined_tbl, idx6 ON combined_tbl, idx7 ON combined_tbl, idx8 ON combined_tbl, idx9 ON combined_tbl, idx10 ON combined_tbl, idx11 ON combined_tbl, idx12 ON combined_tbl, idx13 ON combined_tbl, idx14 ON combined_tbl, idx15 ON combined_tbl, idx1 ON combined_tbl1, idx2 ON combined_tbl1, idx3 ON combined_tbl1, idx4 ON combined_tbl1, idx5 ON combined_tbl1, idx6 ON combined_tbl1, idx7 ON combined_tbl1, idx8 ON combined_tbl1, idx_udt ON test_udt, idx_udt1 ON test_udt, idx_enum ON test_udt, \"idx\u0026_enum2\" ON test_udt, users_unique_nulls_not_distinct_index_email ON users_unique_nulls_not_distinct_index",
"Details": "There are some GIN indexes present in the schema, but GIN indexes are partially supported in YugabyteDB as mentioned in (https://github.com/yugabyte/yugabyte-db/issues/7850) so take a look and modify them if not supported."
},
{
Expand Down
Loading

0 comments on commit ac37160

Please sign in to comment.