Skip to content

Commit c564523

Browse files
charislamLoquacityfabriziomello
authored
Update cagg material for TimescaleDB 2.7 (github#1115)
Co-authored-by: Lana Brindley <[email protected]> Co-authored-by: Fabrízio de Royes Mello <[email protected]>
1 parent d88f218 commit c564523

File tree

3 files changed

+39
-24
lines changed

3 files changed

+39
-24
lines changed

api/create_materialized_view.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Optional `WITH` clause options:
8181
|-|-|-|-|
8282
|`timescaledb.materialized_only`|BOOLEAN|Return only materialized data when querying the continuous aggregate view|`FALSE`|
8383
|`timescaledb.create_group_indexes`|BOOLEAN|Create indexes on the continuous aggregate for columns in its `GROUP BY` clause. Indexes are in the form `(<GROUP_BY_COLUMN>, time_bucket)`|`TRUE`|
84+
|`timescaledb.finalized`|BOOLEAN|In TimescaleDB 2.7 and above, use the new version of continuous aggregates, which stores finalized results for aggregate functions. Supports all aggregate functions, including ones that use `FILTER`, `ORDER BY`, and `DISTINCT` clauses.|`TRUE`|
8485

8586
For more information, see the [real-time aggregates][real-time-aggregates] section.
8687

timescaledb/how-to-guides/continuous-aggregates/about-continuous-aggregates.md

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,34 @@ hasn't been aggregated yet. This gives you up-to-date results on every query. If
5151
you prefer not to see recent data, you can turn this setting off. For more
5252
information, see the section on [real-time aggregates][real-time-aggs].
5353

54-
## Unsupported functions
55-
Continuous aggregates are supported for most aggregate functions that can be
56-
[parallelized by PostgreSQL][postgres-parallel-agg], including the standard
57-
aggregates like `SUM` and `AVG`. You can also use more complex expressions on
58-
top of the aggregate functions, for example `max(temperature)-min(temperature)`.
59-
60-
However, aggregates using `ORDER BY` and `DISTINCT` cannot be used with
61-
continuous aggregates since they are not possible to parallelize with
62-
PostgreSQL. TimescaleDB does not currently support `FILTER` or `JOIN` clauses,
63-
or window functions in continuous aggregates. You can work around this by
64-
[aggregating the other parts of your query beforehand, then using the window function at query time][cagg-window-functions].
65-
66-
To test out continuous aggregates, follow
67-
the [continuous aggregate tutorial][tutorial-caggs].
54+
## Function support
55+
In TimescaleDB 2.7 and above, continuous aggregates support all PostgreSQL
56+
aggregate functions. This includes both parallelizable aggregates, such as `SUM`
57+
and `AVG`, and non-parallelizable aggregates, such as `RANK`.
58+
59+
In older versions of PostgreSQL, continuous aggregates only support
60+
[aggregate functions that can be parallelized by PostgreSQL][postgres-parallel-agg].
61+
They also don't support `FILTER` and `ORDER BY` clauses, and the `DISTINCT` keyword. You can
62+
work around this by aggregating the other parts of your query in the continuous
63+
aggregate, then
64+
[using the window function to query the aggregate][cagg-window-functions].
65+
66+
The following table summarizes aggregate function support in continuous
67+
aggregates:
68+
69+
|Function, clause, or feature|TimescaleDB 2.7 and above|Below TimescaleDB 2.7|
70+
|-|-|-|
71+
|Parallelizable aggregate functions|||
72+
|Non-parallelizable aggregate functions|||
73+
|Ordered-set aggregates|||
74+
|Hypothetical-set aggregates|||
75+
|`DISTINCT` in aggregate functions|||
76+
|`FILTER` in aggregate functions|||
77+
|`ORDER BY` in aggregate functions|||
78+
79+
80+
If you want the old behavior in TimescaleDB 2.7 and above, set the parameter
81+
`timescaledb.finalized` to `false` when creating your continuous aggregate.
6882

6983
## Components of a continuous aggregate
7084
Continuous aggregates consist of:

timescaledb/overview/core-concepts/continuous-aggregates.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,16 @@ SELECT bucket, avg
8080
ORDER BY bucket;
8181
```
8282

83-
Continuous aggregates are supported for most aggregate functions that
84-
can be [parallelized by PostgreSQL][postgres-parallel-agg], which
85-
includes the normal aggregates like `SUM` and `AVG`. However,
86-
aggregates using `ORDER BY` and `DISTINCT` cannot be used with
87-
continuous aggregates since they are not possible to parallelize by
88-
PostgreSQL. In addition, TimescaleDB continuous aggregates do not
89-
currently support the `FILTER` clause (not to be confused with
90-
`WHERE`) even though it is possible to parallelize but we might add
91-
support for this in a future version.
83+
<highlight type="important">
84+
In TimescaleDB 2.7 and above, continuous aggregates support all PostgreSQL
85+
aggregate functions. They also support aggregates with keywords such as
86+
`DISTINCT`, `ORDER BY`, and `FILTER`. Older versions of TimescaleDB only support
87+
aggregate functions that can be
88+
[parallelized by PostgreSQL](https://www.postgresql.org/docs/current/parallel-plans.html#PARALLEL-AGGREGATION).
89+
They don't support `DISTINCT`, `ORDER BY`, and `FILTER`. For more information,
90+
see the
91+
[how-to guide on continuous aggregates](/timescaledb/latest/how-to-guides/continuous-aggregates/about-continuous-aggregates/#unsupported-functions).
92+
</highlight>
9293

9394
## Real-time aggregation [](real-time-aggregates)
9495

@@ -137,5 +138,4 @@ provides great control and flexibility!
137138

138139

139140
[postgres-materialized-views]: https://www.postgresql.org/docs/current/rules-materializedviews.html
140-
[postgres-parallel-agg]:https://www.postgresql.org/docs/current/parallel-plans.html#PARALLEL-AGGREGATION
141141
[api-alter-cagg]: /api/:currentVersion:/continuous-aggregates/alter_materialized_view/

0 commit comments

Comments
 (0)