Skip to content

Commit

Permalink
Show space usage for materialized views (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima authored Feb 20, 2024
1 parent 1b5d6e1 commit 20d9ffc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/pghero/methods/space.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def relation_sizes
SELECT
n.nspname AS schema,
c.relname AS relation,
CASE WHEN c.relkind = 'r' THEN 'table' ELSE 'index' END AS type,
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'm' then 'matview' ELSE 'index' END AS type,
pg_table_size(c.oid) AS size_bytes
FROM
pg_class c
Expand All @@ -19,7 +19,7 @@ def relation_sizes
WHERE
n.nspname NOT IN ('pg_catalog', 'information_schema')
AND n.nspname !~ '^pg_toast'
AND c.relkind IN ('r', 'i')
AND c.relkind IN ('r', 'm', 'i')
ORDER BY
pg_table_size(c.oid) DESC,
2 ASC
Expand Down
2 changes: 1 addition & 1 deletion test/internal/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
t.string :name
end

create_table :users, force: true do |t|
create_table :users, force: :cascade do |t|
t.integer :city_id
t.integer :login_attempts
t.string :email
Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ class User < ActiveRecord::Base
end
User.insert_all!(users)
ActiveRecord::Base.connection.execute("ANALYZE users")
ActiveRecord::Base.connection.execute("CREATE MATERIALIZED VIEW all_users AS SELECT * FROM users")

0 comments on commit 20d9ffc

Please sign in to comment.