Use CTAS approach for rebalancing the materialized view#2249
Merged
whitehawk merged 2 commits intofeature/ADBDEV-6608from Feb 24, 2026
Merged
Use CTAS approach for rebalancing the materialized view#2249whitehawk merged 2 commits intofeature/ADBDEV-6608from
whitehawk merged 2 commits intofeature/ADBDEV-6608from
Conversation
Problem description: Before this patch, in order to rebalance a materialized view, 2 steps were required: the actual rebalance where distribution policy was updated, and the refresh step to update the data in the materialized view. This approach had 2 problems with respect to usage in 'ggrebalance' tool for cluster shrink: 1. It could change the actual data in the materialized view before the cluster shrink, and after the shrink, if the view was not up-to-date. We intend to keep the logical data in the cluster not altered. 2. If a materialized view depends on another materialized view, there could be a race condition when doing the refresh, when we try to refresh based on the yet-not-refreshed one. Fix: Use the CTAS approach from the EXPAND TABLE specifically when we are rebalancing a materialized view. It creates a temp table with a correct distribution policy, where all data from the materialized view is copied, and then the relfilenode of the materialized view is swapped with the temp table. It keeps the data as it was before the rebalance, even if it was not up-to-date (therefore we will not surprise the user with the not expected view content), and it eliminates dependencies on other objects besides the materialized view itself.
bimboterminator1
approved these changes
Feb 20, 2026
KnightMurloc
approved these changes
Feb 24, 2026
bimboterminator1
approved these changes
Feb 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use CTAS approach for rebalancing the materialized view
Problem description:
Before this patch, in order to rebalance a materialized view, 2 steps were
required: the actual rebalance where distribution policy was updated, and the
refresh step to update the data in the materialized view. This approach had 2
problems with respect to usage in 'ggrebalance' tool for cluster shrink:
shrink, and after the shrink, if the view was not up-to-date. We intend to keep
the logical data in the cluster not altered.
a race condition when doing the refresh, when we try to refresh based on the
yet-not-refreshed one.
Fix:
Use the CTAS approach from the EXPAND TABLE specifically when we are rebalancing
a materialized view. It creates a temp table with a correct distribution policy,
where all data from the materialized view is copied, and then the relfilenode
of the materialized view is swapped with the temp table. It keeps the data as it
was before the rebalance, even if it was not up-to-date (therefore we will not
surprise the user with the not expected view content), and it eliminates
dependencies on other objects besides the materialized view itself.