View a markdown version of this page

ALTER SCALEOUT TABLE - Amazon Aurora

ALTER SCALEOUT TABLE

Use ALTER SCALEOUT TABLE to switch a scaleout table to another routing function, or add and remove member tables in a database cluster group for Aurora.

Description and syntax

Changes the routing information of one scaleout table: its routing key and routing function, or its member tables. The statement moves no rows and changes no member table. Each statement takes one action. Switching a table to a new routing function is how you change a routing function, because a routing function has no ALTER statement.

ALTER SCALEOUT TABLE table_name ROUTE BY KEY(column POSITION(n) [, ...]) [USING ROUTING FUNCTION function_name]; ALTER SCALEOUT TABLE table_name ADD MEMBER member_table; ALTER SCALEOUT TABLE table_name DROP MEMBER member_table; ALTER SCALEOUT TABLE table_name DROP ROUTING; ALTER SCALEOUT TABLE table_name ADD ROUTING FUNCTION function_name;

Parameters and options

The statement takes the following parameters.

table_name

The scaleout table to change.

ROUTE BY KEY(column POSITION(n) [, ...]) [USING ROUTING FUNCTION function_name]

The routing key, and optionally a new routing function. Without USING, the table keeps its current function. The new function also applies to tables created OF this one, so each of those tables also needs a member table in every collocation of the new function. Tables that name the old function directly keep it.

ADD MEMBER member_table

Adds one member table, mapped in a collocation that the table doesn't use, without changing routing. The routing layer accepts a member table whose collocation isn't in the current routing function. It receives rows after a switch to a function that targets its collocation.

On Aurora MySQL, write db.member_table.

DROP MEMBER member_table

Removes one member table whose collocation the function no longer targets. Then delete its data mapping; the routing layer refuses to delete the mapping of a member table that a scaleout table still names. The member table name takes the same form as in ADD MEMBER.

DROP ROUTING, ADD ROUTING FUNCTION function_name

DROP ROUTING removes the routing key and the routing function, so you can't query the table. ADD ROUTING FUNCTION binds a function to a table that already has routing key columns. You can't clear the routing of a parent that other tables use with OF.

Where it runs and required privileges

Run the statement at the routing endpoint, in a session that isn't pinned, outside a transaction. On Aurora MySQL, inside a transaction the routing layer refuses the statement with error 1179. For the details, see Where these statements run.

The router user needs dbclustergroup_metadata_admin or dbclustergroup_super_admin. For all privileges for database cluster groups for Aurora, see Privileges.

Usage notes

Keep the following in mind when you use the statement.

  • Switch the routing function only of an empty scaleout table. The switch moves no rows, and the routing layer accepts it on a table that holds rows. After the switch, you can't read a row by its routing key if the new function sends that key to another collocation. For the procedure, see Changing a routing function.

  • The routing layer can't count the rows of a scaleout table, because the count carries no routing key. To check that a table is empty, count the rows of each member table on its member cluster, through a pinned session or a direct connection.

  • The routing layer checks a switch against this table only: the table needs one member table in each collocation that the new function targets. It doesn't compare the new function with the functions of other scaleout tables in the same collocations, and it accepts a state in which they differ. Switch each table that names the old function directly. Don't query those tables between the switches, because they route the same key to different collocations until every switch is done.

  • A routing function change reaches the routing layer within a short time. A statement routed on the earlier definition returns Aurora MySQL error 1412; the session stays open, and a retry routes on the new definition. Inside a transaction, a statement that needs a definition changed after the transaction's first routed statement fails with error 63928, and the routing layer rolls back the transaction. For the retry rule, see Transaction errors and retries. For more information, see Data mappings and collocations.

  • The routing layer doesn't check that a member table you add with ADD MEMBER matches the other member tables. Create it with the same columns, in the same order, with the same data types. See Member table definitions.

  • Include a single action in each statement, for example a single ADD MEMBER.

  • To rename a scaleout table, run ALTER SCALEOUT TABLE table_name RENAME TO new_name at the routing endpoint. The new name must not be in use in the group.

Examples

The following example adds a member table mapped in the new collocation coll_2, switches orders to the routing function orders_mod_fn_v2, and then removes a member table that the new function no longer targets.

ALTER SCALEOUT TABLE orders ADD MEMBER db.orders_s3; ALTER SCALEOUT TABLE orders ROUTE BY KEY(customer_id POSITION(1)) USING ROUTING FUNCTION orders_mod_fn_v2; ALTER SCALEOUT TABLE orders DROP MEMBER db.orders_s1;

Errors

The statement can return the following errors. For all errors from the routing layer, see Error codes for database cluster groups for Aurora.

Aurora MySQL Meaning
64024 Scaleout table '<table>' already has a member in collocation group '<collocation>' (42000) ADD MEMBER of a second member table in one collocation. Map the new member table in a new collocation.
64066 Scaleout table '<table>' has no member in collocation group '<collocation>', which its routing function targets (42000) With more than one group, the message reads collocation groups '<a>', '<b>'. A switch to a function that targets a collocation with no member table, or DROP MEMBER of a targeted collocation.
64040 Member '<member>' already belongs to a scaleout table (42000) The member table belongs to another scaleout table.
64000 Member '<member>' has no data mapping. Create a data mapping for it. (42000) ADD MEMBER of a member table that has no table-level data mapping, that only a database-level mapping covers, or that the statement names by its cluster name instead of its router table name. The scaleout table's member tables stay unchanged. Map the member table at table level with INSERT INTO dbclustergroup_sys.data_mappings, and then run the statement again.
1235 cannot clear routing on scaleout table '<name>': other scaleout tables inherit its routing function (42000) DROP ROUTING or DROP ROUTING FUNCTION on a parent that other tables use with OF.
1064 Syntax error: a form outside the grammar, such as two actions in one statement.
1227 Access denied; you need the '<PRIVILEGE>' privilege for this operation The router user lacks the privilege for database cluster groups for Aurora.
1412 The routing layer routed a statement on the definition from before the change. On Aurora MySQL, the routing layer resends a text-protocol statement up to 3 times first; the session stays open. Retry the statement.
63928 Inside a transaction, a statement needed a definition that changed after the transaction's first routed statement, and the routing layer rolled the whole transaction back. Retry the whole transaction from its first statement.

For more information, see the following: