All pages
Powered by GitBook
1 of 1

Loading...

Routing Statements with MaxScale's Read/Write Split Router

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:

    • When is set to OFF.

    • When is executed.

    • When is executed.

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

  • statements that create prepared statements

  • Internal client commands, such as QUIT, PING, STMT RESET, and CHANGE USER.

This page is: Copyright © 2025 MariaDB. All rights reserved.

REPLACE

  • REPLACE ... RETURNING

  • LOAD DATA INFILE

  • CREATE TABLE

  • ALTER TABLE

  • DROP TABLE

  • CREATE VIEW

  • ALTER VIEW

  • DROP VIEW

  • CREATE SEQUENCE

  • ALTER SEQUENCE

  • DROP SEQUENCE

  • CREATE TRIGGER

  • DROP TRIGGER

  • CREATE PROCEDURE

  • ALTER PROCEDURE

  • DROP PROCEDURE

  • CREATE FUNCTION

  • ALTER FUNCTION

  • DROP FUNCTION

  • CREATE USER

  • ALTER USER

  • DROP USER

  • CREATE ROLE

  • DROP ROLE

  • EXECUTE statements that execute prepared statements
  • SHOW COLLATION

  • SHOW COLUMNS

  • SHOW CREATE DATABASE

  • SHOW CREATE FUNCTION

  • SHOW CREATE PROCEDURE

  • SHOW CREATE SEQUENCE

  • SHOW CREATE TABLE

  • SHOW CREATE TRIGGER

  • SHOW CREATE USER

  • SHOW CREATE VIEW

  • SHOW DATABASES

  • SHOW ENGINES

  • SHOW TABLES

  • SHOW VARIABLES

  • INSERT
    INSERT ... RETURNING
    UPDATE
    DELETE
    CREATE DATABASE
    ALTER DATABASE
    DROP DATABASE
    autocommit
    BEGIN
    START TRANSACTION
    SELECT
    SHOW CHARACTER SET
    SET
    USE
    PREPARE
    SET SESSION autocommit=OFF;
    SELECT * FROM hq_sales.invoices WHERE branch_id=1;
    INSERT INTO hq_sales.invoices
       (customer_id, invoice_date, invoice_total, payment_method)
    VALUES
       (1, '2020-05-10 12:35:10', 1087.23, 'CREDIT_CARD');
    COMMIT;
    BEGIN;
    SELECT * FROM hq_sales.invoices WHERE branch_id=1;
    INSERT INTO hq_sales.invoices
       (customer_id, invoice_date, invoice_total, payment_method)
    VALUES
       (1, '2020-05-10 12:35:10', 1087.23, 'CREDIT_CARD');
    COMMIT;
    SELECT @@global.alter_algorithm;
    SELECT @@my_user_var;
    SHOW statements