OPTIMIZE ... FINAL on very large partitions, keep max_bytes_to_merge_at_max_space_in_pool at its default), or change the upload settings of the disk so that upload parts can grow.
The error
The message has this form (code 318,INVALID_CONFIG_PARAMETER). The placeholders stand for the number of bytes written so far and for the effective settings:
OPTIMIZE writes its result to a disk backed by S3. A background merge that fails is retried and fails again, so the parts it was supposed to merge stay unmerged. How to find failed merges and mutations shows where to look for such failures.
Why it happens
On an S3 disk, every file of a data part is stored as a separate object. In aWide part each column has its own data file, so the largest objects are the data files of the largest columns. A file larger than max_single_part_upload_size is sent as a multipart upload, and a multipart upload may have at most max_part_number parts. The default of 10000 is the limit of AWS S3 itself.
The size of the upload parts is chosen as follows:
- The first part has the size
max_single_part_upload_size(32 MiB by default). - The following parts start at
min_upload_part_size(16 MiB by default). After everyupload_part_size_multiply_parts_count_thresholdparts (500 by default), the size is multiplied byupload_part_size_multiply_factor(2 by default), up tomax_upload_part_size(5 GiB by default). - If
strict_upload_part_sizeis set, every part has exactly that size and nothing grows.
upload_part_size_multiply_factor = 1 the same query returns 156.27 GiB, and with strict_upload_part_size the limit is max_part_number multiplied by that size, which is 156.25 GiB for 16 MiB.
So the error needs two things at once: upload settings that keep the upload parts small, and a data part with a very large column file. Background merges limit the total size of the parts they merge by max_bytes_to_merge_at_max_space_in_pool (150 GiB by default), which is roughly the largest part they can produce. Very large files come from raising that setting, or from OPTIMIZE ... FINAL, which ignores it and merges a whole partition into one part.
Find the large parts and columns
Compare the settings printed in the error message with the size of the largest column files of the table. This query lists them, with the name of your database and table in place ofdb and events:
Keep the data parts smaller
-
Do not run
OPTIMIZE TABLE ... FINALon partitions of this size. See AvoidOPTIMIZE FINAL. -
If
max_bytes_to_merge_at_max_space_in_poolwas raised for the table, return it to the default, or lower it further so that the failing merge is no longer selected: - If you do need one part per partition, choose a partitioning key that keeps partitions smaller than the limit.
Or allow larger objects
On a self-managed server, change the upload settings. For data written by merges they are taken from the configuration of the S3 disk, where each setting has the prefixs3_:
s3_strict_upload_part_size. If the storage requires parts of equal size and you use s3_strict_upload_part_size, raise it until s3_max_part_number multiplied by it is larger than your largest column file. Larger upload parts need more memory for every file that is being written, see s3_max_inflight_parts_for_one_file.
The same error can come from a query that writes one very large file to S3, for example INSERT INTO FUNCTION s3(...). There the query-level settings apply: increase s3_max_upload_part_size or s3_upload_part_size_multiply_factor, as described for s3_max_part_number.