以下技术应用于最优质的水果的鲜果篮
Mysql Cluster does sharding (evenly distributes the data between data nodes) + replication ( every fragment of data stored twice).
So simple table like,
| test | CREATE TABLE `test` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`v1` char(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=ndbcluster AUTO_INCREMENT=1871780 DEFAULT CHARSET=latin1
If you check the information_schema, you will see partitions for this table
mysql> select partition_name,table_rows from information_schema.PARTITIONS where table_name='test' and table_schema='test1';
+----------------+------------+
| partition_name | table_rows |
+----------------+------------+
| p0 | 518667 |
| p1 | 518900 |
| p2 | 517385 |
| p3 | 519050 |
+----------------+------------+
4 rows in set (0.02 sec)
Partition p0,p2 stands for data node 1, and p1,p3 for node 2. The data is distributed based on the PRIMARY KEY (or and artificial key, if now primary key defined).
Select chooses the node to read from based on this partitioning, so if you use explain
mysql> explain partitions select id,v1 from test where id=1\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: test
partitions: p3
type: eq_ref
possible_keys: PRIMARY
key: PRIMARY
key_len: 8
ref: const
rows: 1
Extra: NULL
1 row in set (0.00 sec)
mysql> explain partitions select id,v1 from test where id=2\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: test
partitions: p2
type: eq_ref
possible_keys: PRIMARY
key: PRIMARY
key_len: 8
ref: const
rows: 1
Extra: NULL
The record for id=92 will be read from only one of the data nodes (may the geographical distributed one), but unfortunately it is not just for id 92.
The best is to create a separate table for customer id 92 (on a separate node), and rewrite your application to read from that table/node. To have a solution transparent to the app, you might use Mysql Proxy