diff --git a/SQL-for-analyzing-Synapse-PostgreSQL-database-stats.md b/SQL-for-analyzing-Synapse-PostgreSQL-database-stats.md index 7528a4d..7e48e36 100644 --- a/SQL-for-analyzing-Synapse-PostgreSQL-database-stats.md +++ b/SQL-for-analyzing-Synapse-PostgreSQL-database-stats.md @@ -8,15 +8,6 @@ pg_size_pretty (1 row) ``` ## Show top 20 larger rooms by state events count -this is old and not working -``` -SELECT r.name, s.room_id, s.state_events - FROM room_stats s - LEFT JOIN room_names r USING (room_id) - ORDER BY ts DESC, state_events DESC - LIMIT 20; -``` -maybe, in 2020-4-14 this is: ``` SELECT r.name, s.room_id, s.current_state_events FROM room_stats_current s @@ -25,7 +16,15 @@ SELECT r.name, s.room_id, s.current_state_events LIMIT 20; ``` -and by state_group_events count _(join removed for performance reasons)_: +and by state_group_events count: +``` +SELECT 's.room_id', count('s.room_id') cnt, 'rs.name' FROM state_groups_state s +LEFT JOIN room_stats_current rs USING (room_id) +GROUP BY s.room_id +ORDER BY count(s.room_id) DESC +LIMIT 20; +``` +plus same, but with join removed for performance reasons: ``` SELECT s.room_id, count(s.room_id) FROM state_groups_state s GROUP BY s.room_id