diff --git a/docs/en_US/release_notes_4_13.rst b/docs/en_US/release_notes_4_13.rst index bf9207960..d83da92bd 100644 --- a/docs/en_US/release_notes_4_13.rst +++ b/docs/en_US/release_notes_4_13.rst @@ -23,6 +23,7 @@ Housekeeping | `Issue #4617 `_ - Add Reverse Engineered and Modified SQL tests for Foreign Servers. | `Issue #4618 `_ - Add Reverse Engineered and Modified SQL tests for Foreign Tables. | `Issue #4619 `_ - Add Reverse Engineered and Modified SQL tests for FTS Templates. +| `Issue #4621 `_ - Add Reverse Engineered and Modified SQL tests for Indexes. | `Issue #4627 `_ - Add Reverse Engineered and Modified SQL tests for User Mappings. | `Issue #4690 `_ - Add Modified SQL tests for Resource Group. @@ -47,4 +48,6 @@ Bug fixes | `Issue #4657 `_ - Fix PGADMIN_SERVER_JSON_FILE environment variable support in the container. | `Issue #4663 `_ - Fix exception in query history for python 2.7. | `Issue #4674 `_ - Fix query tool launch error if user name contain html characters. -| `Issue #4681 `_ - Increase cache control max age for static files to improve performance over longer run. \ No newline at end of file +| `Issue #4681 `_ - Increase cache control max age for static files to improve performance over longer run. +| `Issue #4702 `_ - Fix modified SQL for Index when reset the value of Fill factor and Clustered?. +| `Issue #4703 `_ - Fix reversed engineered SQL for btree Index when provided sort order and NULLs. \ No newline at end of file diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py index 239cdbe1e..5ea7e9479 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/__init__.py @@ -505,8 +505,17 @@ class IndexesView(PGChildNodeView): 'collspcname': row['collnspname'], 'op_class': row['opcname'], } - if row['options'][0] == 'DESC': - cols_data['sort_order'] = True + + # ASC/DESC and NULLS works only with btree indexes + if 'amname' in data and data['amname'] == 'btree': + cols_data['sort_order'] = False + if row['options'][0] == 'DESC': + cols_data['sort_order'] = True + + cols_data['nulls'] = False + if row['options'][1].split(" ")[1] == 'FIRST': + cols_data['nulls'] = True + columns.append(cols_data) # We need same data as string to display in properties window @@ -516,8 +525,14 @@ class IndexesView(PGChildNodeView): cols_str += ' COLLATE ' + row['collnspname'] if row['opcname']: cols_str += ' ' + row['opcname'] - if row['options'][0] == 'DESC': - cols_str += ' DESC' + + # ASC/DESC and NULLS works only with btree indexes + if 'amname' in data and data['amname'] == 'btree': + # Append sort order + cols_str += ' ' + row['options'][0] + # Append nulls value + cols_str += ' ' + row['options'][1] + cols.append(cols_str) # Push as collection diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/alter_name_fillfactor_comment.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/alter_name_fillfactor_comment.sql new file mode 100644 index 000000000..e6b08e849 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/alter_name_fillfactor_comment.sql @@ -0,0 +1,15 @@ +-- Index: Idx1_$%{}[]()&*^!@"'`\/# + +-- DROP INDEX public."Idx1_$%{}[]()&*^!@""'`\/#"; + +CREATE UNIQUE INDEX "Idx1_$%{}[]()&*^!@""'`\/#" + ON public.test_table_for_indexes USING btree + (id DESC NULLS FIRST, name COLLATE pg_catalog."POSIX" text_pattern_ops DESC NULLS FIRST) + WITH (FILLFACTOR=10) + TABLESPACE pg_default; + +ALTER TABLE public.test_table_for_indexes + CLUSTER ON "Idx1_$%{}[]()&*^!@""'`\/#"; + +COMMENT ON INDEX public."Idx1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/alter_name_fillfactor_comment_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/alter_name_fillfactor_comment_msql.sql new file mode 100644 index 000000000..04740888f --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/alter_name_fillfactor_comment_msql.sql @@ -0,0 +1,11 @@ +ALTER INDEX public."Idx_$%{}[]()&*^!@""'`\/#" + RENAME TO "Idx1_$%{}[]()&*^!@""'`\/#"; + +ALTER INDEX public."Idx1_$%{}[]()&*^!@""'`\/#" + SET (FILLFACTOR=10); + +ALTER TABLE public.test_table_for_indexes + CLUSTER ON "Idx1_$%{}[]()&*^!@""'`\/#"; + +COMMENT ON INDEX public."Idx1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/alter_reset_fillfactor_cluster.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/alter_reset_fillfactor_cluster.sql new file mode 100644 index 000000000..58fdcade8 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/alter_reset_fillfactor_cluster.sql @@ -0,0 +1,11 @@ +-- Index: Idx1_$%{}[]()&*^!@"'`\/# + +-- DROP INDEX public."Idx1_$%{}[]()&*^!@""'`\/#"; + +CREATE UNIQUE INDEX "Idx1_$%{}[]()&*^!@""'`\/#" + ON public.test_table_for_indexes USING btree + (id DESC NULLS FIRST, name COLLATE pg_catalog."POSIX" text_pattern_ops DESC NULLS FIRST) + TABLESPACE pg_default; + +COMMENT ON INDEX public."Idx1_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/alter_reset_fillfactor_cluster_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/alter_reset_fillfactor_cluster_msql.sql new file mode 100644 index 000000000..fe5da6afa --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/alter_reset_fillfactor_cluster_msql.sql @@ -0,0 +1,5 @@ +ALTER INDEX public."Idx1_$%{}[]()&*^!@""'`\/#" + RESET (FILLFACTOR); + +ALTER TABLE public.test_table_for_indexes + SET WITHOUT CLUSTER; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_asc_null_first.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_asc_null_first.sql new file mode 100644 index 000000000..6e0f9bc08 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_asc_null_first.sql @@ -0,0 +1,13 @@ +-- Index: Idx_$%{}[]()&*^!@"'`\/# + +-- DROP INDEX public."Idx_$%{}[]()&*^!@""'`\/#"; + +CREATE UNIQUE INDEX "Idx_$%{}[]()&*^!@""'`\/#" + ON public.test_table_for_indexes USING btree + (id ASC NULLS FIRST, name COLLATE pg_catalog."POSIX" text_pattern_ops ASC NULLS FIRST) + WITH (FILLFACTOR=10) + TABLESPACE pg_default + WHERE id < 100; + +COMMENT ON INDEX public."Idx_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_asc_null_first_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_asc_null_first_msql.sql new file mode 100644 index 000000000..d232de21c --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_asc_null_first_msql.sql @@ -0,0 +1,9 @@ +CREATE UNIQUE INDEX "Idx_$%{}[]()&*^!@""'`\/#" + ON public.test_table_for_indexes USING btree + (id ASC NULLS FIRST, name COLLATE pg_catalog."POSIX" text_pattern_ops ASC NULLS FIRST) + WITH (FILLFACTOR=10) + TABLESPACE pg_default + WHERE id < 100; + +COMMENT ON INDEX public."Idx_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_asc_null_last.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_asc_null_last.sql new file mode 100644 index 000000000..125260734 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_asc_null_last.sql @@ -0,0 +1,13 @@ +-- Index: Idx_$%{}[]()&*^!@"'`\/# + +-- DROP INDEX public."Idx_$%{}[]()&*^!@""'`\/#"; + +CREATE UNIQUE INDEX "Idx_$%{}[]()&*^!@""'`\/#" + ON public.test_table_for_indexes USING btree + (id ASC NULLS LAST, name COLLATE pg_catalog."POSIX" text_pattern_ops ASC NULLS LAST) + WITH (FILLFACTOR=10) + TABLESPACE pg_default + WHERE id < 100; + +COMMENT ON INDEX public."Idx_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_asc_null_last_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_asc_null_last_msql.sql new file mode 100644 index 000000000..df340aaef --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_asc_null_last_msql.sql @@ -0,0 +1,9 @@ +CREATE UNIQUE INDEX "Idx_$%{}[]()&*^!@""'`\/#" + ON public.test_table_for_indexes USING btree + (id ASC NULLS LAST, name COLLATE pg_catalog."POSIX" text_pattern_ops ASC NULLS LAST) + WITH (FILLFACTOR=10) + TABLESPACE pg_default + WHERE id < 100; + +COMMENT ON INDEX public."Idx_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_desc_null_first.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_desc_null_first.sql new file mode 100644 index 000000000..8d8bc290e --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_desc_null_first.sql @@ -0,0 +1,8 @@ +-- Index: Idx_$%{}[]()&*^!@"'`\/# + +-- DROP INDEX public."Idx_$%{}[]()&*^!@""'`\/#"; + +CREATE UNIQUE INDEX "Idx_$%{}[]()&*^!@""'`\/#" + ON public.test_table_for_indexes USING btree + (id DESC NULLS FIRST, name COLLATE pg_catalog."POSIX" text_pattern_ops DESC NULLS FIRST) + TABLESPACE pg_default; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_desc_null_first_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_desc_null_first_msql.sql new file mode 100644 index 000000000..f7db5ea7e --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_desc_null_first_msql.sql @@ -0,0 +1,4 @@ +CREATE UNIQUE INDEX "Idx_$%{}[]()&*^!@""'`\/#" + ON public.test_table_for_indexes USING btree + (id DESC NULLS FIRST, name COLLATE pg_catalog."POSIX" text_pattern_ops DESC NULLS FIRST) + TABLESPACE pg_default; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_desc_null_last.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_desc_null_last.sql new file mode 100644 index 000000000..1f8515eb5 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_desc_null_last.sql @@ -0,0 +1,13 @@ +-- Index: Idx_$%{}[]()&*^!@"'`\/# + +-- DROP INDEX public."Idx_$%{}[]()&*^!@""'`\/#"; + +CREATE UNIQUE INDEX "Idx_$%{}[]()&*^!@""'`\/#" + ON public.test_table_for_indexes USING btree + (id DESC NULLS LAST, name COLLATE pg_catalog."POSIX" text_pattern_ops DESC NULLS LAST) + WITH (FILLFACTOR=10) + TABLESPACE pg_default + WHERE id < 100; + +COMMENT ON INDEX public."Idx_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_desc_null_last_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_desc_null_last_msql.sql new file mode 100644 index 000000000..9e23286a9 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_btree_desc_null_last_msql.sql @@ -0,0 +1,9 @@ +CREATE UNIQUE INDEX "Idx_$%{}[]()&*^!@""'`\/#" + ON public.test_table_for_indexes USING btree + (id DESC NULLS LAST, name COLLATE pg_catalog."POSIX" text_pattern_ops DESC NULLS LAST) + WITH (FILLFACTOR=10) + TABLESPACE pg_default + WHERE id < 100; + +COMMENT ON INDEX public."Idx_$%{}[]()&*^!@""'`\/#" + IS 'Test Comment'; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_hash_index.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_hash_index.sql new file mode 100644 index 000000000..e02c4f0d0 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_hash_index.sql @@ -0,0 +1,8 @@ +-- Index: Idx_$%{}[]()&*^!@"'`\/# + +-- DROP INDEX public."Idx_$%{}[]()&*^!@""'`\/#"; + +CREATE INDEX "Idx_$%{}[]()&*^!@""'`\/#" + ON public.test_table_for_indexes USING hash + (id) + TABLESPACE pg_default; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_hash_index_msql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_hash_index_msql.sql new file mode 100644 index 000000000..14f012b4f --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/create_hash_index_msql.sql @@ -0,0 +1,4 @@ +CREATE INDEX "Idx_$%{}[]()&*^!@""'`\/#" + ON public.test_table_for_indexes USING hash + (id) + TABLESPACE pg_default; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/test_indexes.json b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/test_indexes.json new file mode 100644 index 000000000..e6aac2922 --- /dev/null +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/indexes/tests/default/test_indexes.json @@ -0,0 +1,251 @@ +{ + "scenarios": [ + { + "type": "create", + "name": "Create Table for indexes", + "endpoint": "NODE-table.obj", + "sql_endpoint": "NODE-table.sql_id", + "data": { + "name": "test_table_for_indexes", + "columns": [{ + "name": "id", + "cltype": "bigint", + "is_primary_key": true + }, { + "name": "name", + "cltype": "text" + }], + "is_partitioned": false, + "spcname": "pg_default", + "schema": "public" + }, + "store_object_id": true + }, { + "type": "create", + "name": "Create btree index with ASC and NULLS LAST", + "endpoint": "NODE-index.obj", + "sql_endpoint": "NODE-index.sql_id", + "msql_endpoint": "NODE-index.msql", + "data": { + "name":"Idx_$%{}[]()&*^!@\"'`\\/#", + "spcname":"pg_default", + "amname":"btree", + "columns":[{ + "colname":"id", + "collspcname":"", + "op_class":"", + "sort_order":false, + "nulls":false, + "is_sort_nulls_applicable":true + }, { + "colname":"name", + "collspcname":"pg_catalog.\"POSIX\"", + "op_class":"text_pattern_ops", + "sort_order":false, + "nulls":false, + "is_sort_nulls_applicable":true + }], + "description":"Test Comment", + "fillfactor":"10", + "indisunique":true, + "indisclustered":false, + "isconcurrent":false, + "indconstraint":"id < 100" + }, + "expected_sql_file": "create_btree_asc_null_last.sql", + "expected_msql_file": "create_btree_asc_null_last_msql.sql" + }, { + "type": "delete", + "name": "Drop index", + "endpoint": "NODE-index.delete_id", + "data": { + "name": "Idx_$%{}[]()&*^!@\"'`\\/#" + } + }, { + "type": "create", + "name": "Create btree index with ASC and NULLS FIRST", + "endpoint": "NODE-index.obj", + "sql_endpoint": "NODE-index.sql_id", + "msql_endpoint": "NODE-index.msql", + "data": { + "name":"Idx_$%{}[]()&*^!@\"'`\\/#", + "spcname":"pg_default", + "amname":"btree", + "columns":[{ + "colname":"id", + "collspcname":"", + "op_class":"", + "sort_order":false, + "nulls":true, + "is_sort_nulls_applicable":true + }, { + "colname":"name", + "collspcname":"pg_catalog.\"POSIX\"", + "op_class":"text_pattern_ops", + "sort_order":false, + "nulls":true, + "is_sort_nulls_applicable":true + }], + "description":"Test Comment", + "fillfactor":"10", + "indisunique":true, + "indisclustered":false, + "isconcurrent":false, + "indconstraint":"id < 100" + }, + "expected_sql_file": "create_btree_asc_null_first.sql", + "expected_msql_file": "create_btree_asc_null_first_msql.sql" + }, { + "type": "delete", + "name": "Drop index", + "endpoint": "NODE-index.delete_id", + "data": { + "name": "Idx_$%{}[]()&*^!@\"'`\\/#" + } + }, { + "type": "create", + "name": "Create btree index with DESC and NULLS LAST", + "endpoint": "NODE-index.obj", + "sql_endpoint": "NODE-index.sql_id", + "msql_endpoint": "NODE-index.msql", + "data": { + "name":"Idx_$%{}[]()&*^!@\"'`\\/#", + "spcname":"pg_default", + "amname":"btree", + "columns":[{ + "colname":"id", + "collspcname":"", + "op_class":"", + "sort_order":true, + "nulls":false, + "is_sort_nulls_applicable":true + }, { + "colname":"name", + "collspcname":"pg_catalog.\"POSIX\"", + "op_class":"text_pattern_ops", + "sort_order":true, + "nulls":false, + "is_sort_nulls_applicable":true + }], + "description":"Test Comment", + "fillfactor":"10", + "indisunique":true, + "indisclustered":false, + "isconcurrent":false, + "indconstraint":"id < 100" + }, + "expected_sql_file": "create_btree_desc_null_last.sql", + "expected_msql_file": "create_btree_desc_null_last_msql.sql" + }, { + "type": "delete", + "name": "Drop index", + "endpoint": "NODE-index.delete_id", + "data": { + "name": "Idx_$%{}[]()&*^!@\"'`\\/#" + } + }, { + "type": "create", + "name": "Create btree index with DESC and NULLS FIRST", + "endpoint": "NODE-index.obj", + "sql_endpoint": "NODE-index.sql_id", + "msql_endpoint": "NODE-index.msql", + "data": { + "name":"Idx_$%{}[]()&*^!@\"'`\\/#", + "spcname":"pg_default", + "amname":"btree", + "columns":[{ + "colname":"id", + "collspcname":"", + "op_class":"", + "sort_order":true, + "nulls":true, + "is_sort_nulls_applicable":true + }, { + "colname":"name", + "collspcname":"pg_catalog.\"POSIX\"", + "op_class":"text_pattern_ops", + "sort_order":true, + "nulls":true, + "is_sort_nulls_applicable":true + }], + "indisunique":true, + "indisclustered":false, + "isconcurrent":false + }, + "expected_sql_file": "create_btree_desc_null_first.sql", + "expected_msql_file": "create_btree_desc_null_first_msql.sql" + }, { + "type": "alter", + "name": "Alter index name, fill factor, comment and clustered", + "endpoint": "NODE-index.obj_id", + "sql_endpoint": "NODE-index.sql_id", + "msql_endpoint": "NODE-index.msql_id", + "data": { + "name": "Idx1_$%{}[]()&*^!@\"'`\\/#", + "description":"Test Comment", + "fillfactor":"10", + "indisclustered":true + }, + "expected_sql_file": "alter_name_fillfactor_comment.sql", + "expected_msql_file": "alter_name_fillfactor_comment_msql.sql" + }, + { + "type": "alter", + "name": "Alter reset fill factor and cluster", + "endpoint": "NODE-index.obj_id", + "sql_endpoint": "NODE-index.sql_id", + "msql_endpoint": "NODE-index.msql_id", + "data": { + "fillfactor": "", + "indisclustered": false + }, + "expected_sql_file": "alter_reset_fillfactor_cluster.sql", + "expected_msql_file": "alter_reset_fillfactor_cluster_msql.sql" + }, { + "type": "delete", + "name": "Drop index", + "endpoint": "NODE-index.delete_id", + "data": { + "name": "Idx1_$%{}[]()&*^!@\"'`\\/#" + } + }, { + "type": "create", + "name": "Create hash index", + "endpoint": "NODE-index.obj", + "sql_endpoint": "NODE-index.sql_id", + "msql_endpoint": "NODE-index.msql", + "data": { + "name": "Idx_$%{}[]()&*^!@\"'`\\/#", + "spcname": "pg_default", + "amname": "hash", + "columns": [{ + "colname": "id", + "collspcname": "", + "op_class": "", + "sort_order": false, + "nulls": false, + "is_sort_nulls_applicable": false + }], + "indisunique": false, + "indisclustered": false, + "isconcurrent": false + }, + "expected_sql_file": "create_hash_index.sql", + "expected_msql_file": "create_hash_index_msql.sql" + }, { + "type": "delete", + "name": "Drop hash index", + "endpoint": "NODE-index.delete_id", + "data": { + "name": "Idx_$%{}[]()&*^!@\"'`\\/#" + } + }, { + "type": "delete", + "name": "Drop Table", + "endpoint": "NODE-table.delete_id", + "data": { + "name": "test_table_for_indexes" + } + } + ] +} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/11_plus/column_details.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/11_plus/column_details.sql index 77f158def..bc74732dd 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/11_plus/column_details.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/11_plus/column_details.sql @@ -2,9 +2,9 @@ SELECT i.indexrelid, CASE i.indoption[i.attnum - 1] WHEN 0 THEN ARRAY['ASC', 'NULLS LAST'] - WHEN 1 THEN ARRAY['DESC', 'NULLS FIRST'] + WHEN 1 THEN ARRAY['DESC', 'NULLS LAST'] WHEN 2 THEN ARRAY['ASC', 'NULLS FIRST'] - WHEN 3 THEN ARRAY['DESC', 'NULLS '] + WHEN 3 THEN ARRAY['DESC', 'NULLS FIRST'] ELSE ARRAY['UNKNOWN OPTION' || i.indoption[i.attnum - 1]::text, ''] END::text[] AS options, i.attnum, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/11_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/11_plus/create.sql index 2fd90d79c..119e58958 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/11_plus/create.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/11_plus/create.sql @@ -21,5 +21,5 @@ FIRST{% else %}LAST{% endif %}{% endif %}{% endfor %}) WITH (FILLFACTOR={{data.fillfactor}}) {% endif %}{% if data.spcname %} TABLESPACE {{conn|qtIdent(data.spcname)}}{% endif %}{% if data.indconstraint %} - WHERE {{data.indconstraint}} -{% endif %}; + + WHERE {{data.indconstraint}}{% endif %}; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/column_details.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/column_details.sql index 0f22dc1b2..4d8505a99 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/column_details.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/column_details.sql @@ -2,9 +2,9 @@ SELECT i.indexrelid, CASE i.indoption[i.attnum - 1] WHEN 0 THEN ARRAY['ASC', 'NULLS LAST'] - WHEN 1 THEN ARRAY['DESC', 'NULLS FIRST'] + WHEN 1 THEN ARRAY['DESC', 'NULLS LAST'] WHEN 2 THEN ARRAY['ASC', 'NULLS FIRST'] - WHEN 3 THEN ARRAY['DESC', 'NULLS '] + WHEN 3 THEN ARRAY['DESC', 'NULLS FIRST'] ELSE ARRAY['UNKNOWN OPTION' || i.indoption[i.attnum - 1]::text, ''] END::text[] AS options, i.attnum, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/create.sql index b7bfa5279..2ed401058 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/create.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/create.sql @@ -15,5 +15,5 @@ FIRST{% else %}LAST{% endif %}{% endif %}{% endfor %}) WITH (FILLFACTOR={{data.fillfactor}}) {% endif %}{% if data.spcname %} TABLESPACE {{conn|qtIdent(data.spcname)}}{% endif %}{% if data.indconstraint %} - WHERE {{data.indconstraint}} -{% endif %}; + + WHERE {{data.indconstraint}}{% endif %}; diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/update.sql index f2acd6c2b..85a6519c1 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/update.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/default/update.sql @@ -2,23 +2,37 @@ {% if data.name and o_data.name != data.name %} ALTER INDEX {{conn|qtIdent(data.schema, o_data.name)}} RENAME TO {{conn|qtIdent(data.name)}}; + {% endif %} {## Changes fillfactor ##} {% if data.fillfactor and o_data.fillfactor != data.fillfactor %} ALTER INDEX {{conn|qtIdent(data.schema, data.name)}} SET (FILLFACTOR={{data.fillfactor}}); + +{% elif data.fillfactor == '' and o_data.fillfactor|default('', 'true') != data.fillfactor %} +ALTER INDEX {{conn|qtIdent(data.schema, data.name)}} + RESET (FILLFACTOR); + {% endif %} {## Changes tablespace ##} {% if data.spcname and o_data.spcname != data.spcname %} ALTER INDEX {{conn|qtIdent(data.schema, data.name)}} SET TABLESPACE {{conn|qtIdent(data.spcname)}}; + {% endif %} {## Alter index to use cluster type ##} {% if data.indisclustered is defined and o_data.indisclustered != data.indisclustered %} +{% if data.indisclustered %} ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} CLUSTER ON {{conn|qtIdent(data.name)}}; + +{% else %} +ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} + SET WITHOUT CLUSTER; + +{% endif %} {% endif %} {## Changes description ##} {% if data.description is defined and o_data.description != data.description %} COMMENT ON INDEX {{conn|qtIdent(data.schema, data.name)}} - IS {{data.description|qtLiteral}};{% endif %} \ No newline at end of file + IS {{data.description|qtLiteral}};{% endif %}