Skip to content

Commit f61d5a1

Browse files
authored
perf: optimize tables query (#542)
1 parent 3db26f4 commit f61d5a1

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

.sqlx/query-aced4382cedbfc359bb1c1ab71cf2472fa8afc0b24bf02ee1bfdfdbf111acfc8.json renamed to .sqlx/query-2b27b190ecaed2d961577fcaaf5875a1842ca09da63a7fe68996409e21e7f779.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pgt_schema_cache/src/queries/tables.sql

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ select
1111
when c.relreplident = 'f' then 'FULL'
1212
else 'NOTHING'
1313
end as "replica_identity!",
14-
pg_total_relation_size(format('%I.%I', nc.nspname, c.relname)) :: int8 as "bytes!",
15-
pg_size_pretty(
16-
pg_total_relation_size(format('%I.%I', nc.nspname, c.relname))
17-
) as "size!",
14+
relation_size:: int8 as "bytes!",
15+
pg_size_pretty(relation_size) as "size!",
1816
pg_stat_get_live_tuples(c.oid) as "live_rows_estimate!",
1917
pg_stat_get_dead_tuples(c.oid) as "dead_rows_estimate!",
2018
obj_description(c.oid) as comment
2119
from
2220
pg_namespace nc
2321
join pg_class c on nc.oid = c.relnamespace
22+
cross join lateral pg_total_relation_size(c.oid) relation_size
2423
where
2524
c.relkind in ('r', 'p', 'v', 'm')
2625
and not pg_is_other_temp_schema(nc.oid)
@@ -32,11 +31,3 @@ where
3231
)
3332
or has_any_column_privilege(c.oid, 'SELECT, INSERT, UPDATE, REFERENCES')
3433
)
35-
group by
36-
c.oid,
37-
c.relname,
38-
c.relkind,
39-
c.relrowsecurity,
40-
c.relforcerowsecurity,
41-
c.relreplident,
42-
nc.nspname;

0 commit comments

Comments
 (0)