If your business requires handling both high-concurrency online transactional processing (OLTP) and complex online analytical processing (OLAP) workloads, you can add a DuckDB-based analytical read-only instance to your RDS for MySQL instance. Using a database proxy, you can enable automatic HTAP query routing or manual routing with a hint. This feature routes OLAP queries to the DuckDB-based analytical read-only instance and OLTP queries to the primary instance or regular read-only instances, helping you efficiently integrate transaction processing and data analysis.
Overview
The HTAP query routing solution for RDS for MySQL uses the distinct advantages of different storage engines. A database proxy automatically routes requests to the most suitable instance type based on the estimated execution cost of SQL queries. This helps isolate workloads and optimize performance.
Instance types
-
Row-oriented instance: The RDS for MySQL primary instance and regular read-only instances. These instances use the InnoDB engine and are ideal for processing high-concurrency OLTP read and write requests.
-
Columnstore instance: The DuckDB-based analytical read-only instance. This instance uses the DuckDB engine and is suitable for complex OLAP analytical queries.
Routing methods
RDS for MySQL supports the following two query routing methods:
-
Automatic HTAP query routing: Automatically routes OLAP and OLTP queries to columnstore or row-oriented instances based on the estimated execution cost of the SQL statement.
-
Manual routing with a hint: If automatic routing is not effective, or if your MySQL version does not support cost estimation, you can use a
hintto manually specify the routing destination.
SQL execution cost
When using automatic routing, you can run the SHOW STATUS LIKE 'Last_query_cost' command to check the estimated execution cost of an SQL statement. This helps you understand the basis for routing decisions. We recommend that you run the EXPLAIN statement before you check the execution cost.
Example
View the estimated execution cost of the SELECT COUNT(*) FROM sbtest5.sbtest1 statement:
EXPLAIN SELECT COUNT(*) FROM sbtest5.sbtest1;
SHOW STATUS LIKE 'Last_query_cost';
-- Example result:
+-------------------+---------------+
| Variable_name | Value |
+-------------------+---------------+
| Last_query_cost | 84454.999000 |
+-------------------+---------------+
The result shows that the estimated execution cost of the SQL statement is 84454.999000. The system uses this cost value to determine whether to route the query to a columnstore instance.
Prerequisites
To use automatic HTAP query routing, the primary instance must meet the following conditions:
-
The instance runs MySQL 8.0 with a minor engine version of 20250731 or later, or MySQL 5.7 with a minor engine version of 20260228 or later.
-
A DuckDB-based analytical read-only instance has been added.
-
The database proxy feature is enabled, and the database proxy version is 2.25.8 or later.
To upgrade the MySQL minor engine version and the database proxy version, see Upgrade the minor engine version and Upgrade the minor engine version of a database proxy.
Usage notes
-
The latency threshold and consistency level of the database proxy also apply to DuckDB-based analytical read-only instances.
-
The read weight of DuckDB-based analytical read-only instances affects only the load balancing among these instances and does not influence the routing logic between row-oriented and columnstore instances.
-
If all DuckDB-based analytical read-only instances are at full capacity, subsequent analytical queries are queued for processing on those instances.
-
After you set the read weight for the proxy endpoint to Custom, the read weight of any new DuckDB-based analytical read-only instance added to the primary instance defaults to 0 and must be configured manually.
You can flexibly configure the latency threshold, consistency level, read/write attribute, and read weights of the database proxy. For more information, see Configure a database proxy.
Automatic HTAP query routing
Enable automatic query routing
-
Log on to the RDS console. In the navigation pane on the left, click Instances. In the top navigation bar, select the region of your instance.
-
On the Instances page, click the ID of the target primary instance. The primary instance is marked with an
icon. -
In the navigation pane on the left, click Database Proxy.
-
In the Connection Information section, find the target proxy endpoint and click Modify Configuration in the Actions column.
-
In the dialog box that appears, enable Automatic row and column separation for HTAP and click OK.
Allocate read weights for DuckDB instances
If your RDS for MySQL instance has multiple DuckDB-based analytical read-only instances, you can set a read weight for each instance based on your business requirements. By default, the read weight for the proxy endpoint is Automatic. A higher read weight means the instance processes more read requests.
-
Log on to the RDS console. In the navigation pane on the left, click Instances. In the top navigation bar, select a region.
-
On the Instances page, click the ID of the target primary instance, which is marked with an
icon. -
In the navigation pane on the left, click Database Proxy.
-
In the Connection Information section, find the target proxy endpoint and click Modify Configuration in the Actions column.
-
In the dialog box that appears, set Read Weight Allocation to Custom.
After you set it to Custom, the read weight of any new DuckDB-based analytical read-only instance added to this primary instance defaults to 0 and must be configured manually.
-
In the DuckDB Analytical Read-Only Instance Read Weight Allocation section, set the read weight for each DuckDB-based analytical read-only instance as needed.
For example, assume a primary instance and its three DuckDB-based analytical read-only instances have their read weights set to 0, 100, 200, and 200, respectively. This means the primary instance does not process read requests (write requests are still automatically sent to it), and the three read-only instances process read requests at a 1:2:2 ratio.
Note-
The read weight can be set to a value from 0 to 10,000.
-
If a DuckDB-based analytical read-only instance is deleted, its weight is automatically removed. The weights of the other instances remain unchanged.
-
Changes to this parameter take effect immediately and do not cause service interruptions. Existing connections are not dropped. Both new and existing connections are routed based on the new weights.
-
Configure the SQL execution cost threshold
When you enable automatic HTAP query routing, the SQL execution cost threshold defaults to 500,000. In most cases, you can use this default value to route database requests:
-
Requests with an estimated cost below the SQL execution cost threshold are routed to a row-oriented instance (the primary instance or a regular read-only instance).
-
Requests with an estimated cost above the SQL execution cost threshold are routed to a columnstore instance (a DuckDB-based analytical read-only instance).
If you need to set a custom threshold that better suits your business requirements, perform the following steps:
-
Estimate the SQL execution cost based on your business requirements.
-
Configure the SQL execution cost threshold:
-
Log on to the RDS console. In the navigation pane on the left, click Instances. In the top navigation bar, select a region.
-
On the Instances page, click the ID of the target primary instance, which is marked with an
icon. -
In the navigation pane on the left, click Database Proxy.
-
In the Connection Information section, find the target proxy endpoint and click Modify Configuration in the Actions column.
-
In the dialog box, modify the SQL Execution Cost Threshold for HTAP Automatic Query Routing and click OK.
-
Manual routing with a hint
If automatic routing performs poorly, or if cost estimation is unavailable for your MySQL version, you can add a hint to an SQL statement to force a specific query route. The hint affects only the current SQL statement.
-
Force routing to a columnstore instance (DuckDB-based analytical read-only instance)
/*force_ap_nodes*/ SELECT COUNT(*) FROM <target_table_name>; -
Force routing to a row-oriented instance (primary instance or regular read-only instance)
SELECT /*+set_var(rds_cost_threshold_for_duckdb = 0)*/ COUNT(*) FROM <target_table_name>;
Related documents and APIs
-
Add a DuckDB-based analytical read-only instance to an RDS for MySQL high-availability instance
-
Related APIs
-
DescribeDBProxy: Queries the details of a database proxy.
-
DescribeDBProxyEndpoint: Queries information about a proxy endpoint.
-
ModifyDBProxyEndpoint: Configures the access policy of a proxy endpoint.
-
Appendix: Automatic HTAP query routing principles
-
The database proxy receives a query and forwards it to a row-oriented instance, such as the primary instance or a regular read-only instance.
-
The optimizer in the row-oriented instance analyzes the query and estimates whether its execution cost exceeds the configured threshold.
-
If the estimated execution cost is below the SQL execution cost threshold, the query is executed on a row-oriented instance. If multiple regular read-only instances exist, the query is routed based on load balancing rules.
-
If the estimated execution cost is above the SQL execution cost threshold, the query is executed on a columnstore instance. If multiple columnstore instances exist, the query is routed based on load balancing rules.
-