> ## 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.

# prefer_* セッション設定

> prefer_* の生成グループに含まれる ClickHouse セッション設定。

export const CloudOnlyBadge = ({supported = ['cloud', 'private', 'BYOC']}) => {
  const platforms = supported.map(platform => ({
    cloud: 'ClickHouse Cloud',
    private: 'ClickHouse Private',
    BYOC: 'BYOC'
  })[platform] || platform);
  const label = platforms.length === 1 ? platforms[0] : platforms.length === 2 ? platforms.join(' and ') : platforms.slice(0, -1).join(', ') + ', and ' + platforms[platforms.length - 1];
  return <div className="cloudBadge">
            <div className="cloudIcon">
            <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path fillRule="evenodd" clipRule="evenodd" d="M5.33395 12.6667H12.3739C13.6593 12.6667 14.7073 11.6187 14.7073 10.3334C14.7073 9.04804 13.6593 8.00004 12.3739 8.00004H12.0839V7.33337C12.0839 5.12671 10.2906 3.33337 8.08395 3.33337C6.09928 3.33337 4.45395 4.78537 4.14195 6.68204C2.55728 6.76271 1.29395 8.06204 1.29395 9.66671C1.29395 11.3234 2.63728 12.6667 4.29395 12.6667H5.33395Z" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
            </svg>
        </div>
            {'Available in ' + label}
        </div>;
};

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](/ja/reference/system-tables/settings) で参照でき、[source](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.cpp) から自動生成されています。

## prefer\_column\_name\_to\_alias

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

クエリの式や句で、別名ではなく元のカラム名を使用するかどうかを切り替えます。特に、別名がカラム名と同じ場合に重要です。詳しくは [Expression Aliases](/ja/reference/syntax#notes-on-usage) を参照してください。この設定を有効にすると、ClickHouse における別名の構文規則が、他の多くのデータベースエンジンとの互換性をより高めます。

設定可能な値:

* 0 — カラム名は別名に置き換えられます。
* 1 — カラム名は別名に置き換えられません。

結合されたテーブル間でカラム名が曖昧であり、同じ名前の別名が存在する場合は、その別名が使用されます:

```sql theme={null}
SET prefer_column_name_to_alias = 1;
SELECT t1.id + 10 AS id, id AS x
FROM (SELECT 1 AS id) AS t1, (SELECT 1 AS k) AS t2, (SELECT 2 AS id) AS t3;
```

```text theme={null}
┌─id─┬──x─┐
│ 11 │ 11 │
└────┴────┘
```

ここでの `id AS x` の `id` は `t1` と `t3` の両方のカラムであるため、別名 `t1.id + 10` に解決されます。

**例**

有効時と無効時の違い:

クエリ:

```sql theme={null}
SET prefer_column_name_to_alias = 0;
SELECT avg(number) AS number, max(number) FROM numbers(10);
```

結果:

```text theme={null}
Received exception from server (version 21.5.1):
Code: 184. DB::Exception: Received from localhost:9000. DB::Exception: Aggregate function avg(number) is found inside another aggregate function in query: While processing avg(number) AS number.
```

クエリ:

```sql theme={null}
SET prefer_column_name_to_alias = 1;
SELECT avg(number) AS number, max(number) FROM numbers(10);
```

結果:

```text theme={null}
┌─number─┬─max(number)─┐
│    4.5 │           9 │
└────────┴─────────────┘
```

## prefer\_external\_sort\_block\_bytes

<SettingsInfoBlock type="UInt64" default_value="16744704" />

<VersionHistory rows={[{"id": "row-1","items": [{"label": "24.5"},{"label": "16744704"},{"label": "外部ソートで最大ブロックバイト数を優先し、マージ時のメモリ使用量を削減します。"}]}]} />

外部ソートで最大ブロックバイト数を優先し、マージ時のメモリ使用量を削減します。

## prefer\_global\_in\_and\_join

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

`IN`/`JOIN` 演算子を `GLOBAL IN`/`GLOBAL JOIN` に置き換える機能を有効にします。

設定可能な値:

* 0 — 無効。`IN`/`JOIN` 演算子は `GLOBAL IN`/`GLOBAL JOIN` に置き換えられません。
* 1 — 有効。`IN`/`JOIN` 演算子は `GLOBAL IN`/`GLOBAL JOIN` に置き換えられます。

**使用方法**

`SET distributed_product_mode=global` は分散テーブルに対するクエリの動作を変更できますが、ローカルテーブルや外部リソース上のテーブルには適していません。そこで `prefer_global_in_and_join` 設定が役立ちます。

たとえば、分散には適さないローカルテーブルを持つクエリ処理ノードがあるとします。この場合、それらのデータを分散処理時に `GLOBAL` キーワード (`GLOBAL IN`/`GLOBAL JOIN`) を使って動的に各ノードへ配布する必要があります。

`prefer_global_in_and_join` のもう 1 つのユースケースは、外部エンジンで作成されたテーブルへのアクセスです。この設定を使うと、そのようなテーブルを join する際の外部ソースへの呼び出し回数を削減できます。クエリごとに 1 回だけです。

**関連項目:**

* `GLOBAL IN`/`GLOBAL JOIN` の使用方法の詳細は、[分散サブクエリ](/ja/reference/statements/in#distributed-subqueries) を参照してください

## prefer\_localhost\_replica

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

分散クエリの処理時に、localhost のレプリカを優先して使用するかどうかを有効または無効にします。

設定可能な値:

* 1 — localhost のレプリカが存在する場合、ClickHouse は常にその localhost のレプリカにクエリを送信します。
* 0 — ClickHouse は、[load\_balancing](/ja/reference/settings/session-settings/load-balancing#load_balancing) 設定で指定された負荷分散戦略を使用します。

<Note>
  [max\_parallel\_replicas](/ja/reference/settings/session-settings/max#max_parallel_replicas) を [parallel\_replicas\_custom\_key](/ja/reference/settings/session-settings/parallel-replicas#parallel_replicas_custom_key) なしで使用する場合は、この設定を無効にしてください。
  [parallel\_replicas\_custom\_key](/ja/reference/settings/session-settings/parallel-replicas#parallel_replicas_custom_key) が設定されている場合、この設定を無効にするのは、複数の分片にそれぞれ複数のレプリカがあるクラスターで使用する場合に限ってください。
  単一の分片と複数のレプリカを持つクラスターで使用する場合、この設定を無効にすると悪影響があります。
</Note>

## prefer\_optimize\_projection

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

<VersionHistory rows={[{"id": "row-1","items": [{"label": "26.10"},{"label": "0"},{"label": "新しい設定: `force_optimize_projection` と同様に、推定コストに関わらず利用可能な projection を選択します。ただし projection が使用されなかった場合でもクエリは失敗しません。"}]}]} />

projection 最適化が有効な場合 ([optimize\_use\_projections](/ja/reference/settings/session-settings/optimize-use#optimize_use_projections) 設定を参照) 、`SELECT` クエリにおいて projection 最適化がテーブルよりも [projections](/ja/reference/engines/table-engines/mergetree-family/mergetree#projections) を優先するようにします。

有効にすると、クエリを処理できる projection は、テーブル自体よりも多くの marks を読み取る必要がある場合でも使用されます。これは [force\_optimize\_projection](/ja/reference/settings/session-settings/force-optimize#force_optimize_projection) と同じ動作ですが、使用可能な projection がない場合でもクエリは失敗しません。

設定可能な値:

* 0 — projection は推定コストに基づいて選択されます。
* 1 — 推定コストに関わらず、利用可能な projection が選択されます。

## prefer\_warmed\_unmerged\_parts\_seconds

<CloudOnlyBadge />

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

ClickHouse Cloud でのみ有効です。マージ済みパーツがこの秒数より新しく、かつ事前ウォームされていない場合 ([cache\_populated\_by\_fetch](/ja/reference/settings/merge-tree-settings/cache-populated-by-fetch#cache_populated_by_fetch) を参照) でも、その元になったすべてのパーツが利用可能で事前ウォームされていれば、SELECT クエリは代わりにそれらのパーツから読み取ります。Replicated-/SharedMergeTree でのみ有効です。なお、これは CacheWarmer がそのパーツを処理したかどうかだけを確認します。別の要因でそのパーツが cache に取り込まれた場合でも、CacheWarmer が処理するまではコールドと見なされます。また、いったんウォームされた後に cache から追い出された場合でも、ウォーム済みと見なされます。
