> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Query and schema recommendations

> Deterministic recommendations ClickHouse Cloud shows from your query logs and table schemas.

Private preview

ClickHouse Cloud examines your query traffic and table schemas, generating recommendations for performance improvement. The tests are deterministic, without usage of LLMs, and they do not execute on your services.

Recommendations are one of two kinds:

* Schema recommendations appear on **Monitoring** > **Tables** and are related to changes you can make to your table schemas.
* Query recommendations appear on **Monitoring** > **Query performance**, when you open a query, and are related to changes you can make to your queries.
  It's possible that some schema and query recommendations overlap, giving you different ways to resolve either via your query pattern or your table schema.

> [!WARNING]
>
> Recommendations are in preview. They may change, and they are not covered by the standard ClickHouse Cloud SLA.

## Schema recommendations

These appear on the table in [Monitoring](https://clickhouse.com/docs/products/cloud/features/monitoring/cloud-console.md).

| Recommendation | When it appears | What to do |
| - | - | - |
| Change the sorting key | Many queries filter on the same columns, and those columns are not in the sorting key. | Consider changing the sorting key so the usual filters match the key. This rebuilds the table. [Schema Advisor](https://clickhouse.com/docs/products/cloud/features/ai-ml/schema-advisor.md) can plan and deploy this change. |
| Add a projection | A lot of queries filter a small set of columns that sit outside the sorting key. | Add a [projection](https://clickhouse.com/docs/data-modeling/projections.md) on those columns. This speeds those queries without changing the sorting key. [Schema Advisor](https://clickhouse.com/docs/products/cloud/features/ai-ml/schema-advisor.md) applies this in place with `ALTER TABLE`, with no rebuild and no `EXCHANGE TABLES`. |
| Use a dictionary | Most queries against the table are single-row lookups. | For a dimension table that is read often and updated rarely, consider a [dictionary](https://clickhouse.com/docs/sql-reference/statements/create/dictionary.md). |
| Batch inserts | The table receives many small inserts, and those inserts create many small parts. | Batch inserts so each part is larger. Fewer parts means less merge work. See [asynchronous inserts](https://clickhouse.com/docs/optimize/asynchronous-inserts.md). |

## Query recommendations

These appear when you open a normalized query on **Monitoring** > **Query performance**. That page is the next version of [Query insights](https://clickhouse.com/docs/products/cloud/features/sql-console-features/query-insights.md): you can filter queries by table and open one query for its metrics. Applying a query recommendation means changing the query. Schema Advisor does not deploy these.

| Recommendation | When it appears | What to do |
| - | - | - |
| Use `uniq` | The query uses `COUNT(DISTINCT ...)` or [`uniqExact`](https://clickhouse.com/docs/sql-reference/aggregate-functions/reference/uniqexact), and an approximate count would do. | Use [`uniq`](https://clickhouse.com/docs/sql-reference/aggregate-functions/reference/uniq) for large distinct counts. It uses less memory. |
| Store JSON natively | The query parses JSON out of a string column while the query runs. | Store the value as a [JSON](https://clickhouse.com/docs/sql-reference/data-types/newjson.md) column, or as ordinary columns, instead of parsing a string on every query. |
| List the columns you need | The query uses `SELECT *` or `alias.*` on a wide table. | Name the columns you need so ClickHouse does not read the rest. |
| Avoid routine `OPTIMIZE ... FINAL` | The query runs [`OPTIMIZE`](https://clickhouse.com/docs/sql-reference/statements/optimize) with `FINAL`, which rewrites the table. | Do not run `OPTIMIZE ... FINAL` as a regular step. It is heavy on I/O and CPU, and it can block inserts. |
| Use a sort-merge join | Both sides of a `JOIN` are already sorted by the join keys. | Set [`join_algorithm`](https://clickhouse.com/docs/reference/settings/session-settings/join#join_algorithm) to `full_sorting_merge` so ClickHouse does not sort the inputs again. |
| Filter on the leading sorting-key columns | The query's filters skip the leading columns of the sorting key. ClickHouse can still prune granules from later key columns, and that pruning can be weaker. See [filtering on secondary key columns](https://clickhouse.com/docs/guides/clickhouse/data-modelling/sparse-primary-indexes.md#efficient-filtering-on-secondary-key-columns). | Check the plan with `EXPLAIN indexes = 1`. Add a leading-key filter only when the query result stays the same. |
| Allow asynchronous inserts | An `INSERT` turns asynchronous inserts off and creates many small parts. | Leave [asynchronous inserts](https://clickhouse.com/docs/optimize/asynchronous-inserts.md) enabled, or batch the inserts in the client, so small writes are combined. |

## Related pages

* [Schema Advisor](https://clickhouse.com/docs/products/cloud/features/ai-ml/schema-advisor.md)
* [Monitoring in the Cloud console](https://clickhouse.com/docs/products/cloud/features/monitoring/cloud-console.md)
* [Query insights](https://clickhouse.com/docs/products/cloud/features/sql-console-features/query-insights.md)
* [Schema design](https://clickhouse.com/docs/data-modeling/schema-design.md)
