Add a public.citus_tables view

pull/4309/head
Marco Slot 2020-12-03 16:33:18 +01:00
parent 4098d33acb
commit c9b658daea
11 changed files with 166 additions and 38 deletions

View File

@ -1,7 +1,6 @@
-- citus--9.5-1--10.0-1
-- bump version to 10.0-1
#include "udfs/citus_tables/10.0-1.sql"
#include "udfs/citus_finish_pg_upgrade/10.0-1.sql"
#include "../../columnar/sql/columnar--9.5-1--10.0-1.sql"

View File

@ -4,3 +4,5 @@
#include "../udfs/citus_finish_pg_upgrade/9.5-1.sql"
#include "../../../columnar/sql/downgrades/columnar--10.0-1--9.5-1.sql"
DROP VIEW public.citus_tables;

View File

@ -0,0 +1,20 @@
CREATE VIEW public.citus_tables AS
SELECT
logicalrelid AS "Name",
CASE WHEN partkey IS NOT NULL THEN 'distributed' ELSE 'reference' END AS "Citus Table Type",
coalesce(column_to_column_name(logicalrelid, partkey), '<none>') AS "Distribution Column",
colocationid AS "Colocation ID",
pg_size_pretty(citus_total_relation_size(logicalrelid)) AS "Size",
(select count(*) from pg_dist_shard where logicalrelid = p.logicalrelid) AS "Shard Count",
pg_get_userbyid(relowner) AS "Owner",
amname AS "Access Method"
FROM
pg_dist_partition p
JOIN
pg_class c ON (p.logicalrelid = c.oid)
LEFT JOIN
pg_am a ON (a.oid = c.relam)
WHERE
partkey IS NOT NULL OR repmodel = 't'
ORDER BY
logicalrelid::text;

View File

@ -0,0 +1,20 @@
CREATE VIEW public.citus_tables AS
SELECT
logicalrelid AS "Name",
CASE WHEN partkey IS NOT NULL THEN 'distributed' ELSE 'reference' END AS "Citus Table Type",
coalesce(column_to_column_name(logicalrelid, partkey), '<none>') AS "Distribution Column",
colocationid AS "Colocation ID",
pg_size_pretty(citus_total_relation_size(logicalrelid)) AS "Size",
(select count(*) from pg_dist_shard where logicalrelid = p.logicalrelid) AS "Shard Count",
pg_get_userbyid(relowner) AS "Owner",
amname AS "Access Method"
FROM
pg_dist_partition p
JOIN
pg_class c ON (p.logicalrelid = c.oid)
LEFT JOIN
pg_am a ON (a.oid = c.relam)
WHERE
partkey IS NOT NULL OR repmodel = 't'
ORDER BY
logicalrelid::text;

View File

@ -82,18 +82,19 @@ FROM test.maintenance_worker();
regression | regression | postgres | postgres
(1 row)
-- ensure no objects were created outside pg_catalog
SELECT COUNT(*)
-- ensure no unexpected objects were created outside pg_catalog
SELECT pgio.type, pgio.identity
FROM pg_depend AS pgd,
pg_extension AS pge,
LATERAL pg_identify_object(pgd.classid, pgd.objid, pgd.objsubid) AS pgio
WHERE pgd.refclassid = 'pg_extension'::regclass AND
pgd.refobjid = pge.oid AND
pge.extname = 'citus' AND
pgio.schema NOT IN ('pg_catalog', 'citus', 'citus_internal', 'test', 'cstore');
count
pgio.schema NOT IN ('pg_catalog', 'citus', 'citus_internal', 'test', 'cstore')
ORDER BY 1, 2;
type | identity
---------------------------------------------------------------------
0
view | public.citus_tables
(1 row)
-- DROP EXTENSION pre-created by the regression suite
@ -487,7 +488,8 @@ SELECT * FROM print_extension_changes();
| table cstore.cstore_skipnodes
| table cstore.cstore_stripes
| table cstore.options
(10 rows)
| view citus_tables
(11 rows)
DROP TABLE prev_objects, extension_diff;
-- show running version
@ -497,18 +499,19 @@ SHOW citus.version;
10.0devel
(1 row)
-- ensure no objects were created outside pg_catalog
SELECT COUNT(*)
-- ensure no unexpected objects were created outside pg_catalog
SELECT pgio.type, pgio.identity
FROM pg_depend AS pgd,
pg_extension AS pge,
LATERAL pg_identify_object(pgd.classid, pgd.objid, pgd.objsubid) AS pgio
WHERE pgd.refclassid = 'pg_extension'::regclass AND
pgd.refobjid = pge.oid AND
pge.extname = 'citus' AND
pgio.schema NOT IN ('pg_catalog', 'citus', 'citus_internal', 'test', 'cstore');
count
pgio.schema NOT IN ('pg_catalog', 'citus', 'citus_internal', 'test', 'cstore')
ORDER BY 1, 2;
type | identity
---------------------------------------------------------------------
0
view | public.citus_tables
(1 row)
-- see incompatible version errors out
@ -593,10 +596,11 @@ SET citus.enable_version_checks TO 'true';
ALTER EXTENSION citus UPDATE;
-- if cache is invalidated succesfull, this \d should work without any problem
\d
List of relations
Schema | Name | Type | Owner
List of relations
Schema | Name | Type | Owner
---------------------------------------------------------------------
(0 rows)
public | citus_tables | view | postgres
(1 row)
\c - - - :master_port
-- test https://github.com/citusdata/citus/issues/3409

View File

@ -82,18 +82,19 @@ FROM test.maintenance_worker();
regression | regression | postgres | postgres
(1 row)
-- ensure no objects were created outside pg_catalog
SELECT COUNT(*)
-- ensure no unexpected objects were created outside pg_catalog
SELECT pgio.type, pgio.identity
FROM pg_depend AS pgd,
pg_extension AS pge,
LATERAL pg_identify_object(pgd.classid, pgd.objid, pgd.objsubid) AS pgio
WHERE pgd.refclassid = 'pg_extension'::regclass AND
pgd.refobjid = pge.oid AND
pge.extname = 'citus' AND
pgio.schema NOT IN ('pg_catalog', 'citus', 'citus_internal', 'test', 'cstore');
count
pgio.schema NOT IN ('pg_catalog', 'citus', 'citus_internal', 'test', 'cstore')
ORDER BY 1, 2;
type | identity
---------------------------------------------------------------------
0
view | public.citus_tables
(1 row)
-- DROP EXTENSION pre-created by the regression suite
@ -483,7 +484,8 @@ SELECT * FROM print_extension_changes();
| table cstore.cstore_skipnodes
| table cstore.cstore_stripes
| table cstore.options
(6 rows)
| view citus_tables
(7 rows)
DROP TABLE prev_objects, extension_diff;
-- show running version
@ -493,18 +495,19 @@ SHOW citus.version;
10.0devel
(1 row)
-- ensure no objects were created outside pg_catalog
SELECT COUNT(*)
-- ensure no unexpected objects were created outside pg_catalog
SELECT pgio.type, pgio.identity
FROM pg_depend AS pgd,
pg_extension AS pge,
LATERAL pg_identify_object(pgd.classid, pgd.objid, pgd.objsubid) AS pgio
WHERE pgd.refclassid = 'pg_extension'::regclass AND
pgd.refobjid = pge.oid AND
pge.extname = 'citus' AND
pgio.schema NOT IN ('pg_catalog', 'citus', 'citus_internal', 'test', 'cstore');
count
pgio.schema NOT IN ('pg_catalog', 'citus', 'citus_internal', 'test', 'cstore')
ORDER BY 1, 2;
type | identity
---------------------------------------------------------------------
0
view | public.citus_tables
(1 row)
-- see incompatible version errors out
@ -589,10 +592,11 @@ SET citus.enable_version_checks TO 'true';
ALTER EXTENSION citus UPDATE;
-- if cache is invalidated succesfull, this \d should work without any problem
\d
List of relations
Schema | Name | Type | Owner
List of relations
Schema | Name | Type | Owner
---------------------------------------------------------------------
(0 rows)
public | citus_tables | view | postgres
(1 row)
\c - - - :master_port
-- test https://github.com/citusdata/citus/issues/3409

View File

@ -484,3 +484,65 @@ ORDER BY colocationid, logicalrelid;
articles_single_shard_hash_mx | 1390011 | 1 | h | s
(23 rows)
-- check the citus_tables view
SELECT "Name", "Citus Table Type", "Distribution Column", "Shard Count", "Owner"
FROM citus_tables
ORDER BY "Name"::text;
Name | Citus Table Type | Distribution Column | Shard Count | Owner
---------------------------------------------------------------------
app_analytics_events_mx | distributed | app_id | 4 | postgres
articles_hash_mx | distributed | author_id | 2 | postgres
articles_single_shard_hash_mx | distributed | author_id | 1 | postgres
citus_mx_test_schema.nation_hash | distributed | n_nationkey | 16 | postgres
citus_mx_test_schema.nation_hash_collation_search_path | distributed | n_nationkey | 4 | postgres
citus_mx_test_schema.nation_hash_composite_types | distributed | n_nationkey | 4 | postgres
citus_mx_test_schema_join_1.nation_hash | distributed | n_nationkey | 4 | postgres
citus_mx_test_schema_join_1.nation_hash_2 | distributed | n_nationkey | 4 | postgres
citus_mx_test_schema_join_2.nation_hash | distributed | n_nationkey | 4 | postgres
company_employees_mx | distributed | company_id | 4 | postgres
customer_mx | reference | <none> | 1 | postgres
labs_mx | distributed | id | 1 | postgres
limit_orders_mx | distributed | id | 2 | postgres
lineitem_mx | distributed | l_orderkey | 16 | postgres
multiple_hash_mx | distributed | category | 2 | postgres
mx_ddl_table | distributed | key | 4 | postgres
nation_hash | distributed | n_nationkey | 16 | postgres
nation_mx | reference | <none> | 1 | postgres
objects_mx | distributed | id | 1 | postgres
orders_mx | distributed | o_orderkey | 16 | postgres
part_mx | reference | <none> | 1 | postgres
researchers_mx | distributed | lab_id | 2 | postgres
supplier_mx | reference | <none> | 1 | postgres
(23 rows)
\c - - - :worker_1_port
SELECT "Name", "Citus Table Type", "Distribution Column", "Shard Count", "Owner"
FROM citus_tables
ORDER BY "Name"::text;
Name | Citus Table Type | Distribution Column | Shard Count | Owner
---------------------------------------------------------------------
app_analytics_events_mx | distributed | app_id | 4 | postgres
articles_hash_mx | distributed | author_id | 2 | postgres
articles_single_shard_hash_mx | distributed | author_id | 1 | postgres
citus_mx_test_schema.nation_hash | distributed | n_nationkey | 16 | postgres
citus_mx_test_schema.nation_hash_collation_search_path | distributed | n_nationkey | 4 | postgres
citus_mx_test_schema.nation_hash_composite_types | distributed | n_nationkey | 4 | postgres
citus_mx_test_schema_join_1.nation_hash | distributed | n_nationkey | 4 | postgres
citus_mx_test_schema_join_1.nation_hash_2 | distributed | n_nationkey | 4 | postgres
citus_mx_test_schema_join_2.nation_hash | distributed | n_nationkey | 4 | postgres
company_employees_mx | distributed | company_id | 4 | postgres
customer_mx | reference | <none> | 1 | postgres
labs_mx | distributed | id | 1 | postgres
limit_orders_mx | distributed | id | 2 | postgres
lineitem_mx | distributed | l_orderkey | 16 | postgres
multiple_hash_mx | distributed | category | 2 | postgres
mx_ddl_table | distributed | key | 4 | postgres
nation_hash | distributed | n_nationkey | 16 | postgres
nation_mx | reference | <none> | 1 | postgres
objects_mx | distributed | id | 1 | postgres
orders_mx | distributed | o_orderkey | 16 | postgres
part_mx | reference | <none> | 1 | postgres
researchers_mx | distributed | lab_id | 2 | postgres
supplier_mx | reference | <none> | 1 | postgres
(23 rows)

View File

@ -215,7 +215,8 @@ ORDER BY 1;
view citus_shard_indexes_on_worker
view citus_shards_on_worker
view citus_stat_statements
view citus_tables
view citus_worker_stat_activity
view pg_dist_shard_placement
(201 rows)
(202 rows)

View File

@ -211,7 +211,8 @@ ORDER BY 1;
view citus_shard_indexes_on_worker
view citus_shards_on_worker
view citus_stat_statements
view citus_tables
view citus_worker_stat_activity
view pg_dist_shard_placement
(197 rows)
(198 rows)

View File

@ -80,15 +80,16 @@ SELECT datname, current_database(),
usename, (SELECT extowner::regrole::text FROM pg_extension WHERE extname = 'citus')
FROM test.maintenance_worker();
-- ensure no objects were created outside pg_catalog
SELECT COUNT(*)
-- ensure no unexpected objects were created outside pg_catalog
SELECT pgio.type, pgio.identity
FROM pg_depend AS pgd,
pg_extension AS pge,
LATERAL pg_identify_object(pgd.classid, pgd.objid, pgd.objsubid) AS pgio
WHERE pgd.refclassid = 'pg_extension'::regclass AND
pgd.refobjid = pge.oid AND
pge.extname = 'citus' AND
pgio.schema NOT IN ('pg_catalog', 'citus', 'citus_internal', 'test', 'cstore');
pgio.schema NOT IN ('pg_catalog', 'citus', 'citus_internal', 'test', 'cstore')
ORDER BY 1, 2;
-- DROP EXTENSION pre-created by the regression suite
@ -235,15 +236,16 @@ DROP TABLE prev_objects, extension_diff;
-- show running version
SHOW citus.version;
-- ensure no objects were created outside pg_catalog
SELECT COUNT(*)
-- ensure no unexpected objects were created outside pg_catalog
SELECT pgio.type, pgio.identity
FROM pg_depend AS pgd,
pg_extension AS pge,
LATERAL pg_identify_object(pgd.classid, pgd.objid, pgd.objsubid) AS pgio
WHERE pgd.refclassid = 'pg_extension'::regclass AND
pgd.refobjid = pge.oid AND
pge.extname = 'citus' AND
pgio.schema NOT IN ('pg_catalog', 'citus', 'citus_internal', 'test', 'cstore');
pgio.schema NOT IN ('pg_catalog', 'citus', 'citus_internal', 'test', 'cstore')
ORDER BY 1, 2;
-- see incompatible version errors out
RESET citus.enable_version_checks;

View File

@ -427,3 +427,16 @@ WITH shard_counts AS (
SELECT logicalrelid, colocationid, shard_count, partmethod, repmodel
FROM pg_dist_partition NATURAL JOIN shard_counts
ORDER BY colocationid, logicalrelid;
-- check the citus_tables view
SELECT "Name", "Citus Table Type", "Distribution Column", "Shard Count", "Owner"
FROM citus_tables
ORDER BY "Name"::text;
\c - - - :worker_1_port
SELECT "Name", "Citus Table Type", "Distribution Column", "Shard Count", "Owner"
FROM citus_tables
ORDER BY "Name"::text;