You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/altinity-kb-useful-queries/altinity-kb-database-size-table-column-size.md
+3-4Lines changed: 3 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: "Database Size - Table - Column size"
3
3
linkTitle: "Database Size - Table - Column size"
4
4
description: >
5
-
Database Size - Table - Column size
5
+
Queries to analyze size and compression rates across tables and columns
6
6
keywords:
7
7
- clickhouse database size
8
8
- clickhouse table size
@@ -52,7 +52,6 @@ ORDER BY size DESC;
52
52
```
53
53
54
54
55
-
56
55
### Column size
57
56
58
57
> Returns size, compression rate, row counts, and average row size for each column (by db and table)
@@ -223,7 +222,7 @@ ORDER BY
223
222
```
224
223
225
224
226
-
## Understanding the partitioning
225
+
## Understanding partitioning
227
226
228
227
> Partition distribution analysis, aggregating system.parts metrics by partition. The quantiles results can indicate whether there is skewed distribution of data between partitions.
229
228
@@ -262,7 +261,7 @@ FORMAT Vertical
262
261
263
262
## Subcolumns sizes
264
263
265
-
Returns column-level storage metricsk, including subcolumns (JSON, tuples, maps, etc - if present)
264
+
> Returns column-level storage metrics, including subcolumns (JSON, tuples, maps, etc - if present)
formatReadableSize(sum(written_bytes)) AS WrittenBytes,
91
+
sum(result_rows) AS ResultRows,
92
+
formatReadableSize(sum(result_bytes)) AS ResultBytes
93
+
FROMsystem.query_log
94
+
WHERE (event_date >= today()) AND (event_time > (now() -3600)) AND type in (2,4) -- QueryFinish, ExceptionWhileProcessing
95
+
GROUP BY normalized_query_hash
96
+
WITH TOTALS
97
+
ORDER BY UserTime DESC
98
+
LIMIT30
99
+
FORMAT Vertical
100
+
```
101
+
98
102
## A/B tests of the same query
103
+
104
+
> Runs cluster-wide, returns a side-by-side comparison of performance metrics, ordered by relative difference
99
105
```
100
106
WITH
101
107
query_id='8c050082-428e-4523-847a-caf29511d6ba' AS first,
@@ -118,11 +124,11 @@ ORDER BY
118
124
metric ASC
119
125
```
120
126
121
-
Another variant
127
+
> Compares two queries run on the same host in the past day, returning the metrics highlighting the most significant performance differences between the faster and slower query
122
128
```
123
129
WITH
124
-
toUUID('d18fb820-4075-49bf-8fa3-cd7e53b9d523') AS fast_query_id,
125
-
toUUID('22ffbcc0-c62a-4895-8105-ee9d7447a643') AS slow_query_id,
130
+
'd18fb820-4075-49bf-8fa3-cd7e53b9d523' AS fast_query_id,
131
+
'22ffbcc0-c62a-4895-8105-ee9d7447a643' AS slow_query_id,
126
132
faster AS
127
133
(
128
134
SELECT pe.1 AS event_name, pe.2 AS event_value
@@ -157,28 +163,33 @@ ORDER BY event_name ASC
157
163
SETTINGS join_use_nulls = 1
158
164
```
159
165
160
-
## Find queries that were started but not finished at some moment in time
161
166
167
+
## Queries which did not complete within specified timeframe
168
+
> For a given time range, returns queries which either did not complete, or did not complete within a configurable timeframe (100 seconds)
162
169
```sql
163
170
SELECT
164
171
query_id,
165
172
min(event_time) t,
166
173
any(query)
167
174
FROMsystem.query_log
168
-
where event_date = today() and event_time >'2021-11-25 02:29:12'
175
+
WHERE event_date = today() AND event_time >'2021-11-25 02:29:12'
169
176
GROUP BY query_id
170
177
HAVING countIf(type='QueryFinish') =0ORsum(query_duration_ms) >100000
171
-
order by t;
178
+
ORDER BY t;
179
+
```
172
180
173
-
select
181
+
> Returns queries which started within a specified timeframe but did not complete successfully (still running, crashed, threw exception)
182
+
```sql
183
+
SELECT
174
184
query_id,
175
185
any(query)
176
-
fromsystem.query_log
177
-
where event_time between'2021-09-24 07:00:00'and'2021-09-24 09:00:00'
178
-
group by query_id HAVING countIf(type=1) <> countIf(type!=1)
186
+
FROMsystem.query_log
187
+
WHERE event_time BETWEEN'2021-09-24 07:00:00'AND'2021-09-24 09:00:00'
188
+
GROUP BY query_id HAVING countIf(type=1) <> countIf(type!=1)
179
189
```
180
190
181
191
## Columns used in WHERE clauses
192
+
> Returns a list of columns which are used as filters against a table. Replace %target_table% with the actual table name (or pattern) you want to inspect.
182
193
```
183
194
WITH
184
195
any(query) AS q,
@@ -197,9 +208,9 @@ WHERE (event_time >= (now() - toIntervalDay(1)))
197
208
GROUP BY c2
198
209
ORDER BY count() ASC;
199
210
```
200
-
Replace %target_table% with the actual table name (or pattern) you want to inspect.
201
211
202
212
## Most‑selected columns
213
+
> Over the past week, which columns have been accessed the most frequently in SELECT queries
203
214
204
215
```
205
216
SELECT
@@ -217,6 +228,7 @@ LIMIT 50;
217
228
```
218
229
219
230
## Most‑used functions
231
+
> Over the past week, which functions have been used the most
220
232
221
233
```
222
234
SELECT
@@ -232,9 +244,10 @@ ORDER BY hits DESC
232
244
LIMIT 50;
233
245
```
234
246
235
-
## query ranks
236
-
```
247
+
## "Worst offender" query ranks
248
+
> Over a specified time range, returns the query shapes which appear to be the worst performing based on a range of ranked criteria
0 commit comments