ClickHouse/docs/en/sql-reference/statements/alter/skipping-index.md

36 lines
1.8 KiB
Markdown
Raw Normal View History

---
slug: /en/sql-reference/statements/alter/skipping-index
toc_hidden_folder: true
sidebar_position: 42
sidebar_label: INDEX
---
2022-06-02 10:55:18 +00:00
# Manipulating Data Skipping Indices
The following operations are available:
2023-06-20 16:41:11 +00:00
## ADD INDEX
2023-06-20 16:56:34 +00:00
`ALTER TABLE [db.]table_name [ON CLUSTER cluster] ADD INDEX [IF NOT EXISTS] name expression TYPE type [GRANULARITY value] [FIRST|AFTER name]` - Adds index description to tables metadata.
2023-06-20 16:41:11 +00:00
## DROP INDEX
2023-06-20 16:56:34 +00:00
`ALTER TABLE [db.]table_name [ON CLUSTER cluster] DROP INDEX [IF EXISTS] name` - Removes index description from tables metadata and deletes index files from disk. Implemented as a [mutation](/docs/en/sql-reference/statements/alter/index.md#mutations).
2023-06-20 16:41:11 +00:00
## MATERIALIZE INDEX
2023-06-20 16:56:34 +00:00
`ALTER TABLE [db.]table_name [ON CLUSTER cluster] MATERIALIZE INDEX [IF EXISTS] name [IN PARTITION partition_name]` - Rebuilds the secondary index `name` for the specified `partition_name`. Implemented as a [mutation](/docs/en/sql-reference/statements/alter/index.md#mutations). If `IN PARTITION` part is omitted then it rebuilds the index for the whole table data.
2023-06-20 16:41:11 +00:00
2023-06-20 16:56:34 +00:00
## CLEAR INDEX
2023-06-20 16:41:11 +00:00
2023-06-20 16:56:34 +00:00
`ALTER TABLE [db.]table_name [ON CLUSTER cluster] CLEAR INDEX [IF EXISTS] name [IN PARTITION partition_name]` - Deletes the secondary index files from disk without removing description. Implemented as a [mutation](/docs/en/sql-reference/statements/alter/index.md#mutations).
The commands `ADD`, `DROP`, and `CLEAR` are lightweight in the sense that they only change metadata or remove files.
2023-06-20 16:41:11 +00:00
Also, they are replicated, syncing indices metadata via ClickHouse Keeper or ZooKeeper.
:::note
2022-11-09 00:17:58 +00:00
Index manipulation is supported only for tables with [`*MergeTree`](/docs/en/engines/table-engines/mergetree-family/mergetree.md) engine (including [replicated](/docs/en/engines/table-engines/mergetree-family/replication.md) variants).
2022-05-15 21:28:49 +00:00
:::