Routing Statements with MaxScale's Read/Write Split Router
Understand the routing logic of the readwritesplit router. This guide explains how MaxScale identifies write statements for the primary and distributes reads to replicas.
The Read/Write Split Router (readwritesplit) uses well-defined rules to determine whether a statement can be routed to a replica server, or whether it needs to be routed to the primary server. Application designers must understand these rules to ensure that the router can properly load balance queries.
Statements Routed to the Primary Server
The following statements are routed to the primary server:
Queries that write to the database. For example, this includes, but is not limited to, the following statements:
Queries that modify the database (DDL) For example, this includes, but is not limited to, the following statements:
Queries within open transactions If the application uses explicit transactions, then all queries within the transaction will be routed to the primary server. Explicit transactions are used in the following cases:
For example, all queries will be routed to the primary server in this case:
And all queries will also be routed to the primary server in this case:
Queries using stored procedures
Queries using stored functions
Queries using user-defined functions (UDF)
Queries that use temporary tables
Statements Routed to a Replica Server
The following statements are routed to a replica server:
Queries that are read-only For example, this includes, but is not limited to, the following statements:
Queries that read system or user-defined variables For example, this includes, but is not limited to, the following statements:
For example, the following queries would be routed to a replica:
Queries using built-in functions
Statements Routed to All Servers
The following statements are routed to all servers:
statements, including those embedded in read-only statements
statements that create prepared statements
This page is: Copyright © 2025 MariaDB. All rights reserved.