-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
store: Add a materialized view 'info.chain_sizes'
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
store/postgres/migrations/2023-01-24-192319_chain_size_view/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
34
store/postgres/migrations/2023-01-24-192319_chain_size_view/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |