Skip to content

Commit e57ce86

Browse files
authored
Merge pull request #160 from capgar/kbase_queries
Updates to Useful Queries pages
2 parents 09ef969 + 7840c77 commit e57ce86

4 files changed

Lines changed: 74 additions & 28 deletions

File tree

content/en/altinity-kb-useful-queries/altinity-kb-database-size-table-column-size.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ keywords:
1111

1212
### Table size
1313

14+
> Returns table size, compression rates, and row and part counts, by table
15+
1416
```sql
1517
SELECT
1618
database,
@@ -30,6 +32,8 @@ ORDER BY size DESC;
3032

3133
### Table size + inner MatView (Atomic)
3234

35+
> As above, but resolves Materialized View inner table names (for Materialized Views created using implicit inner table)
36+
3337
```sql
3438
SELECT
3539
p.database,
@@ -51,6 +55,8 @@ ORDER BY size DESC;
5155

5256
### Column size
5357

58+
> Returns size, compression rate, row counts, and average row size for each column (by db and table)
59+
5460
```sql
5561
SELECT
5662
database,
@@ -74,6 +80,8 @@ ORDER BY size DESC;
7480

7581
### Projection size
7682

83+
> Returns size, compression rate, row counts, and average row size for each projection ("name"), by db and table
84+
7785
```sql
7886
SELECT
7987
database,
@@ -95,6 +103,8 @@ ORDER BY size DESC;
95103

96104
### Projection column size
97105

106+
> Returns size, compression rate, row counts, and average row size for each projection ("name"), by db and table, and column
107+
98108
```sql
99109
SELECT
100110
database,
@@ -114,6 +124,8 @@ ORDER BY size DESC;
114124

115125
## Understanding the columns data properties:
116126

127+
> For each column in a table, unique value counts, min/max, and top 5 most frequent values
128+
117129
```sql
118130
SELECT
119131
count(),
@@ -130,6 +142,13 @@ FORMAT Vertical;
130142

131143
## Understanding the ingest pattern:
132144

145+
> For parts which are recently created and are unmerged, returns row, size, and count information by db and table.
146+
147+
- High count, low rows: lots of small parts
148+
- High countif(NOT active) relative to count(): merges are keeping up
149+
- Low countIf(NOT active) relative to count(): merges may be falling behind
150+
- uniqExact(partition): how many partitions are being written to
151+
133152
```sql
134153
SELECT
135154
database,
@@ -154,6 +173,8 @@ ORDER BY count() DESC
154173

155174
## part_log
156175

176+
> For the past day, returns per-second part lifecycle metrics over 30 minute buckets
177+
157178
```sql
158179
WITH 30 * 60 AS frame_size
159180
SELECT
@@ -176,7 +197,11 @@ ORDER BY
176197
database ASC,
177198
table ASC,
178199
m ASC
179-
200+
```
201+
202+
> For the past day, returns per-second insert throughput metrics, by db and table, over 30 minute buckets
203+
204+
```sql
180205
WITH 30 * 60 AS frame_size
181206
SELECT
182207
toStartOfInterval(event_time, toIntervalSecond(frame_size)) AS m,
@@ -200,6 +225,8 @@ ORDER BY
200225

201226
## Understanding the partitioning
202227

228+
> Partition distribution analysis, aggregating system.parts metrics by partition. The quantiles results can indicate whether there is skewed distribution of data between partitions.
229+
203230
```sql
204231
SELECT
205232
database,
@@ -235,6 +262,8 @@ FORMAT Vertical
235262

236263
## Subcolumns sizes
237264

265+
Returns column-level storage metricsk, including subcolumns (JSON, tuples, maps, etc - if present)
266+
238267
```sql
239268
WITH
240269
if(
@@ -259,7 +288,7 @@ SELECT
259288
sum(rows) AS rows_cnt,
260289
round(usize / rows_cnt, 2) AS avg_row_size
261290
FROM system.parts_columns
262-
WHERE (active = 1) AND (database LIKE '%') AND (`table` LIKE '%)
291+
WHERE (active = 1) AND (database LIKE '%') AND (`table` LIKE '%')
263292
GROUP BY
264293
table_,
265294
colunm_,

content/en/altinity-kb-useful-queries/compare_query_log_for_2_intervals.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ title: "Compare query_log for 2 intervals"
33
linkTitle: "Compare query_log for 2 intervals"
44
weight: 100
55
description: >-
6+
Compare query performance across different time periods
67
---
7-
8+
> Looks at unique query shapes (by normalized_query_hash) which occurred within two different time intervals ("before" and "after"), and returns performance metrics for each query pattern which performed worse in the "after" interval.
89
```
910
WITH
1011
toStartOfInterval(event_time, INTERVAL 5 MINUTE) = '2023-06-30 13:00:00' as before,
@@ -67,7 +68,7 @@ LIMIT 10
6768
FORMAT Vertical
6869
```
6970

70-
71+
> Looks at the system.query_log in a window (in this case, 3 days) prior to and following a specified timestamp of interest. Returns performance metrics for each query pattern which performed worse after that timestamp.
7172
```
7273
WITH
7374
toDateTime('2024-02-09 00:00:00') as timestamp_of_issue,

content/en/altinity-kb-useful-queries/ingestion-rate-part_log.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ description: >-
77
---
88

99
## Insert rate
10+
11+
> Returns aggregated insert metrics, per table, for the current day (by default), including parts per insert, rows/bytes per insert, and rows/bytes per part.
12+
1013
```sql
1114
select database, table, time_bucket,
1215
max(number_of_parts_per_insert) max_parts_pi,
@@ -55,6 +58,9 @@ ORDER BY time_bucket, database, table ASC
5558
```
5659

5760
## New parts per partition
61+
62+
> Returns new part counts and average rows per table for the current day (by default)
63+
5864
```sql
5965
select database, table, event_type, partition_id, count() c, round(avg(rows))
6066
from system.part_log where event_date >= today() and event_type = 'NewPart'
@@ -64,7 +70,9 @@ order by c desc
6470

6571
## Too fast inserts
6672

67-
It should not be more often than 1 new part per table per second (60 inserts per minute)
73+
> Returns new part counts and average rows by minute by table
74+
75+
Should not be more often than 1 new part per table per second (60 inserts per minute)
6876
One insert can create several parts because of partitioning and materialized views attached.
6977

7078
```sql

content/en/altinity-kb-useful-queries/table-meta-in-zookeeper.md

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,44 @@ description: >-
88

99
## Compare table metadata of different replicas in zookeeper
1010

11-
> Metadata on replica is not up to date with common metadata in Zookeeper
11+
> Check if a table is consistent across all zookeeper replicas. From each replica, returns metdadata, columns, and is_active nodes. Checks whether each replica's value matches the previous replica's value, and flags any mismatches (looks_good = 0).
1212
1313
```sql
14-
SELECT *, if( neighbor(name, -1) == name and name != 'is_active', neighbor(value, -1) == value , 1) as looks_good
15-
FROM (
1614
SELECT
17-
name,
18-
path,
19-
ctime,
20-
mtime,
21-
value
22-
FROM system.zookeeper
23-
WHERE (path IN (
24-
SELECT arrayJoin(groupUniqArray(if(path LIKE '%/replicas', concat(path, '/', name), path)))
15+
*,
16+
if(
17+
prev_name = name AND name != 'is_active',
18+
prev_value = value,
19+
1
20+
) AS looks_good
21+
FROM (
22+
SELECT
23+
name,
24+
path,
25+
ctime,
26+
mtime,
27+
value,
28+
lagInFrame(name) OVER w AS prev_name,
29+
lagInFrame(value) OVER w AS prev_value
2530
FROM system.zookeeper
26-
WHERE path IN (
27-
SELECT arrayJoin([zookeeper_path, concat(zookeeper_path, '/replicas')])
28-
FROM system.replicas
29-
WHERE table = 'test_repl'
30-
)
31-
)) AND (name IN ('metadata', 'columns', 'is_active'))
32-
ORDER BY
33-
name = 'is_active',
34-
name ASC,
35-
path ASC
31+
WHERE (path IN (
32+
SELECT arrayJoin(groupUniqArray(if(path LIKE '%/replicas', concat(path, '/', name), path)))
33+
FROM system.zookeeper
34+
WHERE path IN (
35+
SELECT arrayJoin([zookeeper_path, concat(zookeeper_path, '/replicas')])
36+
FROM system.replicas
37+
WHERE table = 'test_repl'
38+
)
39+
)) AND (name IN ('metadata', 'columns', 'is_active'))
40+
WINDOW w AS (ORDER BY name = 'is_active', name ASC, path ASC
41+
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
3642
)
3743
```
3844

39-
vs.
45+
> Returns a table's create_table_query, and the last time the table's metadata was modified
4046
4147
```sql
42-
SELECT metadata_modification_time, create_table_query FROM system.tables WHERE name = 'test_repl'
48+
SELECT metadata_modification_time, create_table_query
49+
FROM system.tables
50+
WHERE name = 'test_repl'
4351
```

0 commit comments

Comments
 (0)