Skip to content

Use CTAS approach for rebalancing the materialized view#2249

Merged
whitehawk merged 2 commits intofeature/ADBDEV-6608from
GG-225
Feb 24, 2026
Merged

Use CTAS approach for rebalancing the materialized view#2249
whitehawk merged 2 commits intofeature/ADBDEV-6608from
GG-225

Conversation

@whitehawk
Copy link

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:

  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.

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.
@whitehawk whitehawk merged commit 0385d97 into feature/ADBDEV-6608 Feb 24, 2026
3 of 4 checks passed
@whitehawk whitehawk deleted the GG-225 branch February 24, 2026 11:44
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