Scaleout tables and routing functions
A scaleout table is one logical table whose rows live in member tables across member clusters. Applications query it by one name through the routing endpoint. Each member table, a standard table on one member cluster, holds one collocation's rows. The routing key, one or more columns, decides where a row lives. The routing function maps each routing key value to a collocation, and a data mapping assigns each collocation to a member cluster.
Use a scaleout table when one table is too large for one member cluster or the data is logically spread across multiple member clusters and you need a single object to access the data. Otherwise, place the whole table on one member cluster with a table-level data mapping. Every statement on a scaleout table must include its routing key value, and you can't update a routing key column value in place. To change the value, delete the row and reinsert it. For guidance on whether a scaleout table fits and how to choose its key, see Choosing a routing key and routing function.
Defining a scaleout table
A scaleout table definition contains the following:
-
A routing key: the column or columns whose value decides which member cluster holds a row. Give every scaleout table a
ROUTE BY KEYclause, because you can't query a scaleout table without a routing key. -
A routing function: the rule that maps a routing key value to a collocation. A data mapping assigns each collocation to a member cluster.
-
Its member tables, by the router names that their data mappings give them.
The following example creates a routing function that sends each customer_id to one of two collocations by its remainder, and a scaleout table that uses it.
CREATE SCALEOUT ROUTING FUNCTION orders_mod_fn(customer_id INT) AS PARTITION BY mod(customer_id, 2) IN TARGET COLLOCATION ( coll_0 VALUES IN (0), coll_1 VALUES IN (1) );
The scaleout table names its two member tables. Each member is named by its router database name and router table name.
CREATE SCALEOUT TABLE orders ( ROUTE BY KEY(customer_id POSITION(1)) USING ROUTING FUNCTION orders_mod_fn ) MEMBERS ( MEMBER db.orders_s1, MEMBER db.orders_s2 );
For an example that creates, loads, and queries a scaleout table, see Creating and loading a scaleout table. For the grammar, see Scaleout table statements.
Creation order. Creating a scaleout table doesn't move data or create anything on a member cluster. Create the objects in the following order:
-
Create each member table and its data mapping. The data mapping creates the collocation.
-
Create the routing function. It can name only collocations that data mappings already created.
-
Create the scaleout table.
Member table definitions. Aurora doesn't compare the member tables of a scaleout table. It doesn't check them when you create the scaleout table or add a member table, or when you change a member table later. You must keep them identical: give every member table the same columns, in the same order, with the same data types, and put each routing key column at the position that POSITION( declares. The routing layer sends each statement to one member table as written, so a difference shows up only for the rows whose key maps to that member table:n)
-
A statement that names a column the member table lacks fails on that member cluster, for example with Aurora MySQL error 1054.
-
SELECT *returns that member table's columns, in its order. -
An
INSERT ... VALUESwith no column list fills the member table's columns in their order. If the order differs, values go into the wrong columns. If a routing key column isn't at itsPOSITION, the row can be stored on a member cluster that its key doesn't map to, and a read by that key doesn't find it. AnINSERTthat lists its columns fills them by name, so it stores the right values even when member tables order their columns differently. Write every insert into a scaleout table with a column list. -
SHOW COLUMNS,DESCRIBE, and theinformation_schemaviews show the columns of one member table.
When you change the schema, run the same change on every member table. See Changing scaleout tables. For the order in which to create the objects, see Order of creation.
Rules. The routing layer rejects the following:
-
A scaleout table that has no member table in one of its routing function's collocations.
-
A scaleout table whose routing key has a different number of columns than its routing function has parameters.
-
A delete of a data mapping while a scaleout table names that data mapping's member table.
Routing key positions. In ROUTE BY KEY, POSITION( gives the key column's position in the member table's column list. The routing layer uses it when a statement doesn't state the column order, such as n)INSERT ... VALUES with no column list. A routing key can have more than one column, for example ROUTE BY KEY(id POSITION(1), geo POSITION(2)).
A scaleout table name is unique across the whole group, not for each database. It must also differ from every router table name in your data mappings.
A statement that creates, changes, or drops a scaleout table or a routing function commits on its own when it returns, and ROLLBACK can't undo it. The routing layer refuses it inside a transaction or with autocommit off, with error 1179. Undo a change with the opposite statement. The other routers of the routing layer apply the change shortly after the statement returns; see Scaleout SQL reference.
Routing functions
A routing function names collocations instead of member clusters, so you can move a collocation to another member cluster without changing the routing function. Aurora provides four routing functions: MOD, HASH, PREFIX, and COLUMN. User-defined routing functions aren't supported.
Comparing routing functions
The following table compares the four routing functions.
| Function | How it assigns a key | Collocation values | Supported key types |
|---|---|---|---|
MOD |
By the remainder of the key, key % n, which keeps the sign of the key, from -(n-1) to n-1 |
A list of remainders, or one range of remainders | Integer types |
HASH |
By a hash of one or more key columns, an integer from 0 to 9223372036854775807 | One range of hash values | Integer, CHAR, VARCHAR, TEXT, DATE, DATETIME, and TIMESTAMP types |
PREFIX |
By the key up to the end of its depth-th segment, cut at a delimiter | A list of prefixes, or one range of prefixes | CHAR, VARCHAR, and TEXT |
COLUMN |
By the key value itself | A list of values, or one range of values | Integer types, CHAR, VARCHAR, DATE, DATETIME, and TIMESTAMP |
No routing function accepts DECIMAL, floating-point, JSON, or binary keys. COLUMN doesn't accept TEXT keys. MOD, PREFIX, and COLUMN take exactly one key column. Only HASH takes more than one.
MOD
A collocation can list more than one remainder, for example coll_0 VALUES IN (0, 2). MOD keeps the sign of a negative key, as the MySQL % operator and the MOD() function do. If you load member tables directly, place each row by key % n, and list negative remainders such as -1 in a collocation if your keys can be negative. The routing layer rejects a key if no collocation lists its remainder.
Give a divisor of 1 or more as an integer literal. CREATE rejects a negative divisor. CREATE accepts 0, but then the routing layer rejects every statement on the table.
List only remainders from -(n-1) to n-1. CREATE accepts other values, such as 7 for MOD(id, 4), but no key produces them.
MOD accepts the integer types TINYINT, SMALLINT, MEDIUMINT, INT, and BIGINT, signed or UNSIGNED.
HASH
You specify the key columns and one of these algorithms, in lowercase: cityhash, xxhash, md5, cityhash_normalized, xxhash_normalized, or md5_normalized. The *_normalized algorithms ignore the routing key's collation. They lowercase a string key, remove all whitespace, and remove accents that Unicode can separate from the base letter. They don't turn ß into ss, ø into o, or full-width letters into ASCII letters. Values that the collation compares as equal can then go to different member clusters. The other algorithms hash a string key under its collation, so values that the collation compares as equal get the same hash. Use cityhash, xxhash, or md5 for a string key, unless the key has a binary collation, such as utf8mb4_bin.
Each collocation takes one range of hash values, not of routing key values. Cover 0 to 9223372036854775807 with no gaps. The last range can end at MAXVALUE. CREATE accepts a gap, but the routing layer rejects every key whose hash falls in it.
A HASH function on two key columns declares both columns in its signature. The routing layer hashes them in signature order, matched by position to the columns in ROUTE BY KEY, so list them in the same order in both. The order inside HASH() doesn't matter, and SHOW CREATE SCALEOUT ROUTING FUNCTION shows it in signature order. Every statement must carry every key column. The following example assumes that data mappings already created the collocations C1 and C2.
CREATE SCALEOUT ROUTING FUNCTION tenant_region_fn(tenant INT, region BIGINT) AS PARTITION BY HASH('cityhash', tenant, region) IN TARGET COLLOCATION ( C1 VALUES IN RANGE (0, 4611686018427387903), C2 VALUES IN RANGE (4611686018427387904, 9223372036854775807) );
No statement returns the hash value. To see where a key value goes, run EXPLAIN on a statement that carries it. The Extra column of its first row lists the member cluster under Target Member Clusters. Load a HASH scaleout table with routed INSERT statements that include the routing key.
HASH doesn't accept DECIMAL, TIME, or UUID keys. DATETIME and TIMESTAMP keys take a fractional precision of up to 6.
PREFIX
PREFIX places a row by the leading part of a string key. You give a delimiter and a depth. PREFIX keeps the key up to the end of its depth-th segment and matches that text against the collocations. A collocation lists exact prefixes with VALUES IN, or takes one inclusive range of prefixes with VALUES IN RANGE, compared as strings under the key collation. The last range can end at MAXVALUE.
If the key starts with the delimiter, the delimiter stays in the result. At depth 1, /us/acme/42 gives /us and us/acme/42 gives us. These are two different values.
A key with no delimiter is one segment. At depth 1, us gives us.
The routing layer rejects a key that has fewer segments than the depth. It also rejects a result that no collocation lists, and it doesn't fall back to a shorter prefix. PREFIX isn't supported on a routing key with a Japanese collation.
The routing layer matches the delimiter as plain text. %, _, ., and | aren't wildcards, and a multi-character delimiter such as :: matches only as a whole.
The routing layer compares the result with the listed values under the key column's collation. Under the default utf8mb4_0900_ai_ci, /US matches /us.
The following example assumes that data mappings already created the collocations C1 and C2.
CREATE SCALEOUT ROUTING FUNCTION tenant_path_fn(tenant_path VARCHAR(128)) AS PARTITION BY PREFIX(tenant_path, '/', 1) IN TARGET COLLOCATION ( C1 VALUES IN ('/us', '/ca'), C2 VALUES IN ('/eu') );
With this function, /us/acme/42 and /ca/beta/7 go to C1, /eu/gamma/1 goes to C2, and /jp/x is rejected.
COLUMN
COLUMN places a row by the key value itself. Each collocation takes one of the following:
-
A list of exact values, for example
C1 VALUES IN ('us', 'ca'). -
One range, for example
C1 VALUES IN RANGE (1, 999999). Both bounds are inclusive. The last range can useMAXVALUEas its upper bound.
One routing function uses either lists or ranges, not both. Each value or bound must fit the key's declared type and length. Range bounds work as follows:
-
Both bounds are inclusive.
VALUES IN RANGE (1, 1000)holds 1 and 1000. -
Ranges can't overlap or share a value. The routing layer refuses
(1, 1000)and(1000, 2000)with error 1493. -
Only the last range can end at
MAXVALUE, which covers every value from its low bound up. No range covers the values below the lowest range. -
CREATE SCALEOUT ROUTING FUNCTIONaccepts ranges that leave a gap, such as(1, 100)and(200, MAXVALUE). It checks only that the ranges don't overlap. AnINSERTof a key in a gap or below the lowest range fails with error 1526, and a read of that key fails with error 1235. Make sure that your ranges cover every key that you insert.
The following routing function tiles a BIGINT key across two collocations with no gap. The lowest range starts at 1, so a key of 0 falls in no range. This example assumes that data mappings already created the collocations C1 and C2.
CREATE SCALEOUT ROUTING FUNCTION accounts_range_fn(account_id BIGINT) AS PARTITION BY COLUMN(account_id) IN TARGET COLLOCATION ( C1 VALUES IN RANGE (1, 1000000), C2 VALUES IN RANGE (1000001, MAXVALUE) );
With this function, the following statements place two rows and refuse a third.
INSERT INTO accounts (account_id) VALUES (1000000); -- goes to C1 INSERT INTO accounts (account_id) VALUES (1000001); -- goes to C2 INSERT INTO accounts (account_id) VALUES (0); -- ERROR 1526 (HY000): Table 'accounts' has no collocation for the row's routing key
Ranges can't share a bound. The routing layer refuses the following function, because both ranges include 1000000.
CREATE SCALEOUT ROUTING FUNCTION accounts_bad_fn(account_id BIGINT) AS PARTITION BY COLUMN(account_id) IN TARGET COLLOCATION ( C1 VALUES IN RANGE (1, 1000000), C2 VALUES IN RANGE (1000000, MAXVALUE) ); -- ERROR 1493 (HY000): TARGET COLLOCATION 'C1' and 'C2' have overlapping VALUES IN RANGE bounds
How you write adjacent ranges depends on the key type:
| Key type | Adjacent ranges | Example |
|---|---|---|
| Integer types | Start each range at the previous high value plus 1. | (1, 1000000), (1000001, 2000000), (2000001, MAXVALUE) |
DATE |
End each range on its last day. | ('2026-01-01', '2026-01-31'), ('2026-02-01', '2026-02-28') |
DATETIME, TIMESTAMP |
End each range on its last value at the key's fractional-second precision. Change the bounds if you change the precision. | DATETIME(6): ('2026-01-01 00:00:00', '2026-01-31 23:59:59.999999'), ('2026-02-01 00:00:00', MAXVALUE) |
CHAR, VARCHAR |
Ranges can't be adjacent, because no string comes right after another string. A key between two ranges is refused: under ('a', 'l') and ('m', 'z'), 'lara' fails with error 1526. Route a string key with PREFIX, with COLUMN and VALUES IN lists, or with HASH instead. |
On a DATETIME or TIMESTAMP key, the routing layer refuses a value that has more fractional-second digits than the key's precision with error 1235. It doesn't round the value as Aurora MySQL does. With a whole-second bound such as '2026-01-31 23:59:59' on a DATETIME(6) key, '2026-01-31 23:59:59.5' is in no range and fails with error 1526.
COLUMN is the only routing function that routes a range predicate, and only with VALUES IN RANGE collocations on an integer, DATE, DATETIME, or TIMESTAMP key. For the range predicates that route, see Statements that resolve to one member cluster. The following example assumes that data mappings already created the collocations C1, C2, and C3.
CREATE SCALEOUT ROUTING FUNCTION orders_range_fn(order_id BIGINT) AS PARTITION BY COLUMN(order_id) IN TARGET COLLOCATION ( C1 VALUES IN RANGE (1, 999999), C2 VALUES IN RANGE (1000000, 1999999), C3 VALUES IN RANGE (2000000, MAXVALUE) );
A date key works the same way:
CREATE SCALEOUT ROUTING FUNCTION events_month_fn(event_day DATE) AS PARTITION BY COLUMN(event_day) IN TARGET COLLOCATION ( C1 VALUES IN RANGE ('2026-01-01', '2026-01-31'), C2 VALUES IN RANGE ('2026-02-01', MAXVALUE) );
The routing layer reads a TIMESTAMP value in your session's time zone.
To choose a routing method for your key, use the following guidance:
-
For integer or date ranges that you query by range, use
COLUMNwithVALUES IN RANGE. -
For string keys that group by a leading token, such as a region or a tenant prefix, use
PREFIX, orCOLUMNwithVALUES INlists of the token values. -
For an even spread with no range queries, use
HASHorMOD.
Choosing the number of collocations
A scaleout table can spread its rows across at most as many member clusters as its routing function has collocations. Decide the number before you create the routing function. Create more collocations than your current member clusters, because several collocations can share one member cluster. Later, a data movement job moves one collocation, with all of its member tables, to another member cluster. For more information, see Planning collocations and headroom.
Placement that routing functions don't support
If your application places rows through a lookup table or by naming the member cluster directly, connect through session pinning, or use data mappings to map each database to its member cluster. For key ranges, use COLUMN, and for a key prefix, use PREFIX. For more information, see Session pinning and Data mappings and collocations.
Changing or dropping a routing function
Routing functions have no ALTER statement. You can't drop a routing function while a scaleout table uses it. If you change a scaleout table's routing function, only its definition changes and no rows move. For more information, see Changing a routing function. For the grammar, see Routing function statements.
Routing keys in statements
The routing layer reads the routing key value from your statement, not from member cluster data, so write the value in the statement. It accepts a literal, such as WHERE id = 5542. It also accepts a call to CAST, CONVERT ... USING, MOD, CONCAT, CONCAT_WS, HEX, or BIN_TO_UUID where each argument is a literal or another such call. It accepts CONVERT only in the CONVERT( form. It accepts x USING utf8mb4)BIN_TO_UUID with a 16-byte hexadecimal literal, such as BIN_TO_UUID(X'00112233445566778899AABBCCDDEEFF', 1), and an optional integer swap flag. It accepts UUID(), which it computes one time and sends as that value.
The routing layer rejects any other value, and it rejects the whole statement. It rejects arithmetic such as 5541 + 1 or MOD(5541 + 1, 4), the % operator, other functions, user-defined functions, subqueries, NULL, DEFAULT, and default, sequence, or generated columns. Compute such a value in your application, and pass a literal.
Prepared statements work on a scaleout table and route by the bound routing key value. Both the text SQL PREPARE and EXECUTE statements and the binary-protocol COM_STMT_PREPARE and COM_STMT_EXECUTE route a statement on a scaleout table by its bound key.
You can't update a routing key column, even to the same member cluster, so an UPDATE can't move a row. To change the key of a row, delete the row and insert it again. A routing key can span multiple columns, and every key column must appear in the statement.
PREFIX, COLUMN, and the cityhash, xxhash, and md5 HASH algorithms compare a character key under the routing key's collation. Set it with ROUTE BY KEY(. Without it, the key takes the scaleout table's default collation (k POSITION(n) COLLATE collation)utf8mb4_0900_ai_ci). The member table column's collation doesn't change placement. The *_normalized HASH algorithms ignore collation. Declare the member table columns with the same collation as the routing key, so that each member cluster compares values the same way. A TIMESTAMP routing key routes by its UTC instant, so set the session time_zone to UTC or a fixed offset.
A unique column outside the routing key is unique only within one member cluster
A unique constraint holds across a scaleout table only when it includes every routing key column. An auto-increment column or a sequence on a member table also counts only within one member cluster. Generate values that must be unique across the database cluster group for Aurora in your application.
Statements that resolve to one member cluster
A statement on a scaleout table must resolve to one member cluster, or the routing layer rejects it. It never sends a keyless statement to every member cluster. Only equality and IN predicates on a routing key column resolve. A range, a pattern, a null test, a function on the column, or no predicate doesn't resolve.
Under a COLUMN routing function with VALUES IN RANGE collocations, a range predicate (BETWEEN, <, >, <=, >=) on an integer, DATE, DATETIME, or TIMESTAMP key also resolves when one collocation's range holds the whole range. The following table shows which predicates on a routing key resolve. A statement that the routing layer can't place on one member cluster fails with error 1235; the routing layer never returns partial or wrong rows for it.
| Predicate on the routing key | Result |
|---|---|
Equality, or IN with all values in one collocation |
Resolves. |
BETWEEN, or a pair such as >= and <= or >= and <, inside one collocation's range |
Resolves. For example, ts >= '2026-01-01' AND ts < '2026-02-01' resolves when one range holds January. |
A range open above, such as k >= 1000001 |
Resolves only when it starts inside the range that ends at MAXVALUE. |
A range open below, such as k < 500 |
Fails with Range predicate on table '<table>' is not fully contained in a single collocation, because the range reaches below the lowest range. Give both ends, such as k BETWEEN 1 AND 499. |
| A range that crosses a collocation boundary or reaches into a gap | Fails with Range predicate on table '<table>' is not fully contained in a single collocation. Split the statement at the boundary. |
IN with values in collocations on different member clusters |
Fails with Statements across member clusters are not supported. Ensure the statement targets a single member cluster. Send one statement for each member cluster. An IN list whose collocations share one member cluster runs. |
| A range that lies wholly in a gap or above every range | Fails with No collocation matched the evaluated routing function result. Aurora MySQL returns no rows for the same query. |
Any range or LIKE on a CHAR or VARCHAR key |
Fails with Operator 'range on non-integer routing key' is not supported on routing key columns or Operator 'LIKE' is not supported on routing key columns. |
A range under COLUMN with VALUES IN lists |
Fails with range predicates require an integer RANGE collocation map. |
A range under MOD or HASH |
Fails with range predicates require a COLUMN routing function. |
Each statement must carry its routing key, and inside a transaction the first routable statement binds the transaction to its member cluster. For more information, see Single-cluster transactions.
The routing layer also rejects the following:
-
A multi-row
INSERTwhose rows target more than one member cluster. Group the rows by member cluster, and send oneINSERTfor each. UnderHASH, your application can't compute a row's member cluster, so send one row for eachINSERT. UnderMOD,PREFIX, andCOLUMN, your application can compute each row's collocation, so group rows by collocation. -
A bulk load into a scaleout table through the routing endpoint. Load each member table instead. For more information, see Loading data into member clusters.
On Aurora MySQL, the routing layer also refuses INSERT ... SELECT into a scaleout table, with error 1235.
A pinned session can't name a scaleout table. Reach the rows through the member tables by their cluster names.
Collocated scaleout tables
A dependent scaleout table, such as items beside orders, stays with its parent when it routes on the same key value through the same routing function and its member tables are in the same collocations as the parent's. To keep a dependent table with its parent, do the following:
-
Give it the parent's routing key column, with the same name and type. It must carry the column itself.
-
Name the same routing function, or take it from the parent with
USING ROUTING FUNCTION OF.parent_table -
In each member table's data mapping, set the collocation value to the matching parent member table's collocation. For more information, see Data mappings and collocations.
A collocation holds at most one member table of each scaleout table, and every scaleout table in a collocation must use the identical routing function. Set collocations in the data mappings.
The relationship goes one level only, so always take the routing function from the root scaleout table. It governs routing only. It isn't a foreign key, and each member cluster enforces foreign keys locally.
Creating and listing scaleout tables
Declare a scaleout table with CREATE SCALEOUT TABLE and a routing function with CREATE SCALEOUT ROUTING FUNCTION. Run both at the routing endpoint, in query routing mode. To list them, use SHOW SCALEOUT TABLES, SHOW SCALEOUT ROUTING FUNCTIONS, SHOW CREATE SCALEOUT TABLE, and SHOW CREATE SCALEOUT ROUTING FUNCTION.
For the grammar, see Scaleout table statements. For error codes, see Error codes for database cluster groups for Aurora.