Skip to content

Conversation

@kssumin
Copy link

@kssumin kssumin commented Oct 13, 2025

Problem

Currently, ALTER TABLE ... RENAME TO ... and RENAME TABLE statements are blocked for sharding and broadcast tables, even though the underlying physical rename operation would succeed. This limitation exists because the original implementation (PR #10462) only addressed single tables, leaving sharding and broadcast tables unsupported.

Users managing sharded databases cannot rename their tables through standard SQL, forcing them to manually drop and recreate tables with new names - a disruptive operation that requires data migration.

Solution

Instead of blocking rename operations entirely, this change allows the physical table rename to proceed while validating that the new table name doesn't conflict with existing sharding rules or schema tables.

The validation logic now focuses on preventing naming conflicts rather than blocking the operation outright:

  • Ensures the new table name isn't already defined as a sharding table
  • Ensures the new table name doesn't already exist in the current schema

For single tables, metadata rules are automatically refreshed after rename. For sharding and broadcast tables, the physical rename succeeds and users can update their rules via DistSQL commands - consistent with existing DROP/CREATE TABLE behavior.

Impact

Breaking change in validation behavior: Previously, any rename operation involving sharding tables would fail immediately. Now, validation focuses on the target table name conflicts, allowing legitimate rename operations to proceed.

Supported modes: Works in both Standalone and Cluster modes. In Standalone mode with in-memory repository, changes are volatile; with JDBC repository, changes persist across restarts.

User workflow for sharding/broadcast tables:

  1. Execute ALTER TABLE ... RENAME TO ... or RENAME TABLE - physical tables are renamed
  2. Update sharding/broadcast rules manually via DistSQL to reflect new table names

Closes #10476

Before committing this PR, I'm sure that I have checked the following options:

  • My code follows the code of conduct of this project.
  • I have self-reviewed the commit code.
  • I have (or in comment I request) added corresponding labels for the pull request.
  • I have passed maven check locally : ./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e.
  • I have made corresponding changes to the documentation.
  • I have added corresponding unit tests for my changes.
  • I have updated the Release Notes of the current development version. For more details, see Update Release Note

* Remove restrictions in ShardingAlterTableSupportedChecker and ShardingRenameTableSupportedChecker
* Add validation to prevent conflicts with existing sharding tables
* Add renameTables() method to MetaDataManagerPersistService interface
* Implement metadata refresh for table rename operations in both cluster and standalone modes
* Add comprehensive test coverage for rename table operations
@terrymanu
Copy link
Member

Could you fix checkstyle first?

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.

Support sharding tables and broadcast tables to execute ALTER TABLE ... RENAME TO ... statement

2 participants