altinity-expert-clickhouse-reporting
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseQuery Performance Analysis
查询性能分析
Diagnose SELECT query performance issues, analyze query patterns, and identify optimization opportunities.
诊断SELECT查询性能问题,分析查询模式并寻找优化机会。
Diagnostics
诊断
Run all queries from the file checks.sql and analyze the results.
运行checks.sql文件中的所有查询并分析结果。
Query Optimization Hints
查询优化提示
Index Usage Check
索引使用情况检查
sql
-- Check if data skipping indices exist
select
database,
table,
name as index_name,
type,
expr,
granularity
from system.data_skipping_indices
where database = '{database}' and table = '{table}'sql
-- Check if data skipping indices exist
select
database,
table,
name as index_name,
type,
expr,
granularity
from system.data_skipping_indices
where database = '{database}' and table = '{table}'Mark Count for Query
查询的标记数统计
For a specific slow query, check how many marks (granules) were read:
sql
select
query_id,
read_rows,
selected_marks,
selected_parts,
formatReadableSize(read_bytes) as read_bytes,
round(read_rows / nullIf(selected_marks, 0)) as rows_per_mark
from system.query_log
where query_id = '{query_id}'
and type = 'QueryFinish'High relative to result = index not selective enough.
selected_marks针对特定慢查询,检查读取了多少个标记(颗粒):
sql
select
query_id,
read_rows,
selected_marks,
selected_parts,
formatReadableSize(read_bytes) as read_bytes,
round(read_rows / nullIf(selected_marks, 0)) as rows_per_mark
from system.query_log
where query_id = '{query_id}'
and type = 'QueryFinish'selected_marksAd-Hoc Query Guidelines
临时查询指南
Required Safeguards
必要的防护措施
sql
-- Always time-bound
where event_date >= today() - 1
-- or
where event_time > now() - interval 1 hour
-- Always limit
limit 100
-- Filter by type
where type = 'QueryFinish' -- completed
where type like 'Exception%' -- failedsql
-- Always time-bound
where event_date >= today() - 1
-- or
where event_time > now() - interval 1 hour
-- Always limit
limit 100
-- Filter by type
where type = 'QueryFinish' -- completed
where type like 'Exception%' -- failedUseful Filters
实用筛选条件
sql
-- By user
where user = 'analytics_user'
-- By query pattern
where query ilike '%SELECT%FROM my_table%'
-- By duration threshold
where query_duration_ms > 10000 -- > 10 seconds
-- By normalized hash (for specific query pattern)
where normalized_query_hash = 1234567890sql
-- By user
where user = 'analytics_user'
-- By query pattern
where query ilike '%SELECT%FROM my_table%'
-- By duration threshold
where query_duration_ms > 10000 -- > 10 seconds
-- By normalized hash (for specific query pattern)
where normalized_query_hash = 1234567890Cross-Module Triggers
跨模块触发器
| Finding | Load Module | Reason |
|---|---|---|
| High memory queries | | Memory limits/optimization |
| Reading too many parts | | Part consolidation |
| Poor index selectivity | | Index/ORDER BY design |
| Cache misses | | Cache sizing |
| MV slow | | MV optimization |
| 发现问题 | 加载模块 | 原因 |
|---|---|---|
| 高内存占用查询 | | 内存限制/优化 |
| 读取过多数据分片 | | 分片合并 |
| 索引选择性差 | | 索引/ORDER BY设计 |
| 缓存未命中 | | 缓存大小配置 |
| 物化视图(MV)运行缓慢 | | 物化视图优化 |
Settings Reference
设置参考
| Setting | Scope | Notes |
|---|---|---|
| Query | Query timeout |
| Query | Limit rows scanned |
| Query | Limit bytes scanned |
| Query | Parallelism |
| Query | Enable query result caching |
| Server | Enable query logging |
| Server | Log threshold |
| 设置项 | 作用范围 | 说明 |
|---|---|---|
| 查询 | 查询超时时间 |
| 查询 | 限制扫描行数 |
| 查询 | 限制扫描字节数 |
| 查询 | 并行度 |
| 查询 | 启用查询结果缓存 |
| 服务器 | 启用查询日志 |
| 服务器 | 日志记录阈值 |