Fixed an issue where tablespace was missing on partition tables in SQL. #5470

pull/5621/head
Pravesh Sharma 2022-12-08 12:54:45 +05:30 committed by GitHub
parent b172cd6a16
commit c42a90db8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 24 additions and 7 deletions

View File

@ -288,7 +288,7 @@ class PartitionsView(BaseTableView, DataTypeReader, SchemaDiffObjectCompare):
"""
SQL = render_template(
"/".join([self.partition_template_path, self._NODES_SQL]),
scid=scid, tid=tid, ptid=ptid
scid=scid, tid=tid, ptid=ptid, did=did
)
status, rset = self.conn.execute_2darray(SQL)
if not status:

View File

@ -20,7 +20,8 @@ COMMENT ON TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
-- Partitions SQL
CREATE TABLE public."test_part_$%{}[]()&*^!@""""""""'`\/#" PARTITION OF public."test_table_$%{}[]()&*^!@""""'`\/#"
FOR VALUES FROM ('0') TO ('1000');
FOR VALUES FROM ('0') TO ('1000')
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."test_part_$%{}[]()&*^!@""""""""'`\/#"
OWNER to postgres;

View File

@ -16,7 +16,8 @@ COMMENT ON TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
-- Partitions SQL
CREATE TABLE public."test_part_$%{}[]()&*^!@""""""""'`\/#" PARTITION OF public."test_table_$%{}[]()&*^!@""""'`\/#"
FOR VALUES FROM ('0') TO ('1000');
FOR VALUES FROM ('0') TO ('1000')
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."test_part_$%{}[]()&*^!@""""""""'`\/#"
OWNER to postgres;

View File

@ -20,7 +20,8 @@ COMMENT ON TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
-- Partitions SQL
CREATE TABLE IF NOT EXISTS public."test_part_$%{}[]()&*^!@""""""""'`\/#" PARTITION OF public."test_table_$%{}[]()&*^!@""""'`\/#"
FOR VALUES FROM ('0') TO ('1000');
FOR VALUES FROM ('0') TO ('1000')
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."test_part_$%{}[]()&*^!@""""""""'`\/#"
OWNER to enterprisedb;

View File

@ -16,7 +16,8 @@ COMMENT ON TABLE public."test_table_$%{}[]()&*^!@""""'`\/#"
-- Partitions SQL
CREATE TABLE IF NOT EXISTS public."test_part_$%{}[]()&*^!@""""""""'`\/#" PARTITION OF public."test_table_$%{}[]()&*^!@""""'`\/#"
FOR VALUES FROM ('0') TO ('1000');
FOR VALUES FROM ('0') TO ('1000')
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public."test_part_$%{}[]()&*^!@""""""""'`\/#"
OWNER to enterprisedb;

View File

@ -9,6 +9,11 @@ SELECT rel.oid, rel.relname AS name,
(CASE WHEN rel.relkind = 'p' THEN pg_catalog.pg_get_partkeydef(rel.oid::oid) ELSE '' END) AS partition_scheme,
(CASE WHEN rel.relkind = 'p' THEN pg_catalog.pg_get_partkeydef(rel.oid::oid) ELSE '' END) AS sub_partition_scheme,
(CASE WHEN rel.relpersistence = 'u' THEN true ELSE false END) AS relpersistence,
(CASE WHEN length(spc.spcname::text) > 0 THEN spc.spcname ELSE
(SELECT sp.spcname FROM pg_catalog.pg_database dtb
JOIN pg_catalog.pg_tablespace sp ON dtb.dattablespace=sp.oid
WHERE dtb.oid = {{ did }}::oid)
END) as spcname,
substring(pg_catalog.array_to_string(rel.reloptions, ',') FROM 'fillfactor=([0-9]*)') AS fillfactor,
(substring(pg_catalog.array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled,
substring(pg_catalog.array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold,
@ -38,6 +43,7 @@ FROM
LEFT JOIN pg_catalog.pg_namespace nsp ON rel.relnamespace = nsp.oid
LEFT OUTER JOIN pg_catalog.pg_class tst ON tst.oid = rel.reltoastrelid
LEFT OUTER JOIN pg_catalog.pg_description des ON (des.objoid=rel.oid AND des.objsubid=0 AND des.classoid='pg_class'::regclass)
LEFT OUTER JOIN pg_catalog.pg_tablespace spc on spc.oid=rel.reltablespace
LEFT JOIN pg_catalog.pg_type typ ON rel.reloftype=typ.oid
WHERE rel.relispartition
{% if ptid %} AND rel.oid = {{ ptid }}::OID {% endif %}

View File

@ -9,6 +9,11 @@ SELECT rel.oid, rel.relname AS name,
(CASE WHEN rel.relkind = 'p' THEN pg_catalog.pg_get_partkeydef(rel.oid::oid) ELSE '' END) AS partition_scheme,
(CASE WHEN rel.relkind = 'p' THEN pg_catalog.pg_get_partkeydef(rel.oid::oid) ELSE '' END) AS sub_partition_scheme,
(CASE WHEN rel.relpersistence = 'u' THEN true ELSE false END) AS relpersistence,
(CASE WHEN length(spc.spcname::text) > 0 THEN spc.spcname ELSE
(SELECT sp.spcname FROM pg_catalog.pg_database dtb
JOIN pg_catalog.pg_tablespace sp ON dtb.dattablespace=sp.oid
WHERE dtb.oid = {{ did }}::oid)
END) as spcname,
substring(pg_catalog.array_to_string(rel.reloptions, ',') FROM 'fillfactor=([0-9]*)') AS fillfactor,
(substring(pg_catalog.array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled,
substring(pg_catalog.array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold,
@ -38,6 +43,7 @@ FROM
LEFT JOIN pg_catalog.pg_namespace nsp ON rel.relnamespace = nsp.oid
LEFT OUTER JOIN pg_catalog.pg_class tst ON tst.oid = rel.reltoastrelid
LEFT OUTER JOIN pg_catalog.pg_description des ON (des.objoid=rel.oid AND des.objsubid=0 AND des.classoid='pg_class'::regclass)
LEFT OUTER JOIN pg_catalog.pg_tablespace spc on spc.oid=rel.reltablespace
LEFT JOIN pg_catalog.pg_type typ ON rel.reloftype=typ.oid
WHERE rel.relispartition
{% if ptid %} AND rel.oid = {{ ptid }}::OID {% endif %}

View File

@ -916,6 +916,7 @@ class BaseTableView(PGChildNodeView, BasePartitionTable, VacuumSettings):
part_data = dict()
part_data['partitioned_table_name'] = data['name']
part_data['parent_schema'] = data['schema']
part_data['spcname'] = row['spcname']
if not json_resp:
part_data['schema'] = data['schema']
else:
@ -1074,7 +1075,7 @@ class BaseTableView(PGChildNodeView, BasePartitionTable, VacuumSettings):
if is_partitioned:
sql = render_template("/".join([self.partition_template_path,
self._NODES_SQL]),
scid=scid, tid=tid)
scid=scid, tid=tid, did=did)
status, rset = self.conn.execute_2darray(sql)
if not status:
return internal_server_error(errormsg=rset)
@ -1769,7 +1770,7 @@ class BaseTableView(PGChildNodeView, BasePartitionTable, VacuumSettings):
partitions = []
sql = render_template("/".join([self.partition_template_path,
self._NODES_SQL]),
scid=scid, tid=tid)
scid=scid, tid=tid, did=did)
status, rset = self.conn.execute_2darray(sql)
if not status:
return internal_server_error(errormsg=rset)