# ALTER TABLE COLUMN ADD INDEX

> **For AI agents:** the complete documentation index is at [llms.txt](https://questdb.com/docs/llms.txt). Every page is available as markdown by appending `.md` to its URL, or by sending an `Accept: text/markdown` request header.

ADD INDEX SQL keyword. Table reference documentation.

Indexes an existing [`symbol`](/docs/concepts/symbol/) column.

## Syntax

Bitmap index (default):

```questdb-sql
ALTER TABLE tableName ALTER COLUMN columnName ADD INDEX [CAPACITY n]
```

[Posting index](/docs/concepts/deep-dive/posting-index/), with optional
covering columns and encoding variant:

```questdb-sql
ALTER TABLE tableName ALTER COLUMN columnName
  ADD INDEX TYPE POSTING [DELTA | EF] [INCLUDE (col, ...)]
```

Adding an [index](/docs/concepts/deep-dive/indexes/) is an atomic, non-blocking, and
non-waiting operation. Once complete, the SQL optimizer will start using the new
index for SQL executions.

:::note QuestDB Enterprise cold storage

`ADD INDEX` fails with `cannot create index, table has a delta-active or remotely served partition` while any partition of the table is served from [cold storage](/docs/concepts/cold-storage/), or keeps [late rows in cold storage](/docs/concepts/cold-storage-late-rows/). Create indexes before a table's partitions go cold.

The check runs on the instance that receives the statement. Another instance that serves a partition from cold storage, for example because of `storage.policy.drop.local.override`, skips the replicated `ADD INDEX`, logs `index not created on this instance`, and has no index on that column, also after a failover. Its rows are the same; only queries on that column are slower there.

:::

## Examples

### Adding a bitmap index (default)

```questdb-sql
ALTER TABLE trades ALTER COLUMN side ADD INDEX;
```

### Adding a posting index

```questdb-sql
ALTER TABLE trades ALTER COLUMN instrument ADD INDEX TYPE POSTING;
```

The bare form has no covering layer — queries selecting columns other
than `instrument` still read from the column files. Add an
[`INCLUDE` clause](#adding-a-posting-index-with-covering-columns) to
build a covering index.

An encoding variant can also be forced:

```questdb-sql
-- Force delta + Frame-of-Reference (benchmarking)
ALTER TABLE trades ALTER COLUMN instrument ADD INDEX TYPE POSTING DELTA;

-- Force Elias-Fano (benchmarking)
ALTER TABLE trades ALTER COLUMN instrument ADD INDEX TYPE POSTING EF;
```

### Adding a posting index with covering columns

The `INCLUDE` clause stores additional column values in the index sidecar
files, enabling covering queries that bypass column file reads:

```questdb-sql
ALTER TABLE trades
  ALTER COLUMN symbol ADD INDEX TYPE POSTING INCLUDE (price, quantity);
```

The designated timestamp is appended to the `INCLUDE` list automatically.
After this, queries that only select columns from the `INCLUDE` list (plus
the indexed symbol column and designated timestamp) are served from the
index sidecar:

```questdb-sql
-- This query reads from the index sidecar, not from column files
SELECT timestamp, price FROM trades WHERE symbol = 'AAPL';
```

See [Posting index and covering index](/docs/concepts/deep-dive/posting-index/)
for supported column types and performance details.
