optimize_aggregators_of_group_by_keys
Eliminates min/max/any/anyLast aggregators of GROUP BY keys in SELECT sectiooptimize_append_index
Use constraints in order to append index condition. The default isfalse.
Possible values:
- true, false
optimize_arithmetic_operations_in_aggregate_functions
Move arithmetic operations out of aggregation functionsoptimize_const_name_size
Replace with scalar and use hash as a name for large constants (size is estimated by the name length). Possible values:- positive integer - max length of the name,
- 0 — always,
- negative integer - never.
optimize_count_from_files
Enables or disables the optimization of counting number of rows from files in different input formats. It applies to table functions/enginesfile/s3/url/hdfs/azureBlobStorage.
Possible values:
- 0 — Optimization disabled.
- 1 — Optimization enabled.
optimize_dictget_tuple_element
RewritetupleElement(dictGet('dict', ('a', 'b', 'c'), key), 2) into dictGet('dict', 'b', key) to avoid fetching unnecessary dictionary attributes. Supports positional (.1, .2, …) and named (.b) access, and also applies to dictGetOrDefault when the default argument is a constant tuple or a tuple(...) of constants.
optimize_distinct_in_order
Enable DISTINCT optimization if some columns in DISTINCT form a prefix of sorting. For example, prefix of sorting key in merge tree or ORDER BY statementoptimize_distributed_group_by_sharding_key
OptimizeGROUP BY sharding_key queries, by avoiding costly aggregation on the initiator server (which will reduce memory usage for the query on the initiator server).
The following types of queries are supported (and all combinations of them):
SELECT DISTINCT [..., ]sharding_key[, ...] FROM distSELECT ... FROM dist GROUP BY sharding_key[, ...]SELECT ... FROM dist GROUP BY sharding_key[, ...] ORDER BY xSELECT ... FROM dist GROUP BY sharding_key[, ...] LIMIT 1SELECT ... FROM dist GROUP BY sharding_key[, ...] LIMIT 1 BY x
SELECT ... GROUP BY sharding_key[, ...] WITH TOTALSSELECT ... GROUP BY sharding_key[, ...] WITH ROLLUPSELECT ... GROUP BY sharding_key[, ...] WITH CUBESELECT ... GROUP BY sharding_key[, ...] SETTINGS extremes=1
- 0 — Disabled.
- 1 — Enabled.
Right now it requires
optimize_skip_unused_shards (the reason behind this is that one day it may be enabled by default, and it will work correctly only if data was inserted via Distributed table, i.e. data is distributed according to sharding_key).optimize_dry_run_check_part
When enabled,OPTIMIZE ... DRY RUN validates the resulting merged part using checkDataPart. If the check fails, an exception is thrown.
optimize_empty_string_comparisons
Convert expressions like col = ” or ” = col into empty(col), and col != ” or ” != col into notEmpty(col), only when col is of String or FixedString type.optimize_extract_common_expressions
Allow extracting common expressions from disjunctions in WHERE, PREWHERE, ON, HAVING and QUALIFY expressions. A logical expression like(A AND B) OR (A AND C) can be rewritten to A AND (B OR C), which might help to utilize:
- indices in simple filtering expressions
- cross to inner join optimizatio
optimize_functions_to_subcolumns
Enables or disables optimization by transforming some functions to reading subcolumns. This reduces the amount of data to read. These functions can be transformed:- length to read the size0 subcolumn.
- empty to read the size0 subcolumn.
- notEmpty to read the size0 subcolumn.
- isNull to read the null subcolumn.
- isNotNull to read the null subcolumn.
- count to read the null subcolumn.
- mapKeys to read the keys subcolumn.
- mapValues to read the values subcolumn.
- 0 — Optimization disabled.
- 1 — Optimization enabled.
optimize_inverse_dictionary_lookup
Avoid repeated inverse dictionary lookup by doing faster lookups into a precomputed set of possible key values.optimize_multiif_to_if
Replace ‘multiIf’ with only one condition to ‘if’.optimize_normalize_count_variants
Rewrite aggregate functions that semantically equals to count() as count().optimize_on_insert
Enables or disables data transformation before the insertion, as if merge was done on this block (according to table engine). Possible values:- 0 — Disabled.
- 1 — Enabled.
optimize_prewhere_after_pushdown
Run a secondPREWHERE promotion pass after later query plan optimizations may have
deposited additional filters above a MergeTree read step (e.g. predicate pushdown through
JOIN, projection rewrites). When an existing PREWHERE is already present, the new
filter is AND-merged into it instead of staying as a separate filter step.
optimize_qbit_distance_function_reads
Replace distance functions onQBit data type with equivalent ones that only read the columns necessary for the calculation from the storage.
optimize_read_in_order
Enables ORDER BY optimization in SELECT queries for reading data from MergeTree tables. Possible values:- 0 —
ORDER BYoptimization is disabled. - 1 —
ORDER BYoptimization is enabled.
optimize_respect_aliases
If it is set to true, it will respect aliases in WHERE/GROUP BY/ORDER BY, that will help with partition pruning/secondary indexes/optimize_aggregation_in_order/optimize_read_in_order/optimize_trivial_countoptimize_sorting_by_input_stream_properties
Optimize sorting by sorting properties of input streamoptimize_substitute_columns
Use constraints for column substitution. The default isfalse.
Possible values:
- true, false
optimize_syntax_fuse_functions
Enables to fuse aggregate functions with identical argument. It rewrites query contains at least two aggregate functions from sum, count or avg with identical argument to sumCount. Possible values:- 0 — Functions with identical argument are not fused.
- 1 — Functions with identical argument are fused.
optimize_throw_if_noop
Enables or disables throwing an exception if an OPTIMIZE query didn’t perform a merge. By default,OPTIMIZE returns successfully even if it didn’t do anything. This setting lets you differentiate these situations and get the reason in an exception message.
Possible values:
- 1 — Throwing an exception is enabled.
- 0 — Throwing an exception is disabled.
optimize_time_filter_with_preimage
Optimize Date and DateTime predicates by converting functions into equivalent comparisons without conversions (e.g.toYear(col) = 2023 -> col >= '2023-01-01' AND col <= '2023-12-31')
optimize_truncate_order_by_after_group_by_keys
Remove trailing ORDER BY elements once all GROUP BY keys are covered in the ORDER BY prefix.optimize_uniq_to_count
Rewrite uniq and its variants(except uniqUpTo) to count if subquery has distinct or group by clause.optimize_using_constraints
Use constraints for query optimization. The default isfalse.
Possible values:
- true, false