Skip to content

Altermv tutorial#34854

Merged
kay-kim merged 10 commits intoMaterializeInc:altermv-tutorialfrom
kay-kim:altermv-tutorial
Feb 3, 2026
Merged

Altermv tutorial#34854
kay-kim merged 10 commits intoMaterializeInc:altermv-tutorialfrom
kay-kim:altermv-tutorial

Conversation

@kay-kim
Copy link
Contributor

@kay-kim kay-kim commented Jan 28, 2026

Wanted to get a pulse on the changes before tweaking the guide a bit.

For ease of review, added a patch to fake the release of v26.10 (2d89321) which will be reverted before merging [hence, converted to draft]

@kay-kim kay-kim requested a review from a team as a code owner January 28, 2026 23:53
@kay-kim kay-kim marked this pull request as draft January 28, 2026 23:53
@kay-kim kay-kim requested review from maheshwarip and teskje January 29, 2026 00:04
things like querying materialized views from different clusters, indexed vs.
non-indexed, and so on."

{{< if-released "v26.10" >}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FROM highest_bid_per_auction
WHERE end_time < mz_now();
```
{{% include-example file="examples/create_materialized_view" example="example-create-materialized-view" %}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced this with the example from quickstart (with the modification of creating a view -> creating a materialized view).


## Details

### Replacing a materialized view
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- name: "syntax-apply-replacement"
code: |
ALTER MATERIALIZED VIEW <name> APPLY REPLACEMENT <replacement_name>;
ALTER MATERIALIZED VIEW <name> APPLY REPLACEMENT <replacement_view>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to view ... in case people thought we were renaming.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how would you feel about us making it replacement_materialized_view to make this more clear?

the target materialized view. See [`CREATE REPLACEMENT MATERIALIZED VIEW
<replacement_view>...FOR <name>...`](/sql/create-materialized-view).

- name: "example-apply-replacement"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Materialize supports a two-step process for replacing materialized views
in-place, i.e., without recreating downstream objects:

1. **Create a replacement**: Use `CREATE REPLACEMENT MATERIALIZED VIEW` to
Copy link
Contributor Author

@kay-kim kay-kim Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since there's the guide being written, I condensed this.

https://preview.materialize.com/materialize/34854/sql/create-materialized-view/#use-case

#### Restrictions
#### Query performance of replacement views

- The replacement must have the same schema as the target materialized view:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I incorporated this not quite as a restriction ... but more on how to run the command

https://preview.materialize.com/materialize/34854/sql/create-materialized-view/#creating-replacement-materialized-views

---
You cannot run `ALTER MATERIALIZED VIEW ... APPLY REPLACEMENT` command within a
transaction block. Instead, the `ALTER MATERIALIZED VIEW ... APPLY REPLACEMENT`
command must be run outside of an explicit transaction.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ... actually, given that we only allow:

  • read-only transactions (for SELECT only txn or SUBSCRIBE-based txns)
  • insert-only transactions

We might not actually need this .. because the list of things we don't allow in a transaction block is everything but the aforementioned bullet points.

```

If the target view is behind, it is recommended to drop the replacement
view instead of having it run for an extended period, buffering
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Is this something people can gauge by how far behind the target is? or is it just people check again after some time and see that it is still behind?
Q: Can people reduce the likelihood of the target being behind by applying the replacement view soon after it hydrates?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll need @teskje's help on these!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something people can gauge by how far behind the target is? or is it just people check again after some time and see that it is still behind?

Kind of. The write frontier is a timestamp and can be interpreted as the time up to which the target MV has processed its outputs. You can subtract that time from the current time to get the "wallclock lag", or look it up in the wallclock lag relations directly. But if the MV is stuck, it doesn't really tell you how long you have to wait (might be forever). Better to look at the frontier several times and check if the write frontier is catching up (i.e. it advances by more than one second per second).

Can people reduce the likelihood of the target being behind by applying the replacement view soon after it hydrates?

I don't think so. That would imply that the replacement running somehow makes the target unhealthy. They are independent dataflows, so the only way the replacement could influence the target is when they run on the same cluster and the running replacement pushes the cluster over the edge. But if that's the case, then hydrating the replacement (which is generally more compute intensive than steady state) would have already overloaded the cluster and would have made the target fall behind, so you wouldn't have been able to apply the replacement immediately after hydration either.

If the replacement view is ahead of the target view, both the command and
the replacement view wait for the target view to catch up. During this
wait, the replacement view buffers any changes it receives from its
inputs, which, depending on the amount to buffer, could cause the cluster
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: If someone runs the command before checking and it hangs, should we tell people to break out of it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I would personally add this in a guidelines section below the bullet points. Adding a note here feels confusing as a reader - but feel free to discard the opinion.

FWIW here's how I would re-write this if we were to move it lower:

To successfully replace a materialized view, the original and the replacement materialized view need to both be up to date. If the original is lagging behind, the ALTER MATERIALIZED VIEW ... APPLY REPLACEMENT command will pause until the original has caught up. If it takes too long for the original to catch up, the cluster might run out of memory. It is recommended to first check whether the original materialized view is up to date with the replacement. If the ALTER MATERIALIZED VIEW ... APPLY REPLACEMENT command does not execute successfully, we recommend canceling it to prevent out of memory errors.

Before applying the replacement view:

- Verify that the replacement view is hydrated to replace without downtime.
- Verify that the target materialized view results are not behind the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd use the word original rather than target here. And I'd frame this as : verify that the original and replacement materialized views are up to date.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went with original.
As for the framing ... for now, went with the not behind ... because everything else was more talking about one catching up to another.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ... just seeing your reframing. Will incorporate.


The replacement view hydrates in the background.

#### Apply the replacement
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like re-using the content! But re-using it does make this section feel like it has been accidentally copy pasted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh ... reused the wrong shared content :D

@maheshwarip maheshwarip marked this pull request as ready for review February 2, 2026 20:43
@maheshwarip
Copy link
Contributor

@kay-kim once Jan replies, feel free to incorporate whichever changes you feel strongly about and then feel free to merge this into my branch so we get unblocked

@kay-kim
Copy link
Contributor Author

kay-kim commented Feb 3, 2026

Will revert the fake release of v26.10 and merge.

@kay-kim kay-kim merged commit 1c701c4 into MaterializeInc:altermv-tutorial Feb 3, 2026
1 of 3 checks passed
@kay-kim kay-kim deleted the altermv-tutorial branch February 3, 2026 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants