max_streams_for_files_processing_in_cluster_functions
If is not zero, limit the number of threads reading data from files in *Cluster table functions.max_streams_for_merge_tree_reading
If is not zero, limit the number of reading streams for MergeTree table.max_streams_for_union_step
Limits the number of simultaneously active data streams in aUNION step (applies to UNION ALL, to UNION DISTINCT, because it is implemented via a UNION ALL step followed by a DISTINCT step, and to a Merge table read with plan-based parallel replicas, which is expanded into a union of the reads from its underlying tables). When a UNION query has many subqueries, all of them open their read buffers at the same time, leading to memory usage proportional to the number of subqueries. This setting inserts Concat processors to narrow the pipeline so that at most this many streams are active at once, drastically reducing peak memory. The actual limit is the minimum of this value and max_threads * max_streams_for_union_step_to_max_threads_ratio (either one being 0 means it is ignored). When both are 0, no narrowing is applied. The limit is also not applied when the query plan requires each output stream of the UNION to stay individually sorted (for example, when the read-in-order optimization is applied across the UNION); in that case correctness of the ordering takes precedence and narrowing is skipped.
max_streams_for_union_step_to_max_threads_ratio
This ratio multiplied bymax_threads determines a limit on simultaneously active streams in a UNION step (applies to both UNION ALL and UNION DISTINCT). The actual limit is the minimum of this computed value and max_streams_for_union_step (either one being 0 means it is ignored). For example, with max_threads = 8 and this ratio set to 1, at most 8 streams will be active. Set to 0 to disable this ratio-based limit. Like max_streams_for_union_step, the limit is not applied when the query plan requires each output stream of the UNION to stay individually sorted.
max_streams_multiplier_for_merge_tables
Ask more streams when reading from Merge table. Streams will be spread across tables that Merge table will use. This allows more even distribution of work across threads and is especially helpful when merged tables differ in size. The number of streams that read simultaneously is capped by this multiplier as well - except for aMerge table read with plan-based parallel replicas (parallel_replicas_allow_merge_tables), which is expanded into a union of the reads from its underlying tables and is therefore capped by max_streams_for_union_step, like any other union.