Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ def sql(self, gid, sid, did, scid, tid):

return BaseTableView.get_reverse_engineered_sql(
self, did=did, scid=scid, tid=tid, main_sql=main_sql, data=data,
add_not_exists_clause=True)
add_not_exists_clause=True, show_default_values_for_indexes=False)

@BaseTableView.check_precondition
def select_sql(self, gid, sid, did, scid, tid):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,19 +505,22 @@ def properties(self, gid, sid, did, scid, tid, idx):
status=200
)

def _fetch_properties(self, did, tid, idx):
def _fetch_properties(self, did, tid, idx, show_default_values=True):
"""
This function is used to fetch the properties of specified object.
:param did:
:param tid:
:param idx:
:param show_default_values:
Whether to show default values in CASE statements
:return:
"""
SQL = render_template(
"/".join([self.template_path, self._PROPERTIES_SQL]),
did=did, tid=tid, idx=idx,
datlastsysoid=self._DATABASE_LAST_SYSTEM_OID,
show_sys_objects=self.blueprint.show_system_objects
show_sys_objects=self.blueprint.show_system_objects,
show_default_values=show_default_values
)

status, res = self.conn.execute_dict(SQL)
Expand Down Expand Up @@ -724,7 +727,8 @@ def delete(self, gid, sid, did, scid, tid, **kwargs):
"/".join([self.template_path, self._PROPERTIES_SQL]),
did=did, tid=tid, idx=idx,
datlastsysoid=self._DATABASE_LAST_SYSTEM_OID,
show_sys_objects=self.blueprint.show_system_objects
show_sys_objects=self.blueprint.show_system_objects,
show_default_values=True
)

status, res = self.conn.execute_dict(SQL)
Expand Down Expand Up @@ -879,7 +883,8 @@ def sql(self, gid, sid, did, scid, tid, idx):
self.conn, schema=self.schema, table=self.table, did=did,
tid=tid, idx=idx, datlastsysoid=self._DATABASE_LAST_SYSTEM_OID,
add_not_exists_clause=True,
show_sys_objects=self.blueprint.show_system_objects
show_sys_objects=self.blueprint.show_system_objects,
show_default_values=False
)

return ajax_response(response=SQL)
Expand Down Expand Up @@ -1010,7 +1015,8 @@ def statistics(self, gid, sid, did, scid, tid, idx=None):
"/".join([self.template_path, self._PROPERTIES_SQL]),
did=did, tid=tid, idx=idx,
datlastsysoid=self._DATABASE_LAST_SYSTEM_OID,
show_sys_objects=self.blueprint.show_system_objects
show_sys_objects=self.blueprint.show_system_objects,
show_default_values=True
)
status, res = self.conn.execute_dict(SQL)
if not status:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ CREATE UNIQUE INDEX IF NOT EXISTS "Idx1_$%{}[]()&*^!@""'`\/#"
ON public.test_table_for_indexes USING btree
(id DESC NULLS FIRST, name COLLATE pg_catalog."POSIX" text_pattern_ops DESC NULLS FIRST)
INCLUDE(name, id)
WITH (fillfactor=100)
TABLESPACE pg_default;

COMMENT ON INDEX public."Idx1_$%{}[]()&*^!@""'`\/#"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ CREATE UNIQUE INDEX IF NOT EXISTS "Idx_$%{}[]()&*^!@""'`\/#"
ON public.test_table_for_indexes USING btree
(id DESC NULLS FIRST, name COLLATE pg_catalog."POSIX" text_pattern_ops DESC NULLS FIRST)
INCLUDE(name, id)
WITH (fillfactor=100)
WITH (fillfactor=90)
TABLESPACE pg_default;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS "Idx3_$%{}[]()&*^!@""'`\/#"
ON public.test_table_for_indexes USING btree
(id ASC NULLS LAST, lower(name) COLLATE pg_catalog."POSIX" text_pattern_ops ASC NULLS LAST)
INCLUDE(name, id)
WITH (fillfactor=10, deduplicate_items=True)
WITH (fillfactor=10)
TABLESPACE pg_default
WHERE id < 100;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS "Idx1_$%{}[]()&*^!@""'`\/#"
ON public.test_table_for_indexes USING btree
(id DESC NULLS FIRST, name COLLATE pg_catalog."POSIX" text_pattern_ops DESC NULLS FIRST)
INCLUDE(name, id)
WITH (fillfactor=10, deduplicate_items=True)
WITH (fillfactor=10)
TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.test_table_for_indexes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ CREATE UNIQUE INDEX IF NOT EXISTS "Idx1_$%{}[]()&*^!@""'`\/#"
ON public.test_table_for_indexes USING btree
(id DESC NULLS FIRST, name COLLATE pg_catalog."POSIX" text_pattern_ops DESC NULLS FIRST)
INCLUDE(name, id)
WITH (fillfactor=100, deduplicate_items=True)
TABLESPACE pg_default;

COMMENT ON INDEX public."Idx1_$%{}[]()&*^!@""'`\/#"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ CREATE UNIQUE INDEX IF NOT EXISTS "Idx_$%{}[]()&*^!@""'`\/#"
ON public.test_table_for_indexes USING btree
(id DESC NULLS FIRST, name COLLATE pg_catalog."POSIX" text_pattern_ops DESC NULLS FIRST)
INCLUDE(name, id)
WITH (fillfactor=100, deduplicate_items=True)
TABLESPACE pg_default;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS "Idx3_$%{}[]()&*^!@""'`\/#"
ON public.test_table_for_indexes USING btree
(id ASC NULLS LAST, lower(name) COLLATE pg_catalog."POSIX" text_pattern_ops ASC NULLS LAST)
INCLUDE(name, id)
WITH (fillfactor=10, deduplicate_items=True)
WITH (fillfactor=10)
TABLESPACE pg_default
WHERE id < 100;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS "Idx1_$%{}[]()&*^!@""'`\/#"
(id DESC NULLS FIRST, name COLLATE pg_catalog."POSIX" text_pattern_ops DESC NULLS FIRST)
INCLUDE(name, id)
NULLS NOT DISTINCT
WITH (fillfactor=10, deduplicate_items=True)
WITH (fillfactor=10)
TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.test_table_for_indexes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ CREATE UNIQUE INDEX IF NOT EXISTS "Idx1_$%{}[]()&*^!@""'`\/#"
(id DESC NULLS FIRST, name COLLATE pg_catalog."POSIX" text_pattern_ops DESC NULLS FIRST)
INCLUDE(name, id)
NULLS NOT DISTINCT
WITH (fillfactor=100, deduplicate_items=True)
TABLESPACE pg_default;

COMMENT ON INDEX public."Idx1_$%{}[]()&*^!@""'`\/#"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS "Idx_$%{}[]()&*^!@""'`\/#"
(id ASC NULLS FIRST, name COLLATE pg_catalog."POSIX" text_pattern_ops ASC NULLS FIRST)
INCLUDE(name, id)
NULLS NOT DISTINCT
WITH (fillfactor=10, deduplicate_items=True)
WITH (fillfactor=10)
TABLESPACE pg_default
WHERE id < 100;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS "Idx_$%{}[]()&*^!@""'`\/#"
(id ASC NULLS LAST, name COLLATE pg_catalog."POSIX" text_pattern_ops ASC NULLS LAST)
INCLUDE(name, id)
NULLS NOT DISTINCT
WITH (fillfactor=10, deduplicate_items=True)
WITH (fillfactor=10)
TABLESPACE pg_default
WHERE id < 100;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ CREATE UNIQUE INDEX IF NOT EXISTS "Idx_$%{}[]()&*^!@""'`\/#"
(id DESC NULLS FIRST, name COLLATE pg_catalog."POSIX" text_pattern_ops DESC NULLS FIRST)
INCLUDE(name, id)
NULLS NOT DISTINCT
WITH (fillfactor=100, deduplicate_items=True)
TABLESPACE pg_default;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS "Idx_$%{}[]()&*^!@""'`\/#"
(id DESC NULLS LAST, name COLLATE pg_catalog."POSIX" text_pattern_ops DESC NULLS LAST)
INCLUDE(name, id)
NULLS NOT DISTINCT
WITH (fillfactor=10, deduplicate_items=True)
WITH (fillfactor=10)
TABLESPACE pg_default
WHERE id < 100;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
CREATE UNIQUE INDEX IF NOT EXISTS "Idx3_$%{}[]()&*^!@""'`\/#"
ON public.test_table_for_indexes USING btree
(id ASC NULLS LAST, lower(name) COLLATE pg_catalog."POSIX" text_pattern_ops ASC NULLS LAST)
WITH (fillfactor=10, deduplicate_items=True)
WITH (fillfactor=10)
TABLESPACE pg_default
WHERE id < 100;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
CREATE UNIQUE INDEX IF NOT EXISTS "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, deduplicate_items=True)
WITH (fillfactor=10)
TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.test_table_for_indexes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
CREATE UNIQUE INDEX IF NOT EXISTS "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, deduplicate_items=True)
WITH (fillfactor=10)
TABLESPACE pg_default
WHERE id < 100;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
CREATE UNIQUE INDEX IF NOT EXISTS "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, deduplicate_items=True)
WITH (fillfactor=10)
TABLESPACE pg_default
WHERE id < 100;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CREATE UNIQUE INDEX "Idx3_$%{}[]()&*^!@""'`\/#"
ON public.test_table_for_indexes USING btree
(id ASC NULLS LAST, (lower(name)) COLLATE pg_catalog."POSIX" text_pattern_ops ASC NULLS LAST)
WITH (fillfactor=10, deduplicate_items=True)
WITH (fillfactor=10)
TABLESPACE pg_default
WHERE id < 100;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,13 @@ def get_reverse_engineered_sql(conn, **kwargs):
with_header = kwargs.get('with_header', True)
if_exists_flag = kwargs.get('add_not_exists_clause', False)
show_sys_obj = kwargs.get('show_sys_objects', False)
show_default_values = kwargs.get('show_default_values', True)

SQL = render_template("/".join([template_path, 'properties.sql']),
did=did, tid=tid, idx=idx,
datlastsysoid=datlastsysoid,
show_sys_objects=show_sys_obj)
show_sys_objects=show_sys_obj,
show_default_values=show_default_values)

status, res = conn.execute_dict(SQL)
if not status:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,72 @@ SELECT DISTINCT ON (cls.relname)
-- Options (with defaults per index type)
COALESCE(
substring(array_to_string(cls.reloptions, ',') FROM 'fillfactor=([0-9]*)')::int,
CASE am.amname
WHEN 'btree' THEN 100
WHEN 'gist' THEN 90
ELSE NULL
END
{% if show_default_values %}
CASE am.amname
WHEN 'btree' THEN 90
WHEN 'gist' THEN 90
WHEN 'hash' THEN 90
WHEN 'spgist' THEN 80
ELSE NULL
END
{% else %}
NULL
{% endif %}
) AS fillfactor,
COALESCE(
CASE am.amname
WHEN 'gin' THEN substring(array_to_string(cls.reloptions, ',') FROM 'gin_pending_list_limit=([0-9]*)')::int
ELSE NULL
END,
CASE am.amname WHEN 'gin' THEN 4096 * 1024 ELSE NULL END
{% if show_default_values %}
CASE am.amname WHEN 'gin' THEN 4096 * 1024 ELSE NULL END
{% else %}
NULL
{% endif %}
) AS gin_pending_list_limit,
COALESCE(
CASE am.amname
WHEN 'brin' THEN substring(array_to_string(cls.reloptions, ',') FROM 'pages_per_range=([0-9]*)')::int
ELSE NULL
END,
CASE am.amname WHEN 'brin' THEN 128 ELSE NULL END
{% if show_default_values %}
CASE am.amname WHEN 'brin' THEN 128 ELSE NULL END
{% else %}
NULL
{% endif %}
) AS pages_per_range,
COALESCE(
CASE am.amname
WHEN 'gist' THEN substring(array_to_string(cls.reloptions, ',') FROM 'buffering=([a-z]*)')
ELSE NULL
END,
CASE am.amname WHEN 'gist' THEN 'auto' ELSE NULL END
{% if show_default_values %}
CASE am.amname WHEN 'gist' THEN 'auto' ELSE NULL END
{% else %}
NULL
{% endif %}
) AS buffering,
COALESCE(
CASE am.amname
WHEN 'gin' THEN substring(array_to_string(cls.reloptions, ',') FROM 'fastupdate=([a-z]*)')::boolean
ELSE NULL
END,
CASE am.amname WHEN 'gin' THEN TRUE ELSE NULL END
{% if show_default_values %}
CASE am.amname WHEN 'gin' THEN TRUE ELSE NULL END
{% else %}
NULL
{% endif %}
) AS fastupdate,
COALESCE(
CASE am.amname
WHEN 'brin' THEN substring(array_to_string(cls.reloptions, ',') FROM 'autosummarize=([a-z]*)')::boolean
ELSE NULL
END,
CASE am.amname WHEN 'brin' THEN FALSE ELSE NULL END
{% if show_default_values %}
CASE am.amname WHEN 'brin' THEN FALSE ELSE NULL END
{% else %}
NULL
{% endif %}
) AS autosummarize,
COALESCE(
substring(array_to_string(cls.reloptions, ',') FROM 'lists=([0-9]*)')::int,
Expand Down
Loading
Loading