> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-parallel-read-in-order-multi-part.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# aggregate_* 会话设置

> aggregate_* 生成组中的 ClickHouse 会话设置。

export const VersionHistory = ({rows = []}) => {
  if (rows.length === 0) {
    return null;
  }
  const headers = ["版本", "默认值", "注释"];
  const border = "1px solid rgba(128, 128, 128, 0.3)";
  const cell = {
    border,
    padding: "0.25rem 0.5rem",
    textAlign: "start",
    verticalAlign: "top"
  };
  return <details className="not-prose" style={{
    border,
    borderRadius: "0.5rem",
    margin: "0.5rem 0",
    padding: "0.5rem 0.75rem",
    fontSize: "0.8125rem",
    lineHeight: "1.125rem"
  }}>
      <summary style={{
    cursor: "pointer",
    fontWeight: 600,
    opacity: 0.72
  }}>
        版本历史
      </summary>
      <table style={{
    borderCollapse: "collapse",
    width: "100%",
    margin: "0.5rem 0 0"
  }}>
        <thead>
          <tr>
            {headers.map(header => <th key={header} style={{
    ...cell,
    fontWeight: 600,
    opacity: 0.72
  }}>
                {header}
              </th>)}
          </tr>
        </thead>
        <tbody>
          {rows.map((row, row_index) => <tr key={row.id ?? row_index}>
              {(row.items ?? []).map((item, item_index) => <td key={item_index} style={{
    ...cell,
    overflowWrap: "anywhere"
  }}>
                  {item?.label}
                </td>)}
            </tr>)}
        </tbody>
      </table>
    </details>;
};

export const SettingsInfoBlock = ({type, default_value, changeable_without_restart}) => {
  return <div className="not-prose" style={{
    display: "flex",
    flexWrap: "wrap",
    alignItems: "baseline",
    columnGap: "0.5rem",
    rowGap: "0.125rem",
    margin: "0.375rem 0",
    fontSize: "0.8125rem",
    lineHeight: "1.125rem"
  }}>
      <div style={{
    fontWeight: 600,
    opacity: 0.72
  }}>类型</div>
      <div style={{
    overflowWrap: "anywhere"
  }}>{type}</div>
      <div style={{
    fontWeight: 600,
    opacity: 0.72,
    marginInlineStart: "0.5rem"
  }}>默认值</div>
      <div style={{
    overflowWrap: "anywhere"
  }}>{default_value}</div>
      {changeable_without_restart && <div style={{
    fontWeight: 600,
    opacity: 0.72,
    marginInlineStart: "0.5rem"
  }}>
          无需重启即可更改
        </div>}
      {changeable_without_restart && <div style={{
    overflowWrap: "anywhere"
  }}>
          {changeable_without_restart}
        </div>}
    </div>;
};

这些设置可在 [system.settings](/zh/reference/system-tables/settings) 中查看，并根据 [源代码](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.cpp) 自动生成。

## aggregate\_function\_input\_format

<SettingsInfoBlock type="AggregateFunctionInputFormat" default_value="state" />

<VersionHistory rows={[{"id": "row-1","items": [{"label": "25.12"},{"label": "state"},{"label": "New setting to control AggregateFunction input format during INSERT operations. Setting Value set to state by default"}]}]} />

输入格式如何读取 `AggregateFunction` 类型的列。

可能的取值：

* `state` — 聚合函数的序列化状态，即输出格式写出的形式 (默认值) 。
* `value` — 聚合函数某个参数的值；若参数有多个，则为这些参数组成的元组。该值会经过聚合形成状态。
* `array` — 由上述 `value` 选项所描述的值组成的数组。数组中的所有元素都会经过聚合形成状态。

在 `value` 和 `array` 模式下，格式会按值的类型来读取该列：`AggregateFunction(f, T)` 按 `T` 读取，`AggregateFunction(f, T1, T2)` 按 `Tuple(T1, T2)` 读取，在 `array` 模式下则按相应的 `Array` 读取。值采用该格式针对相应类型所使用的表示形式写出：在文本格式中为数字或字符串，在 JSON 格式中为 JSON 数组，在 `RowBinary` 或 `Native` 中为该类型的二进制编码，在 `Parquet` 中为该类型的列，依此类推。这适用于所有输入格式，也适用于嵌套在 `Array`、`Tuple` 或 `Map` 中的 `AggregateFunction`。

**示例**

对于具有如下结构的表：

```sql theme={null}
CREATE TABLE example (
    user_id UInt64,
    avg_session_length AggregateFunction(avg, UInt32)
);
```

当 `aggregate_function_input_format = 'value'` 时：

```sql theme={null}
INSERT INTO example FORMAT CSV
123,456
```

```sql theme={null}
INSERT INTO example FORMAT JSONEachRow
{"user_id": 123, "avg_session_length": 456}
```

使用 `aggregate_function_input_format = 'array'` 时：

```sql theme={null}
INSERT INTO example FORMAT CSV
123,"[456,789,101]"
```

```sql theme={null}
INSERT INTO example FORMAT JSONEachRow
{"user_id": 123, "avg_session_length": [456, 789, 101]}
```

注意：`value` 和 `array` 格式比默认的 `state` 格式慢，因为它们需要在插入时创建并聚合值。

## aggregate\_functions\_null\_for\_empty

<SettingsInfoBlock type="Bool" default_value="0" />

启用或禁用对查询中所有聚合函数的重写，并为它们添加 [-OrNull](/zh/reference/functions/aggregate-functions/combinators#-ornull) 后缀。若要兼容 SQL 标准，请启用此设置。
它通过查询重写来实现 (类似于 [count\_distinct\_implementation](/zh/reference/settings/session-settings/count-distinct#count_distinct_implementation) 设置) ，以便在分布式查询中获得一致的结果。

可能的值：

* 0 — 禁用。
* 1 — 启用。

**示例**

请考虑以下包含聚合函数的查询：

```sql theme={null}
SELECT SUM(-1), MAX(0) FROM system.one WHERE 0;
```

当 `aggregate_functions_null_for_empty = 0` 时，结果为：

```text theme={null}
┌─SUM(-1)─┬─MAX(0)─┐
│       0 │      0 │
└─────────┴────────┘
```

当 `aggregate_functions_null_for_empty = 1` 时，结果为：

```text theme={null}
┌─SUMOrNull(-1)─┬─MAXOrNull(0)─┐
│          NULL │         NULL │
└───────────────┴──────────────┘
```
