Skip to content

Feat!: Categorize indirect MV changes as breaking for seamless version switching#5374

Merged
izeigerman merged 12 commits intoSQLMesh:mainfrom
xardasos:indirect_change_to_materialized_view_is_breaking
Sep 26, 2025
Merged

Feat!: Categorize indirect MV changes as breaking for seamless version switching#5374
izeigerman merged 12 commits intoSQLMesh:mainfrom
xardasos:indirect_change_to_materialized_view_is_breaking

Conversation

@xardasos
Copy link
Contributor

Addresses issue: #5365

We now categorize indirect changes to MVs as breaking to allow for instantaneous switches in a virtual layer. This addresses the issue of potentially long downtimes during MVs recreation. This improvement is especially relevant for RisingWave, where chaining MVs is a common use case, as described in https://risingwave.com/understanding-materialized-views/.

if snapshot.is_materialized_view:
# We categorize changes as breaking to allow for instantaneous switches in a virtual layer.
# Otherwise, there might be a potentially long downtime during MVs recreation.
snapshot.categorize_as(SnapshotChangeCategory.INDIRECT_BREAKING, forward_only)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this looks good, but there's still a question what should be the correct behavior when forward_only is True, which will lead to the version being reused despite the INDIRECT_BREAKING category.

The forward_only flag can be set due to:

  1. Running sqlmesh plan --forward-only
  2. The virtual_environment_mode is set to dev_only in the project config, indicating that no virtual layer should be used in production

In both cases, it is the user's explicit intent to continue using the same (existing) table version. How should we handle these scenarios?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. I'm not sure, but maybe we should keep the old behavior in case of forward-only changes?

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 added a check to preserve the original behavior for forward-only changes.

@CLAassistant
Copy link

CLAassistant commented Sep 17, 2025

CLA assistant check
All committers have signed the CLA.

@xardasos xardasos force-pushed the indirect_change_to_materialized_view_is_breaking branch from a4baca7 to fb559d2 Compare September 17, 2025 13:11
@xardasos xardasos changed the title Categorize indirect MV changes as breaking for seamless version switching Feat!: Categorize indirect MV changes as breaking for seamless version switching Sep 18, 2025
@xardasos
Copy link
Contributor Author

Hey @izeigerman,

please let me know if there’s anything else that should be changed or improved before moving forward.

Copy link
Contributor

@georgesittas georgesittas left a comment

Choose a reason for hiding this comment

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

This looks good to me, thanks @xardasos!

elif self._context_diff.indirectly_modified(snapshot.name):
if snapshot.is_materialized_view and not forward_only:
# We categorize changes as breaking to allow for instantaneous switches in a virtual layer.
# Otherwise, there might be a potentially long downtime during MVs recreation.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious to understand a bit more about this. What would cause this long downtime? Can you give an example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

RisingWave doesn't support create or replace nor transactional DDL (although it can alter MV A_1 and swap it with another existing MV A_2). Previously, sqlmesh would drop and recreate the MV in case of indirect changes, making the data unavailable until the MV was rebuilt (and this can take a lot of time in case of larger MVs).

Even if an engine supports create or replace of some sort, I think having side-by-side versions of an MV allows for instantaneous rollbacks in a virtual layer.

@izeigerman izeigerman merged commit 0bf202c into SQLMesh:main Sep 26, 2025
34 of 42 checks passed
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.

4 participants