Skip to content

Commit 0d0f447

Browse files
committed
add new KB article
1 parent ed806a5 commit 0d0f447

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: What if I have a problem with encodings when using Oracle via ODBC?
3+
description: "If you use Oracle as a source of ClickHouse external dictionaries via Oracle ODBC driver, you need to set the correct value for the `NLS_LANG` environment variable in `/etc/default/clickhouse`."
4+
date: 2025-07-25
5+
tags: ['Errors and Exceptions']
6+
keywords: ['OOM', 'memory limit exceeded']
7+
---
8+
9+
{frontMatter.description}
10+
{/* truncate */}
11+
12+
## Memory limit exceeded for query {#troubleshooting-out-of-memory-issues}
13+
14+
As a new user, ClickHouse can often seem like magic - every query is super fast,
15+
even on the largest datasets and most ambitious queries. Invariably though,
16+
real-world usage tests even the limits of ClickHouse. Queries exceeding memory
17+
can be the result of a number of causes. Most commonly, we see large joins or
18+
aggregations on high cardinality fields. If performance is critical, and these
19+
queries are required, we often recommend users simply scale up - something
20+
ClickHouse Cloud does automatically and effortlessly to ensure your queries
21+
remain responsive. We appreciate, however, that in self-managed scenarios,
22+
this is sometimes not trivial, and maybe optimal performance is not even required.
23+
Users, in this case, have a few options.
24+
25+
### Aggregations {#aggregations}
26+
27+
For memory-intensive aggregations or sorting scenarios, users can use the settings
28+
[`max_bytes_before_external_group_by`](/operations/settings/query-complexity/#settings-max_bytes_before_external_group_by)
29+
and [`max_bytes_before_external_sort`](/operations/settings/settings#max_bytes_ratio_before_external_sort) respectively.
30+
The former of which is discussed extensively [here](/sql-reference/statements/select/group-by/#group-by-in-external-memory).
31+
32+
In summary, this ensures any aggregations can “spill” out to disk if a memory
33+
threshold is exceeded. This will invariably impact query performance but will
34+
help ensure queries do not OOM. The latter sorting setting helps address similar
35+
issues with memory-intensive sorts. This can be particularly important in
36+
distributed environments where a coordinating node receives sorted responses
37+
from child shards. In this case, the coordinating server can be asked to sort a
38+
dataset larger than its available memory. With [`max_bytes_before_external_sort`](/sql-reference/statements/select/order-by/#implementation-details),
39+
sorting can be allowed to spill over to disk. This setting is also helpful for
40+
cases where the user has an `ORDER BY` after a `GROUP BY` with a `LIMIT`,
41+
especially in cases where the query is distributed.
42+
43+
### Joins {#joins}
44+
45+
For joins, users can select different `JOIN` algorithms, which can assist in
46+
lowering the required memory. By default, joins use the hash join, which offers
47+
the most completeness with respect to features and often the best performance.
48+
This algorithm loads the right-hand table of the `JOIN` into an in-memory hash
49+
table, against which the left-hand table is then evaluated. To minimize memory,
50+
users should thus place the smaller table on the right side. This approach still
51+
has limitations in memory-bound cases, however. In these cases, `partial_merge`
52+
join can be enabled via the [`join_algorithm`](/operations/settings/settings#settings-join_algorithm)
53+
setting. This derivative of the [sort-merge algorithm](https://en.wikipedia.org/wiki/Sort-merge_join),
54+
first sorts the right table into blocks and creates a min-max index for them.
55+
It then sorts parts of the left table by the join key and joins them over the
56+
right table. The min-max index is used to skip unneeded right table blocks.
57+
This is less memory-intensive at the expense of performance. Taking this concept
58+
further, the `full_sorting_merge` algorithm allows a `JOIN` to be performed when
59+
the right-hand side is very large and doesn't fit into memory and lookups are
60+
impossible, e.g. a complex subquery. In this case, both the right and left side
61+
are sorted on disk if they do not fit in memory, allowing large tables to be
62+
joined.
63+
64+
65+
66+
67+
68+
69+

0 commit comments

Comments
 (0)