Skip to content

Commit

Permalink
Merge pull request #2844 from ClickHouse/vdimir/followupmvdoc
Browse files Browse the repository at this point in the history
Followup for #2827
  • Loading branch information
vdimir authored Nov 29, 2024
2 parents 7226f5e + f09c7cc commit 0d5c692
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion docs/en/materialized-view/index.md
Original file line number Diff line number Diff line change
@@ -311,12 +311,15 @@ In practice, you may use this behavior to optimize materialized views that only
```sql
CREATE TABLE t0 (id UInt32, value String) ENGINE = MergeTree() ORDER BY id;
CREATE TABLE t1 (id UInt32, description String) ENGINE = MergeTree() ORDER BY id;
INSERT INTO t1 VALUES (1, 'A'), (2, 'B'), (3, 'C');

CREATE TABLE mvw1_target_table (id UInt32, value String, description String) ENGINE = MergeTree() ORDER BY id;

CREATE MATERIALIZED VIEW mvw1 TO mvw1_target_table AS
SELECT t0.id, t0.value, t1.description
FROM t0
JOIN t1 ON t0.id = t1.id WHERE t0.id IN (SELECT id FROM t0);
JOIN (SELECT * FROM t1 WHERE t1.id IN (SELECT id FROM t0)) AS t1
ON t0.id = t1.id;
```

In this example, set build from the `IN (SELECT id FROM t0)` subquery has only the newly inserted rows, which can help to filter `t1` against it.

0 comments on commit 0d5c692

Please sign in to comment.