> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-postgresql-tls-support.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Visualize system.query_log data to simplify query debugging and performance optimization

# Query insights

export const Image = ({img, alt, size = "lg"}) => {
  const normalizedSize = ["sm", "md", "lg"].includes(size) ? size : "lg";
  return <div className={`ch-image-${normalizedSize}`}>
      <Frame>
        <img src={img} alt={alt} />
      </Frame>
    </div>;
};

The **Query Insights** feature makes ClickHouse's built-in query log easier to use through visualizations and tables. ClickHouse's `system.query_log` table is a key source of information for query optimization, debugging, and monitoring overall cluster health and performance.

<h2 id="query-overview">
  Query overview
</h2>

After selecting a service, the **Monitoring** navigation item in the left sidebar should expand to reveal a new **Query insights** sub-item. Clicking on this option opens the new Query insights page:

<Image img="https://mintcdn.com/private-7c7dfe99-postgresql-tls-support/mXojvHhEhDtRJeuO/images/cloud/sqlconsole/insights_overview.webp?fit=max&auto=format&n=mXojvHhEhDtRJeuO&q=85&s=5ad333135c292bb8822f8880f29e6350" size="md" alt="Query Insights UI Overview" border width="1712" height="790" data-path="images/cloud/sqlconsole/insights_overview.webp" />

<h2 id="top-level-metrics">
  Top-level metrics
</h2>

The stat boxes at the top represent some basic top-level query metrics over the selected period of time. Beneath it, we've exposed three time-series charts representing query volume, latency, and error rate broken down by query kind (select, insert, other) over a selected time window. The latency chart can be further adjusted to display p50, p90, and p99 latencies:

<Image img="https://mintcdn.com/private-7c7dfe99-postgresql-tls-support/mXojvHhEhDtRJeuO/images/cloud/sqlconsole/insights_latency.webp?fit=max&auto=format&n=mXojvHhEhDtRJeuO&q=85&s=e19d821ee9fb8b5d2942749a9a98bb4a" size="md" alt="Query Insights UI Latency Chart" border width="1456" height="384" data-path="images/cloud/sqlconsole/insights_latency.webp" />

<h2 id="recent-queries">
  Recent queries
</h2>

Beneath the top-level metrics, a table displays query log entries (grouped by normalized query hash and user) over the selected time window:

<Image img="https://mintcdn.com/private-7c7dfe99-postgresql-tls-support/mXojvHhEhDtRJeuO/images/cloud/sqlconsole/insights_recent.webp?fit=max&auto=format&n=mXojvHhEhDtRJeuO&q=85&s=8ec5893fa42a7e4bc3818186ea7b0ac4" size="md" alt="Query Insights UI Recent Queries Table" border width="1625" height="736" data-path="images/cloud/sqlconsole/insights_recent.webp" />

Recent queries can be filtered and sorted by any available field. The table can also be configured to display or hide additional fields such as tables, p90, and p99 latencies.

<h2 id="query-drill-down">
  Query drill-down
</h2>

Selecting a query from the recent queries table will open a flyout containing metrics and information specific to the selected query:

<Image img="https://mintcdn.com/private-7c7dfe99-postgresql-tls-support/mXojvHhEhDtRJeuO/images/cloud/sqlconsole/insights_drilldown.webp?fit=max&auto=format&n=mXojvHhEhDtRJeuO&q=85&s=e4e66dacb9e71cc20ad629dc1554fa30" size="md" alt="Query Insights UI Query Drill down" border width="1889" height="963" data-path="images/cloud/sqlconsole/insights_drilldown.webp" />

As we can see from the flyout, this particular query has been run more than 3000 times in the last 24 hours. All metrics in the **Query info** tab are aggregated metrics, but we can also view metrics from individual runs by selecting the **Query history** tab:

<Image img="https://mintcdn.com/private-7c7dfe99-postgresql-tls-support/mXojvHhEhDtRJeuO/images/cloud/sqlconsole/insights_query_info.webp?fit=max&auto=format&n=mXojvHhEhDtRJeuO&q=85&s=82690f45d91dd46269db6e29ed07a63c" size="sm" alt="Query Insights UI Query Information" border width="591" height="961" data-path="images/cloud/sqlconsole/insights_query_info.webp" />

<br />

From this pane, the `Settings` and `Profile Events` items for each query run can be expanded to reveal additional information.
