Skip to content

Fix mat view guide typos #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 15 additions & 25 deletions documentation/guides/mat-views.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,16 @@ If you are unfamiliar with the OHLC concept, please see our

```questdb-sql title="trades_OHLC_15m DDL"
CREATE MATERIALIZED VIEW 'trades_OHLC_15m'
WITH BASE 'trades' REFRESH INCREMENTAL
AS (
SELECT
timestamp, symbol,
first(price) AS open,
max(price) as high,
min(price) as low,
last(price) AS close,
sum(amount) AS volume
FROM trades
SAMPLE BY 15m
) PARTITION BY MONTH;
WITH BASE 'trades' REFRESH INCREMENTAL AS
SELECT
timestamp, symbol,
first(price) AS open,
max(price) as high,
min(price) as low,
last(price) AS close,
sum(amount) AS volume
FROM trades
SAMPLE BY 15m;
```

In this example:
Expand All @@ -132,12 +130,13 @@ In this example:
4. The `SAMPLE BY` query contains two key column (`timestamp`, `symbol`) and
five aggregates (`first`, `max`, `min`, `last`, `price`) calculated in `15m`
time buckets.
5. The view is partitioned by `DAY`.
5. The view is partitioned by `MONTH`. This partitioning is selected
[by default](#default-partitioning) based on the `SAMPLE BY` interval.
6. No TTL is defined
- Therefore, the materialized view will contain a summary of _all_ the base
`trades` table's data.

Many parts of the above DDL statement are optional and can be ommited:
Many parts of the above DDL statement are optional and can be omitted:

```questdb-sql title="trades_OHLC_15m compact DDL"
CREATE MATERIALIZED VIEW 'trades_OHLC_15m' AS
Expand Down Expand Up @@ -357,20 +356,12 @@ useful.

## Limitations

### Beta

- Not all `SAMPLE BY` syntax is supported, for example, `FILL`.
- The `INCREMENTAL` refresh strategy relies on deduplicated inserts (O3 writes)
- We will instead delete a time range and insert the data as an append, which
is **much** faster.
- This also means that currently, deduplication keys must be aligned across
- This means that currently, deduplication keys must be aligned across
the `base` table and the view.

### Post-release

- Only `INCREMENTAL` refresh is supported
- We intend to add alternatives, such as:
- `PERIODIC` (once per partition),
- In next versions, we intend to add alternatives, such as:
- `TIMER` (once per time interval)
- `MANUAL` (only when manually triggered)
- `INCREMENTAL` refresh is only triggered by inserts into the `base` table, not
Expand Down Expand Up @@ -496,7 +487,6 @@ Instead of storing the raw data, we will store one row, per symbol, per side,
per day of data.

```questdb-sql title="down-sampling test query" demo

SELECT timestamp, symbol, side, price, amount, "latest" as timestamp FROM (
SELECT timestamp,
symbol,
Expand Down