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

store: Add a materialized view 'info.chain_sizes' #4318

Merged
merged 1 commit into from
Jan 25, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- This file should undo anything in `up.sql`

drop view if exists info.all_sizes;

create view info.all_sizes as
select * from info.subgraph_sizes
union all
select * from info.table_sizes;

drop materialized view if exists info.chain_sizes;
34 changes: 34 additions & 0 deletions store/postgres/migrations/2023-01-24-192319_chain_size_view/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

drop materialized view if exists info.chain_sizes;

create materialized view info.chain_sizes as
select *,
pg_size_pretty(total_bytes) as total,
pg_size_pretty(index_bytes) as index,
pg_size_pretty(toast_bytes) as toast,
pg_size_pretty(table_bytes) as table
from (
select *,
total_bytes-index_bytes-coalesce(toast_bytes,0) AS table_bytes
from (
select nspname as table_schema, relname as table_name,
'shared'::text as version,
c.reltuples as row_estimate,
pg_total_relation_size(c.oid) as total_bytes,
pg_indexes_size(c.oid) as index_bytes,
pg_total_relation_size(reltoastrelid) as toast_bytes
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where relkind = 'r'
and nspname like 'chain%'
) a
) a with no data;

drop view if exists info.all_sizes;

create view info.all_sizes as
select * from info.subgraph_sizes
union all
select * from info.chain_sizes
union all
select * from info.table_sizes;