This topic describes DDL replication operations on a Global Database Network (GDN).
Efficient DML replication implements table consistency between the upstream and downstream clusters of a GDN. DDL replication ensures schema consistency between the primary and secondary clusters of a GDN. Schema consistency between the primary and secondary clusters of a GDN means not only the consistency of the table structure, but also the consistency of all database objects. This ensures that secondary clusters can carry application traffic when a failover occurs. Otherwise, even losing an index can cause a serious performance issue.
DDL types
PolarDB-X supports multiple types of database objects, including not only common MySQL-compatible tables, columns, indexes, views, and functions, but also custom object types such as table groups, sequences, global secondary indexes (GSIs), clustered columnar indexes (CCIs), and custom functions. PolarDB-X also provides custom extended syntax, such as TTL, locality, online modify column (OMC), and local indexes. DDL replication is challenging both in terms of compatibility and the complexity of distributed scenarios. Therefore, PolarDB-X provide the built-in DDL replication capabilities which are characterized by simplicity, reliability, and ease of use.
The following table describes the supported DDL types.
Type | DDL statement | Supported or not | Remarks |
DATABASE | CREATE_DATABASE | Yes | For more information , see Database statements. Note The ALTER DATABASE statement does not allow you to modify character sets. Therefore, ALTER DATABASE is not supported in replication scenarios. |
DROP_DATABASE | Yes | ||
ALTER_DATABASE | No | ||
MOVE_DATABASE | No | ||
TABLE | CREATE_TABLE | Yes | For more information, see Table statements. |
ALTER_TABLE | Yes | ||
DROP_TABLE | Yes | ||
TRUNCATE_TABLE | Yes | ||
RENAME_TABLE | Yes | ||
ANALYZE_TABLE | Yes | ||
PARTITION | SPLIT_PARTITION | Yes | For more information, see Partition statements. Note Partition migration is not supported. For more information, see Limit 1. |
SPLIT_INTO_BY_HOT_VALUE | Yes | ||
MERGE_PARTITIONS | Yes | ||
MOVE_PARTITIONS | No | ||
RENAME_PARTITION | Yes | ||
ADD_PARTITION | Yes | ||
DROP_PARTITION | Yes | ||
MODIFY_PARTITION | Yes | ||
REORGANIZE_PARTITION | Yes | ||
TRUNCATE_PARTITION | Yes | ||
TABLEGROUP | CREATE_TABLEGROUP | Yes | For more information, see Table group statements. |
DROP_TABLEGROUP | Yes | ||
ALTER_TABLEGROUP | Yes | ||
MERGE_TABLEGROUP | Yes | ||
ALTER_TABLEGROUP_ADD_TABLE | Yes | ||
ALTER_TABLE_SET_TABLEGROUP | Yes | ||
JOINGROUP | CREATE_JOINGROUP | Yes | |
ALTER_JOINGROUP | Yes | ||
DROP_JOINGROUP | Yes | ||
INDEX | CREATE_INDEX | Yes | For more information, see Indexes. |
DROP_INDEX | Yes | ||
ALTER_INDEX | Yes | ||
ALTER_INDEX_VISIBILITY | Yes | ||
SEQUENCE | CREATE_SEQUENCE | Yes | For more information, see Sequences. |
DROP_SEQUENCE | Yes | ||
ALTER_SEQUENCE | Yes | ||
RENAME_SEQUENCE | Yes | ||
CONVERT_ALL_SEQUENCES | Yes | ||
FUNCTION | CREATE_FUNCTION | Yes | For more information, see Custom functions. |
DROP_FUNCTION | Yes | ||
ALTER_FUNCTION | Yes | ||
CREATE_JAVA_FUNCTION | Yes | ||
ALTER_JAVA_FUNCTION | Yes | ||
DROP_JAVA_FUNCTION | Yes | ||
PROCEDURE | CREATE_PROCEDURE | Yes | For more information, see Stored procedures. |
ALTER_PROCEDURE | Yes | ||
DROP_PROCEDURE | Yes | ||
VIEW | CREATE_VIEW | Yes | For more information, see Views. |
DROP_VIEW | Yes | ||
ALTER_VIEW | Yes | ||
CREATE_MATERIALIZED_VIEW | Yes | ||
DROP_MATERIALIZED_VIEW | Yes | ||
USER | CREATE_USER | Yes | For more information, see Manage accounts and permissions. |
DROP_USER | Yes | ||
SET_PASSWORD | Yes | ||
GRANT_PRIVILEGE_TO_USER | Yes | ||
REVOKE_PRIVILEGE_FROM_USER | Yes | ||
ROLE | CREATE_ROLE | Yes | For more information, see Manage roles and permissions. |
DROP_ROLE | Yes | ||
GRANT_PRIVILEGE_TO_ROLE | Yes | ||
GRANT_ROLE_TO_USER | Yes | ||
SQL_SET_DEFAULT_ROLE | Yes | ||
REVOKE_PRIVILEGE_FROM_ROLE | Yes | ||
REVOKE_ROLE_FROM_USER | Yes | ||
SET | SET GLOBAL ... | No | PolarDB-X adopts the same policy as the native MySQL. Data is not synchronized when a primary/secondary replication link is established. This is not a schema change. To make a schema change, perform the operations separately on the primary cluster and secondary clusters. |
SQL throttling | * | No | SQL throttling is a temporary operation. You cannot copy throttling rules to secondary clusters in a GDN. To copy throttling rules to a secondary cluster, you must perform the operations separately on the primary cluster and secondary clusters. |
DDL statements related to CCIs (CREATE COLUMNAR INDEX, DROP COLUMNAR INDEX, and ALTER COLUMNAR INDEX) cannot be replicated.
Table group types
PolarDB-X supports two types of table groups: explicit table groups and implicit table groups.
You can create an explicit table group by executing the
CREATE TABLEGROUPstatement, delete it by executing theDROP TABLEGROUPstatement, and modify it by executing theALTER TABLEGROUPstatement. For more information, see Table groups.Implicit table groups are implicitly created by PolarDB-X. When you create a partitioned table, delete a partitioned table, or change the partition type of a table, implicit table groups may be created, modified, or deleted. For implicit table groups, the
CREATE TABLEGROUPandDROP TABLEGROUPstatements cannot be used, but theALTER TABLEGROUPstatement can be used. Implicit table groups are named maintaining a sequence number list: tg1, tg2, tg3, and so on. Sequence numbers are generated with uncertainty. For example, if partitioned tables T1 and T2 are created in parallel, the sequence numbers of the implicit table groups for these two tables are random. In addition, some sequence numbers may be skipped. For example, if the sequence number of a table group is generated by adding 1 to an existing sequence number and when the DDL task flow is rolled back, the generated sequence number is skipped.
Implicit table groups pose a challenge to primary/secondary replication in PolarDB-X. If the primary cluster and secondary clusters generate their own implicit table groups based on the default rules, the names of the implicit table groups for the same tables in the primary cluster and secondary clusters may be inconsistent, or even the names of all implicit table groups may be confused. For GDNs, implicit table groups are replicated by extending DDL statements. When a DDL statement involves the change of an implicit table group, the extended DDL statement is recorded in the binary log of the primary cluster.
Example 1
The following SQL statement to create a table is submitted:
create table if not exists tb1 (
a int PRIMARY KEY,
b int,
c int,
d varchar(10) UNIQUE,
INDEX b(b),
INDEX b_2(b),
KEY b_3 (b),
KEY b_4 (b),
UNIQUE KEY b_5 (b),
UNIQUE KEY b_6 (b),
UNIQUE INDEX b_7 (b),
UNIQUE INDEX b_8 (b),
INDEX g1(b),
KEY g2 (b),
UNIQUE KEY g3 (b),
UNIQUE INDEX g4 (b)
) DEFAULT CHARACTER SET = utf8mb4 DEFAULT COLLATE = utf8mb4_general_ci;Example 2
The following SQL statement to modify a partition is submitted:
ALTER TABLE tb1 MERGE PARTITIONS p1, p2 TO p12;The following extended SQL statement is recorded in the binary log:
ALTER TABLE tb1 MERGE PARTITIONS p1, p2 TO p12 WITH TABLEGROUP=tg29 IMPLICIT;Multi-stream replication
In single-stream replication mode, the DDL statements of the primary cluster are replicated to the secondary clusters one by one based on the sequence in the binary log. However, in multi-stream replication scenario, you need to consider coordinating different replication links in DDL replication. Each replication link must wait for other replication links after receiving a DDL statement. The DDL statement can be replicated to secondary clusters only after all links receive it. Otherwise, inconsistency between DML traffic and schemas will occur, and exceptions or data errors are thrown.
For multi-stream replication, PolarDB-X provides the distributed DDL replication engine to implement DDL replication consistency in distributed scenarios using efficient multi-link coordination algorithm.

Limits
Limit 1
PolarDB-X allows you to use LOCALITY to specify the storage location. This feature allows you to include the DN node ID in DDL statements. However, PolarDB-X does not support the association mapping between the DN nodes on the primary cluster and secondary clusters. Therefore, when the DDL statements that contain such SQL statements are duplicated to downstream clusters, DN-related information is removed from the SQL statements. In this case, you can log on to secondary clusters and manually adjust the partition distribution.
Example 1
// The following SQL statement is executed on the primary cluster: CREATE TABLE test_pg3 ( id int ) DEFAULT CHARSET = utf8mb4 DEFAULT COLLATE = utf8mb4_general_ci PARTITION BY RANGE (id) ( PARTITION p0 VALUES LESS THAN (1000) LOCALITY 'dn=xdevelop-240524092100-31ef-bngl-dn-1', PARTITION p1 VALUES LESS THAN (2000) LOCALITY 'dn=xdevelop-240524092100-31ef-bngl-dn-1' ) // The following SQL statement is duplicated to secondary clusters: create table test_pg3 ( id int ) DEFAULT CHARACTER SET = utf8mb4 DEFAULT COLLATE = utf8mb4_general_ci PARTITION BY RANGE (id) ( PARTITION p0 VALUES LESS THAN (1000), PARTITION p1 VALUES LESS THAN (2000) ) WITH TABLEGROUP = tg3778 IMPLICITExample 2
// The following SQL statement is executed on the primary cluster: ALTER TABLE special_dml_test1 MOVE PARTITIONS (p2, p4, p6, p8) TO 'xdevelop-240524092100-31ef-bngl-dn-0'; // The following SQL statement is duplicated to secondary clusters: ALTER TABLE special_dml_test1;
Limit 2
PolarDB-X supports the SET PARTITION_HINT statement to specify SQL statements to be executed on the specified partitions. In the GDN replication scenario, the SET PARTITION_HINT statement cannot be passed through to secondary clusters. After you execute this statement to explicitly write data to the specified partitions on the primary node, it is not guaranteed that the data is written to the same partitions on secondary clusters.