> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# aggregate_* 会话设置

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

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](/docs/zh/reference/system-tables/settings) 中查看，并根据 [源代码](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.cpp) 自动生成。

<div id="aggregate_function_input_format">
  ## aggregate\_function\_input\_format
</div>

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "25.12"},{"label": "state"},{"label": "新增设置，用于控制 INSERT 操作期间 AggregateFunction 的输入格式。设置值默认为 state"}]}]} />

INSERT 操作期间 AggregateFunction 输入的格式。

可能的值：

* `state` — 包含序列化状态的二进制字符串 (默认值) 。这是默认行为，即 AggregateFunction 值应以二进制数据形式提供。
* `value` — 此格式要求提供聚合函数参数的单个值；如果有多个参数，则要求提供由这些参数组成的 tuple。它们会使用相应的 IDataType 或 DataTypeTuple 进行反序列化，然后聚合形成状态。
* `array` — 此格式要求提供一个值的 `Array`，如上文 `value` 选项所述。数组中的所有元素都会被聚合以形成状态。

**示例**

对于一个具有以下结构的表：

```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
```

当 `aggregate_function_input_format = 'array'` 时：

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

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

<div id="aggregate_functions_null_for_empty">
  ## aggregate\_functions\_null\_for\_empty
</div>

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

启用或禁用对查询中所有聚合函数的重写，并为它们添加 [-OrNull](/docs/zh/reference/functions/aggregate-functions/combinators#-ornull) 后缀。若要兼容 SQL 标准，请启用此设置。
它通过查询重写来实现 (类似于 [count\_distinct\_implementation](/docs/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 │
└───────────────┴──────────────┘
```
