1. Home
  2. Knowledge Base
  3. ClickHouse
  4. Handling “Too many partitions for single INSERT block”
  1. Home
  2. Knowledge Base
  3. ClickHouse DBA
  4. Handling “Too many partitions for single INSERT block”
  1. Home
  2. Knowledge Base
  3. ClickHouse Troubleshooting
  4. Handling “Too many partitions for single INSERT block”

Handling “Too many partitions for single INSERT block”

ClickHouse supports partitioning in MergeTree family of table engines. A partition is a logical/virtual set of records based on a predefined condition. The following error may be common while inserting multiple rows into a MergeTree table with a partition key.

DB::Exception: Too many partitions for single INSERT block (more than 100). The limit is controlled by 'max_partitions_per_insert_block' setting. Large number of partitions is a common misconception. It will lead to severe negative performance impact, including slow server startup, slow INSERT queries and slow SELECT queries. Recommended total number of partitions for a table is under 1000..10000. Please note, that partitioning is not intended to speed up SELECT queries (ORDER BY key is sufficient to make range queries fast). Partitions are intended for data manipulation (DROP PARTITION, etc).

The error message is pretty self explanatory. This error occurs when we perform an INSERT operation with more than 100 unique values for the partition column. Let us try reproducing this error. Create a table and Insert records with more than 100 unique partition values in it.

CREATE TABLE partition_error_example
(col1 Int32,
col2 Int32)
ENGINE MergeTree
ORDER BY col1
PARTITION BY col2;
chistadata :) ​​​​​INSERT INTO partition_error_example
              SELECT * FROM generateRandom('col1 Int32, col2 Int32', 1) 
              LIMIT 1000;

INSERT INTO partition_error_example SELECT *
FROM generateRandom('col1 Int32, col2 Int32', 1)
LIMIT 1000

Query id: a9173978-ef3a-4ac2-9066-85e534f3bd40


0 rows in set. Elapsed: 0.003 sec. 

Received exception from server (version 22.12.3):
Code: 252. DB::Exception: Received from localhost:9000. DB::Exception: Too many partitions for single INSERT block (more than
 100). The limit is controlled by 'max_partitions_per_insert_block' setting. Large number of partitions is a common 
misconception. It will lead to severe negative performance impact, including slow server startup, slow INSERT queries and slow 
SELECT queries. Recommended total number of partitions for a table is under 1000..10000. Please note, that partitioning is not 
intended to speed up SELECT queries (ORDER BY key is sufficient to make range queries fast). Partitions are intended for data 
manipulation (DROP PARTITION, etc).. (TOO_MANY_PARTS)

As described in the error message, the max_partitions_per_insert_block setting is responsible for this. This error is a proactive measure to avoid a sudden increase in server load, thereby degrading the performance. We can increase this setting value (but not too much). We have to set the value in the profile section of users.xml file.

<profiles>
    <!-- Default settings. -->
    <default>
    <max_partitions_per_insert_block>10000</max_partitions_per_insert_block>

    </default>

The above setting will increase the threshold to 10000 parts per insertion. Though these are the workarounds available, this setting should still be handled with care and may cause slowness in production servers, depending on the data and the server specs.

Was this article helpful?

Related Articles

CHISTADATA IS COMMITTED TO OPEN SOURCE SOFTWARE AND BUILDING HIGH PERFORMANCE COLUMNSTORES

In the spirit of freedom, independence and innovation. ChistaDATA Corporation is not affiliated with ClickHouse Corporation 

Need Support?

Can't find the answer you're looking for?
Contact Support

ChistaDATA Inc. Knowledge base is licensed under the Apache License, Version 2.0 (the “License”)

Copyright 2022 ChistaDATA Inc

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.