-
Notifications
You must be signed in to change notification settings - Fork 1
/
tables.sql
40 lines (39 loc) · 1.15 KB
/
tables.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
CREATE DATABASE IF NOT EXISTS ops;
CREATE VIEW ops.tables AS
SELECT
database
, table
, partitions
, parts
, size
, marks_size
, pk_memory
, pk_memory_allocated
, rows
, engine
FROM (
SELECT
database
, table
, COUNT(DISTINCT partition) AS partitions
, COUNT() AS parts
, SUM(bytes) AS order_size
, formatReadableSize(SUM(bytes)) AS size
, formatReadableSize(SUM(marks_size)) AS marks_size
, formatReadableSize(SUM(primary_key_bytes_in_memory)) AS pk_memory
, formatReadableSize(SUM(primary_key_bytes_in_memory_allocated)) AS pk_memory_allocated
, SUM(rows) AS rows
FROM system.parts
WHERE active
GROUP BY
database, table
WITH TOTALS
ORDER BY order_size DESC
) AS P
INNER JOIN (
SELECT
database
, name AS table
, engine
FROM system.tables
) AS T USING (database, table);