PolarDB-X allows you to execute the SET PARTITION_HINT statement to specify a SQL statement to be executed on a shard of the data node.
Syntax
SET PARTITION_HINT=[PARTITION_NAME|GROUP_NAME|GROUP_NAME:TABLE_INDEX]This statement is supported in databases in AUTO and DRDS mode.
Parameters
PARTITION_NAME: the partition_name attribute of the table in the database in AUTO mode.
GROUP_NAME: the GROUP_NAME attribute of the table in the database in DRDS mode.
TABLE_INDEX: indicates the index of the table in the group to which the table belongs if the group in the database in DRDS mode contains multiple tables. The index starts from 0.
Precautions
The statement is supported only on cluster of PolarDB-X 5.4.16-16773973.
Examples
Specify subsequent SQL statements to be executed on PARTITION_HINT_TEST_DRDS_000003_GROUP.
set PARTITION_HINT='PARTITION_HINT_TEST_DRDS_000003_GROUP:0';
Query OK, 0 rows affected (0.00 sec)Obtain the results of the SQL statements executed on PARTITION_HINT_TEST_DRDS_000003_GROUP.
select * from multi_db_single_tbl;
+--------+------+
| id | name |
+--------+------+
| 100003 | c |
+--------+------+
1 row in set (0.02 sec)Specify subsequent SQL statements to be executed on all shards.
set partition_hint='';
Query OK, 0 rows affected (0.00 sec)Obtain the results of the SQL statements executed on all shards.
select * from multi_db_single_tbl;
+--------+------+
| id | name |
+--------+------+
| 100003 | c |
| 100002 | b |
| 100001 | a |
+--------+------+
3 rows in set (0.04 sec)