Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add size_plus_indexes_bytes column to schemas, tables, and views #29

Merged
merged 1 commit into from
Jan 23, 2022
Merged
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
60 changes: 33 additions & 27 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ extension_sql_file!("sql/load_default_data.sql",
#[pg_extern]
fn schemas(
) -> impl std::iter::Iterator<Item = (name!(s_name, Option<String>),
name!(owner, Option<String>),
name!(data_source, Option<String>),
name!(sensitive, Option<bool>),
name!(description, Option<String>),
name!(system_object, Option<bool>),
name!(table_count, Option<i64>),
name!(view_count, Option<i64>),
name!(function_count, Option<i64>),
name!(size_pretty, Option<String>),
name!(size_plus_indexes, Option<String>),
name!(size_bytes, Option<i64>))>
name!(owner, Option<String>),
name!(data_source, Option<String>),
name!(sensitive, Option<bool>),
name!(description, Option<String>),
name!(system_object, Option<bool>),
name!(table_count, Option<i64>),
name!(view_count, Option<i64>),
name!(function_count, Option<i64>),
name!(size_pretty, Option<String>),
name!(size_plus_indexes, Option<String>),
name!(size_bytes, Option<i64>),
name!(size_plus_indexes_bytes, Option<i64>))>
{
let query = include_str!("sql/function_query/schemas-all.sql");

Expand All @@ -51,7 +52,8 @@ fn schemas(
row.by_ordinal(9).unwrap().value::<i64>(),
row.by_ordinal(10).unwrap().value::<String>(),
row.by_ordinal(11).unwrap().value::<String>(),
row.by_ordinal(12).unwrap().value::<i64>()
row.by_ordinal(12).unwrap().value::<i64>(),
row.by_ordinal(13).unwrap().value::<i64>()
))
.for_each(|tuple| results.push(tuple));
Ok(Some(()))
Expand Down Expand Up @@ -156,6 +158,7 @@ fn tables(
name!(size_bytes, Option<i64>),
name!(rows, Option<i64>),
name!(bytes_per_row, Option<i64>),
name!(size_plus_indexes_bytes, Option<i64>),
name!(size_plus_indexes, Option<String>),
name!(description, Option<String>),
name!(system_object, Option<bool>),
Expand All @@ -178,12 +181,13 @@ fn tables(
row.by_ordinal(6).unwrap().value::<i64>(),
row.by_ordinal(7).unwrap().value::<i64>(),
row.by_ordinal(8).unwrap().value::<i64>(),
row.by_ordinal(9).unwrap().value::<String>(),
row.by_ordinal(9).unwrap().value::<i64>(),
row.by_ordinal(10).unwrap().value::<String>(),
row.by_ordinal(11).unwrap().value::<bool>(),
row.by_ordinal(12).unwrap().value::<String>(),
row.by_ordinal(13).unwrap().value::<bool>(),
row.by_ordinal(14).unwrap().value::<i64>()
row.by_ordinal(11).unwrap().value::<String>(),
row.by_ordinal(12).unwrap().value::<bool>(),
row.by_ordinal(13).unwrap().value::<String>(),
row.by_ordinal(14).unwrap().value::<bool>(),
row.by_ordinal(15).unwrap().value::<i64>()
))
.for_each(|tuple| results.push(tuple));
Ok(Some(()))
Expand All @@ -197,14 +201,15 @@ fn tables(
#[pg_extern]
fn views(
) -> impl std::iter::Iterator<Item = (name!(s_name, Option<String>),
name!(v_name, Option<String>),
name!(view_type, Option<String>),
name!(owned_by, Option<String>),
name!(rows, Option<i64>),
name!(size_pretty, Option<String>),
name!(size_bytes, Option<i64>),
name!(description, Option<String>),
name!(system_object, Option<bool>))>
name!(v_name, Option<String>),
name!(view_type, Option<String>),
name!(owned_by, Option<String>),
name!(rows, Option<i64>),
name!(size_pretty, Option<String>),
name!(size_bytes, Option<i64>),
name!(size_plus_indexes_bytes, Option<i64>),
name!(description, Option<String>),
name!(system_object, Option<bool>))>
{
let query = include_str!("sql/function_query/views-all.sql");

Expand All @@ -219,8 +224,9 @@ fn views(
row.by_ordinal(5).unwrap().value::<i64>(),
row.by_ordinal(6).unwrap().value::<String>(),
row.by_ordinal(7).unwrap().value::<i64>(),
row.by_ordinal(8).unwrap().value::<String>(),
row.by_ordinal(9).unwrap().value::<bool>()
row.by_ordinal(8).unwrap().value::<i64>(),
row.by_ordinal(9).unwrap().value::<String>(),
row.by_ordinal(10).unwrap().value::<bool>()
))
.for_each(|tuple| results.push(tuple));
Ok(Some(()))
Expand Down
3 changes: 2 additions & 1 deletion src/sql/function_query/schemas-all.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ SELECT s.s_name::TEXT,
COALESCE(f.function_count, 0::bigint)::BIGINT AS function_count,
pg_size_pretty(sum(pg_table_size(c.oid::regclass)))::TEXT AS size_pretty,
pg_size_pretty(sum(pg_total_relation_size(c.oid::regclass)))::TEXT AS size_plus_indexes,
sum(pg_table_size(c.oid::regclass))::BIGINT AS size_bytes
sum(pg_table_size(c.oid::regclass))::BIGINT AS size_bytes,
sum(pg_total_relation_size(c.oid::regclass))::BIGINT AS size_plus_indexes_bytes
FROM s
LEFT JOIN pg_class c
ON s.oid = c.relnamespace
Expand Down
2 changes: 2 additions & 0 deletions src/sql/function_query/tables-all.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ SELECT n.nspname::TEXT AS s_name,
THEN (pg_table_size(c.oid::regclass)::double precision / c.reltuples)::BIGINT
ELSE NULL::BIGINT
END AS bytes_per_row,
pg_total_relation_size(c.oid::regclass)::BIGINT AS size_plus_indexes_bytes,
pg_size_pretty(pg_total_relation_size(c.oid::regclass))::TEXT AS size_plus_indexes,

obj_description(c.oid, 'pg_class'::name)::TEXT AS description,
CASE
WHEN n.nspname !~ '^pg_toast'::text AND (n.nspname <> ALL (ARRAY['pg_catalog'::name, 'information_schema'::name])) THEN false
Expand Down
1 change: 1 addition & 0 deletions src/sql/function_query/views-all.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SELECT n.nspname::TEXT AS s_name,
c.reltuples::BIGINT AS rows,
pg_size_pretty(pg_table_size(c.oid::regclass))::TEXT AS size_pretty,
pg_table_size(c.oid::regclass)::BIGINT AS size_bytes,
pg_total_relation_size(c.oid::regclass)::BIGINT AS size_plus_indexes_bytes,
obj_description(c.oid, 'pg_class'::name)::TEXT AS description,
CASE
WHEN n.nspname !~ '^pg_toast'::text AND (n.nspname <> ALL (ARRAY['pg_catalog'::name, 'information_schema'::name]))
Expand Down