arrow-left

All pages
gitbookPowered by GitBook
1 of 1

Loading...

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.

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

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

hashtag
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

hashtag
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

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

  • When is executed.

    statements that execute prepared statements

  • Internal client commands, such as QUIT, PING, STMT RESET, and CHANGE USER.
    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
    INSERTarrow-up-right
    INSERT ... RETURNINGarrow-up-right
    UPDATEarrow-up-right
    CREATE DATABASEarrow-up-right
    ALTER DATABASEarrow-up-right
    autocommitarrow-up-right
    BEGINarrow-up-right
    SELECTarrow-up-right
    SETarrow-up-right
    USEarrow-up-right
    PREPAREarrow-up-right
    spinner
    DELETEarrow-up-right
    REPLACEarrow-up-right
    REPLACE ... RETURNINGarrow-up-right
    LOAD DATA INFILEarrow-up-right
    DROP DATABASEarrow-up-right
    CREATE TABLEarrow-up-right
    ALTER TABLEarrow-up-right
    DROP TABLEarrow-up-right
    CREATE VIEWarrow-up-right
    ALTER VIEWarrow-up-right
    DROP VIEWarrow-up-right
    CREATE SEQUENCEarrow-up-right
    ALTER SEQUENCEarrow-up-right
    DROP SEQUENCEarrow-up-right
    CREATE TRIGGERarrow-up-right
    DROP TRIGGERarrow-up-right
    CREATE PROCEDUREarrow-up-right
    ALTER PROCEDUREarrow-up-right
    DROP PROCEDUREarrow-up-right
    CREATE FUNCTIONarrow-up-right
    ALTER FUNCTIONarrow-up-right
    DROP FUNCTIONarrow-up-right
    CREATE USERarrow-up-right
    ALTER USERarrow-up-right
    DROP USERarrow-up-right
    CREATE ROLEarrow-up-right
    DROP ROLEarrow-up-right
    START TRANSACTIONarrow-up-right
    EXECUTEarrow-up-right
    SHOW CHARACTER SETarrow-up-right
    SHOW COLLATIONarrow-up-right
    SHOW COLUMNSarrow-up-right
    SHOW CREATE DATABASEarrow-up-right
    SHOW CREATE FUNCTIONarrow-up-right
    SHOW CREATE PROCEDUREarrow-up-right
    SHOW CREATE SEQUENCEarrow-up-right
    SHOW CREATE TABLEarrow-up-right
    SHOW CREATE TRIGGERarrow-up-right
    SHOW CREATE USERarrow-up-right
    SHOW CREATE VIEWarrow-up-right
    SHOW DATABASESarrow-up-right
    SHOW ENGINESarrow-up-right
    SHOW TABLESarrow-up-right
    SHOW VARIABLESarrow-up-right