By default, some indexes are automatically created when you create a continuous aggregate. You can change this behavior. You can also manually create and drop indexes.

When you create a continuous aggregate, an index is automatically created for each GROUP BY column. The index is a composite index, combining the GROUP BY column with the time_bucket column.

For example, if you define a continuous aggregate view with GROUP BY device, location, bucket, two composite indexes are created: one on {device, bucket} and one on {location, bucket}.

To turn off automatic index creation, set timescaledb.create_group_indexes to false when you create the continuous aggregate.

For example:

CREATE MATERIALIZED VIEW conditions_daily
WITH (timescaledb.continuous, timescaledb.create_group_indexes=false)
AS
...

You can use a regular PostgreSQL statement to create or drop an index on a continuous aggregate.

For example, to create an index on avg_temp for a materialized hypertable named weather_daily:

CREATE INDEX avg_temp_idx ON weather_daily (avg_temp);

Indexes are created under the _timescaledb_internal schema, where the continuous aggregate data is stored. To drop the index, specify the schema. For example, to drop the index avg_temp_idx, run:

DROP INDEX _timescaledb_internal.avg_temp_idx

In Timescale 2.7 and later, you can create an index on any column in the materialized view. This includes aggregated columns, such as those storing sums and averages. In earlier versions of TimescaleDB, you can't create an index on an aggregated column.

You can't create unique indexes on a continuous aggregate, in any of the Timescale versions.

Keywords

Found an issue on this page?Report an issue or Edit this page in GitHub.