Error Code 396: TOO_MANY_ROWS_OR_BYTES
This error occurs when query results exceed limits set by max_result_rows or max_result_bytes settings.
It's a safety mechanism to prevent queries from consuming excessive memory or network bandwidth when returning large result sets.
Error Message Format:
or
When you'll see it
-
Large query results:
- When a
SELECTquery returns more rows thanmax_result_rows(default: unlimited in self-hosted, varies in ClickHouse Cloud) - When result size exceeds
max_result_byteslimit
- When a
-
LowCardinality columns:
- With
LowCardinalitycolumns, even small row counts can trigger this error - LowCardinality dictionaries add significant overhead to result size
- A query returning 209 rows can exceed 10MB due to dictionary metadata
- With
-
HTTP interface queries:
- Particularly common when using SQL Console or HTTP clients
- ClickHouse Cloud SQL Console sets
result_overflow_mode=breakby default
-
Settings profiles:
- When organization/user settings profiles enforce restrictive result limits
- Default limits may be set at the profile level for resource control
Potential causes
-
Queries returning too many rows - The query legitimately returns more data than allowed by
max_result_rows -
LowCardinality overhead - Using
LowCardinalitycolumns with small fixed-size types causes dictionary metadata to inflate result size unexpectedly -
Restrictive profile settings - Settings profiles (in ClickHouse Cloud or user profiles) enforce low limits like:
-
Query cache incompatibility - Since ClickHouse 24.9+, using
use_query_cache = truewithresult_overflow_mode != 'throw'triggers error 731, but older configurations may still hit error 396 -
Missing ORDER BY optimization - Queries without
ORDER BYmay hit the limit, while addingORDER BYallows the query to succeed (query execution differences)
Quick fixes
1. Increase result limits:
2. Use result_overflow_mode = 'break' to get partial results:
In ClickHouse 24.9+, result_overflow_mode = 'break' is incompatible with query cache
3. Optimize LowCardinality usage:
4. Use pagination with LIMIT/OFFSET:
5. Modify settings profile (ClickHouse Cloud):
6. For HTTP/JDBC clients - pass settings in connection:
Important notes
-
Cloud SQL Console behavior: ClickHouse Cloud SQL Console automatically sets
result_overflow_mode=breakandmax_result_rows=500000in HTTP query parameters -
LowCardinality overhead: When using
LowCardinality, dictionary metadata is sent with each data block, which can cause unexpected size bloat:- 209 rows × 1 column can exceed 10MB limit
- 110 rows can require 979MB due to dictionary overhead
- Solution: Remove
LowCardinalityor increasemax_result_bytes
-
Setting precedence: Settings passed in query parameters override profile settings, but profile settings apply if not explicitly overridden
-
result_overflow_modebehavior:'throw'(default): Throws exception when limit exceeded'break': Returns partial results (incompatible with query cache in 24.9+)- Using
'break'provides no indication that results were truncated
-
Version compatibility: The query cache + overflow mode restriction was introduced in ClickHouse 24.9.