@@ -55,10 +55,10 @@ As data grows in size, the performance of certain queries can degrade.
5555Materialized views store the result of a ` SAMPLE BY ` or time-based ` GROUP BY `
5656query on disk, and keep it automatically up to date.
5757
58- The refresh of a materialized view is ` INCREMENTAL ` and very efficient, and
59- using materialized views can offer 100x or higher query speedups. If you require
60- the lowest latency queries, for example, for charts and dashboards, use
61- materialized views!
58+ The refresh of a materialized view is incremental and very efficient, and using
59+ materialized views can offer 100x or higher query speedups. If you require the
60+ lowest latency queries, for example, for charts and dashboards, use materialized
61+ views!
6262
6363For a better understanding of what materialized views are for, read the
6464[ introduction to materialized views] ( /docs/concept/mat-views/ ) documentation.
@@ -106,7 +106,7 @@ If you are unfamiliar with the OHLC concept, please see our
106106
107107``` questdb-sql title="trades_OHLC_15m DDL"
108108CREATE MATERIALIZED VIEW 'trades_OHLC_15m'
109- WITH BASE 'trades' REFRESH INCREMENTAL AS
109+ WITH BASE 'trades' REFRESH IMMEDIATE AS
110110SELECT
111111 timestamp, symbol,
112112 first(price) AS open,
@@ -124,9 +124,9 @@ In this example:
1241242 . The base table is ` trades `
125125 - This is the data source, and will trigger incremental refresh when new data
126126 is written.
127- 3 . The refresh strategy is ` INCREMENTAL `
128- - The data is automatically refreshed and incrementally written; efficient,
129- fast, low maintenance.
127+ 3 . The refresh strategy is ` IMMEDIATE `
128+ - The data is automatically refreshed and incrementally written after a base
129+ table transaction occurs; efficient, fast, low maintenance.
1301304 . The ` SAMPLE BY ` query contains two key column (` timestamp ` , ` symbol ` ) and
131131 five aggregates (` first ` , ` max ` , ` min ` , ` last ` , ` price ` ) calculated in ` 15m `
132132 time buckets.
@@ -172,13 +172,61 @@ will not trigger any sort of refresh.
172172
173173#### Refresh strategies
174174
175- Currently, only ` INCREMENTAL ` refresh is supported. This strategy incrementally
176- updates the view when new data is inserted into the base table. This means that
177- only new data is written to the view, so there is minimal write overhead.
175+ The ` IMMEDIATE ` refresh strategy incrementally updates the view when new data is
176+ inserted into the base table. This means that only new data is written to the
177+ view, so there is minimal write overhead.
178178
179179Upon creation, or when the view is invalidated, a full refresh will occur, which
180180rebuilds the view from scratch.
181181
182+ Other than ` IMMEDIATE ` refresh, QuestDB supports ` MANUAL ` and timer
183+ (` EVERY <interval> ` ) strategies for materialized views. Manual strategy means
184+ that to refresh the view, you need to run the
185+ [ ` REFRESH ` SQL] ( /docs/reference/sql/refresh-mat-view/ ) explicitly. In case of
186+ timer-based refresh the view is refreshed periodically, at the specified
187+ interval.
188+
189+ The refresh strategy of an existing view can be changed any time with the
190+ [ ` ALTER SET REFRESH ` ] ( /docs/reference/sql/alter-mat-view-set-refresh/ ) command.
191+
192+ ## Period materialized views
193+
194+ In certain use cases, like storing trading day information, the data becomes
195+ available at fixed time intervals. In this case, ` PERIOD ` variant of
196+ materialized views can be used:
197+
198+ ``` questdb-sql title="Period materialized view"
199+ CREATE MATERIALIZED VIEW trades_daily_prices
200+ REFRESH PERIOD (LENGTH 1d TIME ZONE 'Europe/London' DELAY 2h) AS
201+ SELECT
202+ timestamp,
203+ symbol,
204+ avg(price) AS avg_price
205+ FROM trades
206+ SAMPLE BY 1d;
207+ ```
208+
209+ Refer to the following
210+ [ documentation page] ( /docs/reference/sql/create-mat-view/#period-materialized-views )
211+ to learn more on period materialized views.
212+
213+ ## Initial refresh
214+
215+ As soon as a materialized view is created an asynchronous refresh is started. In
216+ situations when this is not desirable, ` DEFERRED ` keyword can be specified along
217+ with the refresh strategy:
218+
219+ ``` questdb-sql title="Deferred manual refresh"
220+ CREATE MATERIALIZED VIEW trades_daily_prices
221+ REFRESH MANUAL DEFERRED AS
222+ ...
223+ ```
224+
225+ The ` DEFERRED ` keyword can be specified for any refresh strategy. Refer to the
226+ following
227+ [ documentation page] ( /docs/reference/sql/create-mat-view/#initial-refresh ) to
228+ learn more on the keyword.
229+
182230#### SAMPLE BY
183231
184232Materialized views are populated using ` SAMPLE BY ` or time-based ` GROUP BY `
@@ -357,7 +405,7 @@ useful.
357405## Limitations
358406
359407- Not all ` SAMPLE BY ` syntax is supported, for example, ` FILL ` .
360- - ` INCREMENTAL ` refresh is only triggered by inserts into the ` base ` table, not
408+ - ` IMMEDIATE ` refresh is only triggered by inserts into the ` base ` table, not
361409 join tables.
362410
363411## LATEST ON materialized views
@@ -555,15 +603,6 @@ partitioning capabilities.
555603
556604### Refresh mechanism
557605
558- ::: note
559-
560- Currently, QuestDB only supports ** incremental refresh** for materialized views.
561-
562- Future releases will include additional refresh types, such as time-interval and
563- manual refreshes.
564-
565- :::
566-
567606Unlike regular views, which recompute their results at query time, materialized
568607views in QuestDB are incrementally refreshed as new data is added to the base
569608table. This approach ensures that only the ** relevant time slices** of the view
0 commit comments