When you need to perform full-text search or complex analysis on business data inPolarDB for MySQL, directly operating on the database may affect the stability of core business.PolarDB The AutoETL feature provided byPolarSearch node continuously and automatically synchronizes data from the read/write node to a PolarSearch node in the cluster, providing a one-stop data service. You can use search views or ETL stored procedures to create data synchronization links without deploying or maintaining additional ETL tools, achieving data synchronization while isolating search and analysis workloads from online transaction processing workloads.
When you use AutoETL to create a link, you authorize the AutoETL engine to access PolarDB data for data synchronization by default.
Overview
AutoETL is the built-in data synchronization capability ofPolarDB for MySQL. It enables automatic data flow between different types of nodes in the same cluster. The current version only supports synchronization fromPolarDB for MySQL to a PolarSearch node in the same cluster for high-performance search and analysis.
AutoETL provides two methods to create data synchronization links:
Search view: Use the
CREATE SEARCH VIEWsyntax to define data synchronization logic in standard SQL. Suitable for most single-table synchronization and multi-table aggregation scenarios. The system automatically handles the underlying connection details.ETL stored procedure (
dbms_etl.sync_by_sql): Use Flink SQL-compatible syntax to define complex data cleaning, transformation, and aggregation logic through stored procedures.
Scope of application
Before using AutoETL, ensure the following requirements are met:
Cluster version:
Search view:
MySQL 8.0.1. The revision version must be 8.0.1.1.54 or later.
MySQL 8.0.2. The revision version must be 8.0.2.2.34 or later.
ETL stored procedure (sync_by_sql):
MySQL 8.0.1. The revision version must be 8.0.1.1.52 or later.
MySQL 8.0.2. The revision version must be 8.0.2.2.33 or later.
Binlog: The cluster must haveEnable binary logging enabled.
Synchronization direction: Only synchronization fromPolarDB for MySQL to aPolarSearch node.
DDL limitations: When performing DDL operations on source tables that have search views or ETL stored procedures, follow specific rules to avoid synchronization interruption. Some incompatible changes require rebuilding the search view. For more information, see DDL change rules and best practices.
Data types: The
BITtype and spatial data types such asGEOMETRY、POINT、LINESTRING、POLYGON、MULTIPOINT、MULTILINESTRING、MULTIPOLYGON、GEOMETRYCOLLECTIONare not supported for synchronization.Search view query limitations: Search views currently only support defining synchronization semantics and do not support data queries. To query data, connect to the PolarSearch node directly.
Computing resources: AutoETL uses CU as the computing unit. By default, the number of CUs in a cluster isPolarSearch nodetwice the sum of the CPUs of all nodes. You can view the current CU usage of the cluster on the page, on theAutoETLtab.
Search views
A search view is a declarative data synchronization mechanism provided by AutoETL. You can use standard SQL syntax to create a search view, and the system automatically establishes a continuous data synchronization link from the source table to the PolarSearch node.
Create a search view
Syntax
CREATE SEARCH VIEW view_name [(column_list, PRIMARY KEY (pk_column_list))]
[WITH (option_list)]
AS select_statement;Parameters
Parameter | Required | Description |
| Yes | The name of the search view, which is also the name of the target index on the PolarSearch node. |
| No | Manually define the columns of the search view. Separate multiple columns with Note In single-table synchronization, you do not need to specify |
| No | The primary key columns of the search view. The structure corresponds to the index mapping of the PolarSearch node, so If not specified, the first column of |
| No | The synchronization configuration explicitly specified when creating the search view, such as synchronization parallelism, compute resource usage per sync worker, and destination index name. Separate multiple configurations with |
| Yes | The |
Usage limits and notes
The source table must contain a primary key or a unique key.
You must have the
ALTERpermission on all source tables in the search view, and theSELECTpermission on the related columns or the entire table.After a search view is created, new columns added to the source table are not automatically synchronized. To synchronize new columns, see Modify a search view.
To use a custom destination index configuration, you can first create the index on the PolarSearch node and manually create the index and define its configuration, and then create a search view. If the destination index does not exist at creation time, the system creates it automatically.
To configure advanced synchronization parameters for multi-table aggregation or complex queries, such as JSON field conversion and routing fields, see AutoETL parameter configuration and best practices.
Data preparation
You can create the test data used in the following examples by executing the following SQL statements inPolarDB for MySQL.
CREATE DATABASE IF NOT EXISTS db1;
CREATE DATABASE IF NOT EXISTS db2;
USE db1;
CREATE TABLE IF NOT EXISTS t1 (
id INT PRIMARY KEY,
c1 VARCHAR(100),
c2 VARCHAR(100)
);
INSERT INTO t1(id, c1, c2) VALUES
(1, 'apple', 'red'),
(2, 'banana', 'yellow'),
(3, 'grape', 'purple');
USE db2;
CREATE TABLE IF NOT EXISTS t2 (id INT PRIMARY KEY, c2 INT);
INSERT INTO t2(id, c2) VALUES (1, 111), (2, 222), (4, 444);Examples
Full table synchronization: Join
db1.t1to PolarSearch. The view nameview_testis also the target index name in PolarSearch.CREATE SEARCH VIEW view_test AS SELECT * FROM db1.t1;Specified column synchronization: Synchronize only the
c1andc2columns, and manually define column types and the primary key.CREATE SEARCH VIEW view_test1 AS SELECT c1, c2 FROM db1.t1;Specified synchronization parameters: Specify synchronization configuration through the
WITHclause when creating a search view. The following example synchronizes thedb1.t1c1andc2columns to PolarSearch and sets the synchronization parallelism to 2.CREATE SEARCH VIEW view_test6 WITH ('parallelism' = '2') AS SELECT c1, c2 FROM db1.t1;Conditional filter synchronization: Synchronize only data that meets the
WHEREcondition.CREATE SEARCH VIEW view_test2 AS SELECT id, c1, c2 FROM db1.t1 WHERE c1 > 10;Multi-table JOIN: Join
db1.t1anddb2.t2throughidand synchronize the result to PolarSearch.CREATE SEARCH VIEW view_test3(id, c1, c2) AS SELECT t1.id, t1.c1, t2.c2 FROM db1.t1 AS t1 LEFT JOIN db2.t2 AS t2 ON t1.id = t2.id;Multi-table UNION: Merge multiple tables with the same structure and synchronize. Each
SELECTstatement must have the same number and types of columns.CREATE SEARCH VIEW view_test4(id, c2) AS SELECT id, c2 FROM db1.t1 UNION ALL SELECT id, c2 FROM db2.t2;Group aggregation: Synchronize data after group aggregation. When using
GROUP BY, you must manually define columns and the primary key.CREATE SEARCH VIEW view_test5 (id, max_c) AS SELECT t1.id, MAX(t1.c1) AS max_c FROM db1.t1 GROUP BY t1.id;
Verify data
Check the synchronization status of the search view:
SHOW SEARCH VIEW STATUS;When the status is active, the search view data synchronization is running normally. Connect to the PolarSearch node, using an Elasticsearch-compatible REST API to verify data:
# Replace <user>:<password> with the PolarSearch node credentials and <polarsearch_endpoint> with the PolarSearch node endpoint and port
curl -u <user>:<password> -X GET "http://<polarsearch_endpoint>/view_test/_search"Manage search views
You can use the following commands to view created search views, or to stop, restart, or rebuild data synchronization. All commands must be executed in a database client after connecting to the cluster.
View the status of all search views
SHOW SEARCH VIEW STATUS;The result is as follows. When the status is active, the search view data synchronization is running normally.
+------------+--------+----------+---------+---------------------+---------------------+
| View Name | Type | Status | Message | Created_at | Updated_at |
+------------+--------+----------+---------+---------------------+---------------------+
| view_test | search | active | | 2026-03-18 18:44:12 | 2026-03-18 18:51:37 |
+------------+--------+----------+---------+---------------------+---------------------+View the CREATE statement of a specified search view
SHOW CREATE SEARCH VIEW view_test;The result is as follows:
+-----------+------------------------------------------------------+
| View Name | Create Search View |
+-----------+------------------------------------------------------+
| view_test | CREATE SEARCH VIEW view_test AS SELECT * FROM db1.t1 |
+-----------+------------------------------------------------------+Stop a search view
When you need to modify or rebuild the target index on the PolarSearch node, to avoid synchronization write errors, you can first stop the search view data synchronization. After the index modification on the PolarSearch node node is complete, restart the search view.
ALTER SEARCH VIEW view_test STOP;Restart a search view
Restart a stopped or running search view.
ALTER SEARCH VIEW view_test RESTART;Rebuild a search view
Re-read all data from the source table and write it to the PolarSearch node.
A rebuild re-scans all data in the source table. This may take a long time if the data volume is large.
A rebuild does not clear the existing index data on the PolarSearch node. Instead, the data is directly overwritten.
ALTER SEARCH VIEW view_test REBUILD;Delete a search view
Deleting a search view is a high-risk operation. Confirm before proceeding. This operation stops the search view data synchronization and cleans up related resources,but does not delete the index data in PolarSearch.
DROP SEARCH VIEW view_name;The system handles deletion differently depending on the search view status:
activesearch view: The status first changes todropping. After the system completes resource cleanup and target index data deletion, the status changes todropped.droppedsearch view: The system completely removes the search view information.Search views in other statuses: The system does not support deletion.
Modify a search view
After a search view is created, you can adjust its runtime parameters or modify its synchronization logic, such as adding synchronization fields or changing query conditions. AutoETL provides three modification methods:
To adjust only runtime parameters such as parallelism and compute resource usage, use Parameter modification. No changes to the synchronization SQL are required.
When modifying the synchronization logic, preferIn-place SQL modification. If the SQL definitions are compatible, synchronization continues from the original checkpoint without full re-synchronization. You can refer toDDL change rules and best practices to determine whether the SQL definitions are compatible.
If the SQL definitions are incompatible and in-place modification is not possible, use “new index + new search view”modification to rebuild.
Parameter modification
For a running search view, you can modify its runtime parameters using the following syntax. AutoETL automatically reads the new configuration and restarts the search view.
Syntax
ALTER SEARCH VIEW view_name UPDATE WITH (new_option_list);Examples
view_test Adjust the parallelism to 8, CPU per worker to 4, and concurrency per worker to 8:
ALTER SEARCH VIEW view_test UPDATE WITH ('parallelism' = '8', 'link.tm.cpu' = '4', 'link.tm.slots' = '8');In-place SQL modification
In-place SQL modification directly modifies the synchronization SQL of an existing search view without creating a new PolarSearch index or search view or switching business queries, reducing full synchronization time. If the SQL definitions are compatible, synchronization continues from the original checkpoint. If not, the modification fails, and the system automatically rolls back to the pre-modification definition and restarts the search view.
Syntax
ALTER SEARCH VIEW view_name UPDATE
[TO (column_list, PRIMARY KEY (pk_column_list))]
AS new_select_statement;Examples
Synchronize new columns from the source table: A full-table search view does not automatically synchronize new columns added to the source table after the view is created. After the source table
db1.t1adds new columns, execute the following statement to synchronize the new column data to PolarSearch.ALTER SEARCH VIEW view_test UPDATE;Adjust synchronized columns: Originally synchronize the
c1andc2column. Change to synchronize only thec1column.ALTER SEARCH VIEW view_test UPDATE AS SELECT c1 FROM db1.t1;Adjust filter conditions: Join
WHEREcondition fromc1 > 10toc1 > 20.ALTER SEARCH VIEW view_test UPDATE AS SELECT id, c1, c2 FROM db1.t1 WHERE c1 > 20;
“new index + new search view”modification
If the SQL definitions are incompatible and in-place modification is not possible, use“new index + new search view” method to rebuild, ensuring business queries are not affected.
Create a new search view and synchronize to a new PolarSearch index.
through
SHOW SEARCH VIEW STATUSto check the status of the new search view. When the synchronization latency drops to 0 to 1 second, switch the business query logic from the old index to the new index.Delete the old search view.
For the impact of source table DDL changes on search views and detailed modification practices, see DDL change rules and best practices.
ETL stored procedure (sync_by_sql)
For scenarios requiring complex transformation, aggregation, or computation, you can use the CALL dbms_etl.sync_by_sql stored procedure to define data synchronization logic using Flink SQL-compatible syntax.
Create a synchronization link
Syntax
Before callingdbms_etl.sync_by_sql, you can use the session variables (such asAutoETL parameter configuration and best practices) fromesl_link_options、esl_sink_options to set the link synchronization configuration. The AutoETL engine automatically reads these variables when creating the link.
CALL dbms_etl.sync_by_sql("search", "<sync_sql>");Examples
The connection information for the source and destination tables, such as host addresses, ports, and credentials, is automatically configured by the system. You do not need to manually specify it in the WITH clause.
CALL dbms_etl.sync_by_sql("search", "
-- Step 1: Define the PolarDB source table
CREATE TEMPORARY TABLE `db1`.`t1` (
`id` BIGINT,
`c1` STRING,
PRIMARY KEY (`id`) NOT ENFORCED
) WITH (
'connector' = 'mysql',
'database-name' = 'db1',
'table-name' = 't1'
);
-- Step 2: Define the PolarSearch destination table
CREATE TEMPORARY TABLE `dest` (
`id` BIGINT,
`max_c` STRING,
PRIMARY KEY (`id`) NOT ENFORCED
) WITH (
'connector' = 'opensearch',
'index' = 'dest'
);
-- Step 3: Define the computation and insert logic
INSERT INTO `dest`
SELECT
`t1`.`id`,
MAX(`t1`.`c1`)
FROM `db1`.`t1` AS `t1`
GROUP BY `t1`.`id`;
");Verify data
Connect to the PolarSearch node, using an Elasticsearch-compatible REST APIto query, verify that data has been synchronized.
# Replace <polarsearch_endpoint> with the PolarSearch node endpoint
curl -u <user>:<password> -X GET "http://<polarsearch_endpoint>/dest/_search"Manage synchronization links
You can use the following commands to view created synchronization links, or to stop, restart, or rebuild data synchronization. All commands must be executed in a database client after connecting to the cluster.
View all links
CALL dbms_etl.show_sync_link();View a specified link by ID
<sync_id> with the ID returned when the link was created.
CALL dbms_etl.show_sync_link_by_id('<sync_id>')\GDescription of the returned result:
*************************** 1. row ***************************
SYNC_ID: crb5rmv8rttsg
NAME: crb5rmv8rttsg
SYSTEM: search
SYNC_DEFINITION: db1.t1 -> dest
SOURCE_TABLES: db1.t1
SINK_TABLES: dest
STATUS: active -- Link status. active indicates normal operation
MESSAGE: -- If an error occurs, the error message is displayed here
CREATED_AT: 2024-05-20 11:55:06
UPDATED_AT: 2024-05-20 17:28:04
OPTIONS:...Stop a link
When you need to modify or rebuild the target index on the PolarSearch node, to avoid synchronization write errors, you can first stop the synchronization link. After the index modification on the PolarSearch node node is complete, restart the link.
CALL dbms_etl.stop_sync_link('<sync_id>');Restart a link
Restart a stopped or running synchronization link.
CALL dbms_etl.restart_sync_link('<sync_id>');Rebuild a link
Re-read all data from the source table and write it to the PolarSearch node.A rebuild re-scans all data in the source table. This may take a long time if the data volume is large. A rebuild does not clear the existing index data on the PolarSearch node. Instead, the data is directly overwritten.
CALL dbms_etl.rebuild_sync_link('<sync_id>');Delete a synchronization link
This operation stops data synchronization and cleans up related resources.
Deleting a synchronization link is a high-risk operation. Confirm before proceeding. This operation stops the link data synchronization and cleans up related resources,but does not delete the index data in PolarSearch.
CALL dbms_etl.drop_sync_link('<sync_id>');The system handlesdrop_sync_link deletion differently depending on the link status:
activelink: The status first changes todropping. After the system completes link resource and target index data cleanup, the status changes todropped.droppedlink: The system completely removes the link information.Links in other statuses: The system does not support deletion.
Modify a synchronization link
After a synchronization link is created, you can adjust its runtime parameters or modify its synchronization SQL. Similar to search views, AutoETL provides three modification methods:
To adjust only runtime parameters such as parallelism and compute resource usage, use Parameter modification. No changes to the synchronization SQL are required.
When modifying the synchronization SQL, preferIn-place SQL modification. If the SQL definitions are compatible, synchronization continues from the original checkpoint without full re-synchronization. You can refer toDDL change rules and best practices to determine whether the SQL definitions are compatible.
If the SQL definitions are incompatible and in-place modification is not possible, use “new index + new link”modification to rebuild.
Parameter modification
For a running synchronization link, you can first set new link configuration through the session variableesl_link_options, and then calldbms_etl.update_sync_link to apply the configuration. AutoETL automatically reads the newesl_link_options configuration and restarts the synchronization link.
Syntax
SET esl_link_options = "<new_option_list>";
CALL dbms_etl.update_sync_link('<sync_id>', '');Examples
link8f4228x2uq12z Adjust the parallelism to 8, CPU per worker to 4, and concurrency per worker to 8:
SET esl_link_options = "'parallelism' = '8', 'link.tm.cpu' = '4', 'link.tm.slots' = '8'";
CALL dbms_etl.update_sync_link('8f4228x2uq12z', '');In-place SQL modification
In-place SQL modification directly modifies the synchronization of an existing link SQL, without creating a new PolarSearch index or link or switching business queries, reducing full synchronization time. Before and after the modification, the SQL definitions are compatible, synchronization continues from the original checkpoint; if they are not compatible, the modification fails, the system automatically rolls back to the pre-modification synchronization definition and restarts the link.
Syntax
<new_sync_sql> requires the complete new synchronization SQL. Its structure is the same as the synchronization SQL indbms_etl.sync_by_sql when the link was created.
CALL dbms_etl.update_sync_link('<sync_id>', '<new_sync_sql>');Examples
link8f4228x2uq12z filter condition toc1 > 20:
CALL dbms_etl.update_sync_link('8f4228x2uq12z', "
CREATE TEMPORARY TABLE `db1`.`t1` (
`id` BIGINT,
`c1` STRING,
PRIMARY KEY (`id`) NOT ENFORCED
) WITH (
'connector' = 'mysql',
'database-name' = 'db1',
'table-name' = 't1'
);
CREATE TEMPORARY TABLE `dest` (
`id` BIGINT,
`c1` STRING,
PRIMARY KEY (`id`) NOT ENFORCED
) WITH (
'connector' = 'opensearch',
'index' = 'dest'
);
INSERT INTO `dest` SELECT `id`, `c1` FROM `db1`.`t1` WHERE `c1` > 20;
");“new index + new link”modification
If the SQL definitions are incompatible and in-place modification is not possible, use“new index + new link” method to rebuild, ensuring business queries are not affected.Take modifying link A as an example:
Create link B based on the new synchronization SQL and synchronize to a new PolarSearch index.
through
CALL dbms_etl.show_sync_link_by_id('<sync_id>')to check the status of link B. When the synchronization latency of link B drops to 0 to 1 second, switch the business query logic from the old index to the new index.After confirming that link B is running stably, execute
CALL dbms_etl.drop_sync_link('<sync_id>')to delete the old link A.