All Products
Search
Document Center

PolarDB:Search views and ETL stored procedures

Last Updated:Aug 27, 2026

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.

Note

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 VIEW syntax 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: TheBIT type and spatial data types such asGEOMETRY、POINT、LINESTRING、POLYGON、MULTIPOINT、MULTILINESTRING、MULTIPOLYGON、GEOMETRYCOLLECTION are 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 Settings and Management > Search Managementpage, 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

view_name

Yes

The name of the search view, which is also the name of the target index on the PolarSearch node.

column_list

No

Manually define the columns of the search view. Separate multiple columns with,.

Note

In single-table synchronization, you do not need to specifycolumn_list. The original column names of the source table are used by default.

pk_column_list

No

The primary key columns of the search view. The structure corresponds to the index mapping of the PolarSearch node, sopk_column_list specifies the index document ID on the PolarSearch node.

If not specified, the first column ofcolumn_list is used as the document ID by default. In single-table synchronization, the primary key of the source table is used as the document ID by default.

option_list

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,. If not specified, system default values are used. For configurable parameters and values, see AutoETL parameter configuration and best practices.

select_statement

Yes

TheSELECT statement that defines the data source and synchronization logic. This statement retrieves data from the source table and stores the result inPolarSearch. Supports single-table queries, multi-tableJOIN、UNION ALLandGROUP BY operations.

Usage limits and notes

  • The source table must contain a primary key or a unique key.

  • You must have the ALTER permission on all source tables in the search view, and the SELECT permission 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: Joindb1.t1 to PolarSearch. The view nameview_test is also the target index name in PolarSearch.

    CREATE SEARCH VIEW view_test AS SELECT * FROM db1.t1;
  • Specified column synchronization: Synchronize only the c1andc2 columns, 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 WITH clause when creating a search view. The following example synchronizes the db1.t1 c1andc2 columns 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 WHERE condition.

    CREATE SEARCH VIEW view_test2 AS SELECT id, c1, c2 FROM db1.t1 WHERE c1 > 10;
  • Multi-table JOIN: Joindb1.t1anddb2.t2throughid and 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. EachSELECT statement 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 usingGROUP 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.

Important
  • 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

Important

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:

  • active search view: The status first changes todropping. After the system completes resource cleanup and target index data deletion, the status changes todropped.

  • dropped search 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 tabledb1.t1 adds 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 the c1column.

    ALTER SEARCH VIEW view_test UPDATE AS SELECT c1 FROM db1.t1;
  • Adjust filter conditions: JoinWHERE condition fromc1 > 10 toc1 > 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.

  1. Create a new search view and synchronize to a new PolarSearch index.

  2. throughSHOW SEARCH VIEW STATUS to 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.

  3. 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

Note

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

Note

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>')\G

Description 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:...

Delete a synchronization link

This operation stops data synchronization and cleans up related resources.

Important

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:

  • active link: The status first changes todropping. After the system completes link resource and target index data cleanup, the status changes todropped.

  • dropped link: 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:

Parameter modification

In-place SQL modification

<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.

“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:

  1. Create link B based on the new synchronization SQL and synchronize to a new PolarSearch index.

  2. throughCALL 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.

  3. After confirming that link B is running stably, executeCALL dbms_etl.drop_sync_link('<sync_id>') to delete the old link A.

FAQ

What are the differences between search views and ETL stored procedures (sync_by_sql)?

The core differences lie in the use scenarios and complexity:

  • Search views: Uses standard SQL syntax (CREATE SEARCH VIEW). The system automatically handles underlying connection and synchronization details. No need to write Flink SQL. Suitable for most single-table synchronization and multi-table aggregation scenarios.

  • ETLstored procedure: Uses Flink SQL-compatible syntax (CALL dbms_etl.sync_by_sql). Suitable for scenarios requiring complex data cleaning, transformation, and aggregation, providing full Flink SQL control capabilities. Connection configuration for source and destination tables is automatically handled by the system.