ClickhouseQuery Performance

Query Performance Monitoring

UptimeDock provides comprehensive query performance monitoring for your ClickHouse databases. Track execution times, identify slow queries, and analyze resource consumption to optimize your database performance.

Overview

The Query Performance dashboard is divided into two main sections:

  • Query Profile – Aggregated view of all queries with execution statistics
  • Slow Queries – Individual slow query instances for detailed analysis

Both views help you understand how your queries are performing and identify opportunities for optimization.

Query Profile

The Query Profile tab shows an aggregated view of queries executed on your ClickHouse database. Queries are grouped by their normalized form (query hash), allowing you to see patterns and identify frequently executed or resource-intensive queries.

Understanding the Columns

ColumnDescription
QueryThe SQL query text (truncated for display). Click the eye icon to view full query details.
DatabaseThe database where the query was executed.
ExecutionsTotal number of times this query pattern has been executed.
Avg DurationAverage execution time across all executions of this query.
Avg Read RowsAverage number of rows read per execution.
Avg Write RowsAverage number of rows written per execution (for INSERT/UPDATE operations).
Search & Filter

Use the search box to filter queries by text. Click "Show Settings" to access additional filtering options like date range and query type.

Query Details

Click on any query row to open the Query Details modal. This provides deeper insights into the query's performance characteristics:

MetricDescription
DatabaseThe target database for this query.
Executed ByThe ClickHouse user who executed the query.
ExecutionsTotal execution count with query type indicator (Select/Insert).
CPU Time (Avg)Average CPU time consumed per execution.
Memory Usage (Avg)Average memory consumed per execution.
Full QueryComplete SQL query text with syntax highlighting.

The Query Details modal also includes tabs for:

  • Duration – Execution time distribution and trends
  • Read – Read operation statistics
  • Write – Write operation statistics

Slow Queries

The Slow Queries tab shows individual query executions that exceeded the slow query threshold. Unlike Query Profile which aggregates similar queries, this view shows each slow execution separately, helping you identify specific problematic instances.

ColumnDescription
QueryThe SQL query text that was slow.
DatabaseThe database where the query ran.
DurationHow long this specific execution took.
Execution TimeWhen the query was executed (timestamp).
Slow Query Threshold

By default, queries exceeding 10ms are considered slow. You can adjust this threshold in your check settings based on your performance requirements.

Slow Query Details

Click on a slow query to view detailed execution information:

FieldDescription
Full QueryComplete SQL with syntax highlighting for easy reading.
Initial Query IdUnique identifier for this query execution in ClickHouse.
Query HashHash of the normalized query (links similar queries together).
DatabaseTarget database.
UserClickHouse user who ran the query.
User AgentClient application that submitted the query.
Execution TimeExact timestamp when the query was executed.
Affected TablesTables accessed by this query (e.g., system.parts).
DurationTotal execution time.
Memory UsagePeak memory consumed during execution.
CPU TimeCPU time consumed by this query.

The Slow Query Details modal includes additional tabs:

  • Read – Rows and bytes read during execution
  • Write – Rows and bytes written (for mutations)
  • Query Profile – Link to the aggregated query profile
  • Alerts – Any alerts triggered by this query

Analyzing Slow Queries

When investigating a slow query, consider these factors:

  1. Check the affected tables – Large tables without proper indexing can cause slow queries
  2. Review the query structure – Look for missing WHERE clauses or inefficient JOINs
  3. Compare memory and CPU usage – High memory usage may indicate full table scans
  4. Check execution time patterns – Is this query always slow or only sometimes?
-- Example: Identify tables with many parts (can slow down queries)
SELECT 
    database,
    table,
    count() AS part_count,
    formatReadableSize(sum(bytes_on_disk)) AS total_size
FROM system.parts
WHERE active = 1
GROUP BY database, table
HAVING part_count >= 100
ORDER BY part_count DESC

Key Metrics Explained

Understanding these metrics helps you identify performance issues:

MetricWhat It MeasuresWarning Signs
DurationWall clock time from query start to completionQueries > 1 second should be investigated
CPU TimeActual CPU processing timeHigh CPU with low duration = efficient; Low CPU with high duration = I/O bound
Memory UsagePeak memory during executionQueries approaching max_memory_usage limits
Read RowsNumber of rows scannedHigh read rows with few results = missing indexes
ExecutionsHow often a query runsHigh-frequency queries should be highly optimized

Best Practices

Follow these best practices to maintain optimal query performance:

Optimization Tips
  • Use LIMIT clauses when you don't need all results
  • Filter by partition key columns in WHERE clauses
  • Avoid SELECT * – only select columns you need
  • Use materialized views for frequently aggregated data
  • Monitor queries with high execution counts first

Regular monitoring checklist:

  1. Review the Slow Queries tab daily for new issues
  2. Check Query Profile weekly for patterns in high-frequency queries
  3. Investigate any query with avg duration > 100ms
  4. Monitor memory usage trends to prevent OOM errors
  5. Set up alerts for queries exceeding your thresholds

Troubleshooting

Common query performance issues and solutions:

IssuePossible CauseSolution
High read rows, low result countMissing or ineffective indexAdd appropriate primary key or index
High memory usageLarge GROUP BY or ORDER BYUse max_memory_usage setting, optimize query
Slow INSERT queriesToo many small insertsBatch inserts together, use async inserts
Queries timing outResource contentionCheck concurrent query count, optimize heavy queries
Inconsistent query timesBackground merges or mutationsMonitor system.merges, schedule heavy operations
Need More Help?

For advanced optimization techniques, see our Memory & Resources guide or contact support for personalized assistance.