All Products
Search
Document Center

ApsaraDB RDS:HTAP-based automatic query routing

Last Updated:Oct 17, 2025

If your business requires both high-concurrency online transaction processing (OLTP) and complex online analytical processing (OLAP), you can add DuckDB-based analytical read-only instances to your RDS for MySQL instance. This setup allows you to implement HTAP-based query routing through a database proxy. OLAP queries are routed to the DuckDB-based analytical read-only instances, while OLTP queries are routed to the primary RDS instance or regular read-only instances. This architecture enables enterprise users efficiently handle HTAP queries.

Introduction

The HTAP-based query routing solution for RDS for MySQL leverages the distinct advantages of different storage engines. A database proxy automatically directs requests to the most suitable instance type based on the estimated execution cost of SQL queries, achieving workload isolation and performance optimization.

Two routing methods are supported:

  • HTAP-based automatic query routing: Automatically routes OLAP and OLTP queries to columnstore or row-oriented instances based on the estimated SQL execution cost.

  • Manual routing by using hints: If automatic routing does not meet your expectations or your MySQL version does not support cost estimation, you can use hints to manually route SQL queries.

Usage notes

Before using HTAP-based automatic query routing, make sure that:

Note

If your instnace's minor engine version or database proxy version does not meet the requirements, update the minor engine version or upgrade the database proxy version.

Precautions

  • The latency threshold and consistency level of the database proxy also apply to the DuckDB-based read-only instances.

  • When you enable HTAP-based automatic query routing for a primary instance, theRead/Write Splitting Attribute of the instance's proxy endpoint must be set to Read/Write.

  • The read weights of DuckDB-based analytical read-only instances affect only the load balancing among these instances and do 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 requests are queued for processing.

  • If you select Custom for Read Weight Allocation, the read weight of new DuckDB-based analytical read-only instance is set to 0 by default and must be configured manually.

Note

You can configure the latency threshold, consistency level, read/write attribute, and read weight of database proxy based on your requirements. For more information, see Configure database proxy.

Enable HTAP-based automatic query routing

  1. Log on to the RDS console. In the left-side navigation pane, click Instances. In the top navigation bar, select the region where your primary RDS instance resides.

  2. On the Instances page, click the ID of the primary RDS instance (with a image icon).

  3. In the left-side navigation pane, click Database Proxy.

  4. In the Connection Information section, find the proxy endpoint and click Modify Configuration in the Actions column.

  5. In the panel that appears, enable Auto HTAP-based Routing and click OK.

Allocate read weights to DuckDB-based analytical read-only instances

If your RDS for MySQL instance is configured with multiple DuckDB-based analytical read-only instances, you can set a read weight for each of these instances as needed. By default, the read weight for a proxy endpoint is set to System-assigned. A higher read weight indicates that the instance processes more read requests.

  1. Log on to the RDS console. In the left-side navigation pane, click Instances. In the top navigation bar, select the region where your primary RDS instance resides.

  2. On the Instances page, click the ID of the primary RDS instance (with a image icon).

  3. In the left-side navigation pane, click Database Proxy.

  4. In the Connection Information section, find the proxy endpoint and click Modify Configuration in the Actions column.

  5. In the dialog box that appears, select Automatic Distribution for Read Weight Allocation.

    If you select Custom, the read weight of new DuckDB-based analytical read-only instance is set to 0 by default and must be configured manually.

  6. In the Read Weight for DuckDB-based Read-only Instance section, set the read weight for each DuckDB-based analytical read-only instance.

    For example, if a primary RDS instance has three DuckDB-based analytical read-only instances with read weights of 0, 100, and 200, respectively, only write requests are routed to the primary RDS instance. The three read-only instances handle read requests based on a 1:2 ratio.

    Note
    • The read weight can be an integer from 0 to 10,000.

    • If a DuckDB-based analytical read-only instance is deleted, its weight is automatically removed, and the weights of the other instances remain unchanged.

    • Modifications to this parameter take effect immediately without causing service interruptions. Both new and existing connections are routed based on the new weights.

Manually route queries by using hints

If automatic routing is not effective or your MySQL version does not support cost estimation, you can add a hint to your SQL statement to force a specific query route for the query.

  • Route a query to the DuckDB-based analytical read-only node.

    /*force_ap_nodes*/ SELECT COUNT(*) FROM <Table_name>;
  • Route a query to the primary RDS instance or regular read-only instance.

    SELECT /*+set_var(rds_cost_threshold_for_duckdb = 0)*/ COUNT(*) FROM <Table_name>;

Reference

Appendix: How HTAP-based automatic query routing works

  1. The database proxy receives a query and forwards it to a row-oriented instance, such as the primary RDS instance or a read-only instance.

  2. The optimizer of the row-oriented instance analyzes the query and estimates whether its execution cost exceeds a predefined threshold.

    • If the estimated cost is below the threshold, the query is executed on a row-oriented instance or between multiple regular read-only instances based on load balancing.

    • If the estimated cost is above the threshold, the query is routed to a DuckDB-based analytical read-only instance or between multiple DuckDB-based analytical read-only instances based on load balancing.