When you perform DDL operations on source tables that have a search view or an ETL stored procedure (sync_by_sql), different types of changes affect the synchronization link differently. This topic describes the impact of each DDL operation and provides best practices for rebuilding when necessary.
DDL impact on source tables
For information about DDL operations, see DDL operation guide for PolarDB for MySQL. The following table describes how common DDL operations on source tables affect the synchronization link.
Change type | Operation | Synchronization status | Description |
Column changes | Drop a column | Normal | Existing data retains the values of the dropped column. In incremental data, the field value is |
Add a column | Normal | The new column is not automatically added to the synchronization link. To add the column to the link, see AutoETL change practices. | |
Modify a column type | Depends on the type | Compatible types (for example, Incompatible types: the link becomes unavailable. You must rebuild the link. | |
Rename a column | Disrupted | The link uses column names from creation time. After a rename, the link cannot identify the renamed source table column. You must rebuild the link. | |
Other (reorder columns, modify default values, modify comments, extend VARCHAR length, modify character sets, modify auto-increment properties, modify NULL constraints, etc.) | Normal | These operations do not affect synchronization. | |
Index changes | Add, drop, or modify a secondary index | Normal | Secondary index changes do not affect synchronization. |
Drop or modify the primary key index | Disrupted | The link depends on the source table primary key for data synchronization. After you change the primary key, you must rebuild the link. | |
Table changes |
| Disrupted | The link cannot detect |
| Disrupted | The link does not recognize the new table name. Incremental data synchronization stops. | |
Other ( | Normal | These operations do not affect synchronization. | |
Partitioned table changes | Convert to a partitioned table, add a partition, merge partitions, repartition, analyze a partition, check a partition, optimize a partition, rebuild a partition, convert to a non-partitioned table, use local indexes, etc. | Normal | These operations do not affect synchronization. |
| Disrupted | The link cannot detect these operations. To delete data and synchronize the change to PolarSearch, use | |
| Disrupted | The link cannot detect direct data replacement or repair in specified partitions. Other partitions are unaffected. We recommend that you rebuild the link after these operations. |
AutoETL change practices
When you need to change the synchronization structure of a search view or an ETL stored procedure (for example, add synchronization fields), first determine whether the change can be performed in place:
If in-place changes are supported, directly update the SQL definition of the search view or ETL stored procedure. Synchronization resumes from the original offset without a full resynchronization.
If in-place changes are not supported, rebuild by using the "new index + new link" approach. After the new search view or ETL stored procedure completes data synchronization and verification, switch your application query traffic to the new index.
Whether in-place changes are supported
The following table lists common search view or ETL stored procedure changes and whether they support in-place changes.
Change type | Applicable scenario | In-place change supported | Description |
Modify runtime parameters | Single-table synchronization / Multi-table aggregation | Yes | Adjusting parameters for synchronization resources and concurrency does not change computation semantics. In-place changes are supported. |
Modify | Single-table synchronization / Multi-table aggregation | Yes | Modifying filter conditions does not update existing data that has been synchronized to PolarSearch nodes. To clean up existing data, rebuild the link. |
Add synchronization columns | Single-table synchronization | Yes | The new column applies only to incremental data. Historical data is not backfilled. To backfill all data, rebuild the link. |
Remove synchronization columns | Single-table synchronization | Yes | The removed columns in PolarSearch nodes stop being updated. |
Modify the primary key of PolarSearch node indexes | Single-table synchronization / Multi-table aggregation | No. Rebuild required. | The primary key is also the document ID in PolarSearch. The change is incompatible. |
Add or remove | Multi-table aggregation | No. Rebuild required. | The synchronization structure changes. A full recalculation is required. |
Add or remove | Multi-table aggregation | No. Rebuild required. | The aggregation structure changes. Historical aggregation results cannot be reused. |
Add or remove | Multi-table aggregation | No. Rebuild required. | The synchronization structure changes. A full recalculation is required. |
Convert between single-table synchronization and multi-table aggregation | Single-table synchronization / Multi-table aggregation | No. Rebuild required. | The synchronization logic are entirely changed. |
Change the data type of primary key / | Single-table synchronization / Multi-table aggregation | No. Rebuild required. | After a key column type change, the original synchronization state cannot be reused. |
In-place changes
Modify the SQL logic in the existing link and start the link by using the existing link state. For more information, see Search views - Modify a search view and ETL stored procedures (sync_by_sql) - Modify a synchronization link.
Search view syntax:
ALTER SEARCH VIEW view_name UPDATE [WITH (option_list)] [TO (column_list, PRIMARY KEY (pk_column_list))] AS new_select_statement;ETL stored procedure syntax:
SET esl_link_options = "<new_option_list>"; -- If new_sync_sql is empty, the existing sync SQL is retained CALL dbms_etl.update_sync_link('<sync_id>', '<new_sync_sql>');
"New index + new link" changes
The "new index + new link" approach is the most versatile change method. The link rescans data and writes it to the PolarSearch node. After the new search view or ETL stored procedure completes data synchronization and verification, switch your application query traffic to the new index.
Example:
Add a field to the shop.user table and rebuild the search view. Assume the original search view synchronizes the shop.user table (with id, name, phone, gmt_create columns) to the user_v1 index. You need to add the membership_level column without disrupting online queries.
Create a new index: Create a new index named
user_v2on the PolarSearch node, and include the newmembership_levelfield in its mapping.PUT user_v2 { "mappings": { "properties": { "id": { "type": "keyword" }, "name": { "type": "text", "fields": { "keyword": { "type": "keyword" } } }, "phone": { "type": "keyword" }, "gmt_create": { "type": "date" }, "membership_level": { "type": "integer" } } } }Modify the source table: Add the new column to the
usertable in the source PolarDB for MySQL.ALTER TABLE shop.user ADD COLUMN membership_level TINYINT NOT NULL DEFAULT 0 COMMENT 'Membership level';Create a new search view: Create a new search view to synchronize data from the
shop.usertable to theuser_v2index.CREATE SEARCH VIEW user_v2 AS SELECT id, name, phone, gmt_create, membership_level FROM shop.user;Verify and switch over: Run
SHOW SEARCH VIEW STATUSto check the status of the new search view. After the synchronization latency drops to approximately 0 to 1 second, verify the data in the new index. After verification, switch your application query traffic to the newuser_v2index.Clean up old resources:: After the new search view runs stably, drop the old search view and the
user_v1index。DROP SEARCH VIEW user_v1;