Skip to content

Support 'ALTER TABLE REBALANCE' MVP#1845

Merged
whitehawk merged 18 commits intofeature/ADBDEV-6608from
ADBDEV-7579
Jul 15, 2025
Merged

Support 'ALTER TABLE REBALANCE' MVP#1845
whitehawk merged 18 commits intofeature/ADBDEV-6608from
ADBDEV-7579

Conversation

@whitehawk
Copy link

@whitehawk whitehawk commented Jul 8, 2025

Support 'ALTER TABLE REBALANCE' MVP

Problem description:
There were no means to provide segments shrink feature to the 'gprebalance'
tool.

Fix:
Add new command 'ALTER TABLE <table_name> REBALANCE' (MVP level). Details:

  1. 'ALTER TABLE <table_name> REBALANCE' supports an optional parameter - target
    number of segments (ex. 'ALTER TABLE <table_name> REBALANCE 2;').
  2. If the target number of segments is more than the number of segments in the
    table's distribution policy, rebalance command will invoke the existing
    functionality of 'ALTER TABLE <table_name> EXPAND TABLE' (meaning that expand
    will always be done to the current number of segments in the cluster, even if
    we specified less)
  3. If the target number of segments is less than the number of segments in the
    table's distribution policy, the table will be shrunk into the target number
    of segments. For hashed or randomly distributed tables, data from the excessive
    segments is inserted into the target segments, and then for all table types the
    distribution policy is updated for the target number of segments. Data from the
    excessive segments is not removed (we do not want to spend time on it, as most
    likely they will be excluded from the cluster soon anyway).
  4. New GUC 'gp_target_numsegments' is added. If the target number of segments is
    not specified for the 'ALTER TABLE <table_name> REBALANCE' command, value of
    'gp_target_numsegments' is used.
  5. If 'gp_target_numsegments' is set, all new tables are created using this
    number of segments.

@whitehawk whitehawk changed the title ADBDEV-7579: ALTER TABLE REBALANCE MVP Support 'ALTER TABLE REBALANCE' MVP Jul 8, 2025
@whitehawk whitehawk marked this pull request as ready for review July 10, 2025 05:07
Copy link

@red1452 red1452 left a comment

Choose a reason for hiding this comment

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

Should be command autocompleted?

postgres=# alter table test 
ADD                  ATTACH PARTITION     DETACH PARTITION     DROP                 INHERIT              OWNER TO             REPLICA IDENTITY     SET                  
ALTER                CLUSTER ON           DISABLE              ENABLE               NO INHERIT           RENAME               RESET                VALIDATE CONSTRAINT  
postgres=# alter table test re
rename            replica identity  reset

@whitehawk
Copy link
Author

whitehawk commented Jul 14, 2025

Should be command autocompleted?

postgres=# alter table test 
ADD                  ATTACH PARTITION     DETACH PARTITION     DROP                 INHERIT              OWNER TO             REPLICA IDENTITY     SET                  
ALTER                CLUSTER ON           DISABLE              ENABLE               NO INHERIT           RENAME               RESET                VALIDATE CONSTRAINT  
postgres=# alter table test re
rename            replica identity  reset

Added autocomplete for this command. It is a psql feature.

…l to total

Problem:
Before this change, if a table was created via CTAS with Orca planner, next
insert into this table could be planned also via Orca, though Orca shouldn't
plan such queries as it doesn't support partially distributed queries and should
fallback to Postgres planner. It was so, because MD cache wasn't reloaded.

Fix:
Completely forbid CTAS via Orca if target number of segments is not equal to
total number of segments (as partial distribution is not yet supported in Orca).
@whitehawk whitehawk merged commit 5b3f506 into feature/ADBDEV-6608 Jul 15, 2025
3 of 4 checks passed
@whitehawk whitehawk deleted the ADBDEV-7579 branch July 15, 2025 15:37
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