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

# optimize_skip_* session settings

> ClickHouse session settings in the optimize_skip_* generated group.

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
  }}>Type</div>
      <div style={{
    overflowWrap: "anywhere"
  }}>{type}</div>
      <div style={{
    fontWeight: 600,
    opacity: 0.72,
    marginInlineStart: "0.5rem"
  }}>Default</div>
      <div style={{
    overflowWrap: "anywhere"
  }}>{default_value}</div>
      {changeable_without_restart && <div style={{
    fontWeight: 600,
    opacity: 0.72,
    marginInlineStart: "0.5rem"
  }}>
          Changeable without restart
        </div>}
      {changeable_without_restart && <div style={{
    overflowWrap: "anywhere"
  }}>
          {changeable_without_restart}
        </div>}
    </div>;
};

These settings are available in [system.settings](/docs/reference/system-tables/settings) and are autogenerated from [source](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.cpp).

<h2 id="optimize_skip_merged_partitions">
  optimize\_skip\_merged\_partitions
</h2>

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

Enables or disables optimization for [OPTIMIZE TABLE ... FINAL](/docs/reference/statements/optimize) query if there is only one part with level > 0 and it doesn't have expired TTL.

* `OPTIMIZE TABLE ... FINAL SETTINGS optimize_skip_merged_partitions=1`

By default, `OPTIMIZE TABLE ... FINAL` query rewrites the one part even if there is only a single part.

Possible values:

* 1 - Enable optimization.
* 0 - Disable optimization.

<h2 id="optimize_skip_unused_shards">
  optimize\_skip\_unused\_shards
</h2>

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

Enables or disables skipping of unused shards for [SELECT](/docs/reference/statements/select/index) queries that have sharding key condition in `WHERE/PREWHERE`, and activates related optimizations for distributed queries (e.g. aggregation by sharding key).

<Note>
  Assumes that the data is distributed by sharding key, otherwise a query yields incorrect result.
</Note>

Possible values:

* 0 — Disabled.
* 1 — Enabled.

<h2 id="optimize_skip_unused_shards_limit">
  optimize\_skip\_unused\_shards\_limit
</h2>

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

Limit for number of sharding key values, turns off `optimize_skip_unused_shards` if the limit is reached.

Too many values may require significant amount for processing, while the benefit is doubtful, since if you have huge number of values in `IN (...)`, then most likely the query will be sent to all shards anyway.

<h2 id="optimize_skip_unused_shards_nesting">
  optimize\_skip\_unused\_shards\_nesting
</h2>

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

Controls [`optimize_skip_unused_shards`](/docs/reference/settings/session-settings/optimize-skip#optimize_skip_unused_shards) (hence still requires [`optimize_skip_unused_shards`](/docs/reference/settings/session-settings/optimize-skip#optimize_skip_unused_shards)) depends on the nesting level of the distributed query (case when you have `Distributed` table that look into another `Distributed` table).

Possible values:

* 0 — Disabled, `optimize_skip_unused_shards` works always.
* 1 — Enables `optimize_skip_unused_shards` only for the first level.
* 2 — Enables `optimize_skip_unused_shards` up to the second level.

<h2 id="optimize_skip_unused_shards_rewrite_in">
  optimize\_skip\_unused\_shards\_rewrite\_in
</h2>

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

Rewrite IN in query for remote shards to exclude values that does not belong to the shard (requires optimize\_skip\_unused\_shards).

Possible values:

* 0 — Disabled.
* 1 — Enabled.
