mysql cluster 分片_mysql cluster分片:查看详细分区信息的方法

以下技术应用于最优质的水果的鲜果篮

Mysql Cluster does sharding (evenly distributes the data between data nodes) + replication ( every fragment of data stored twice).

So simple table like,

|test|CREATETABLE`test`(`id`bigint(20)NOTNULLAUTO_INCREMENT,`v1`char(255)DEFAULTNULL,PRIMARYKEY(`id`))ENGINE=ndbcluster AUTO_INCREMENT=1871780DEFAULTCHARSET=latin1

If you check the information_schema, you will see partitions for this table

mysql>selectpartition_name,table_rowsfrominformation_schema.PARTITIONSwheretable_name='test'andtable_schema='test1';+----------------+------------+|partition_name|table_rows|+----------------+------------+|p0|518667||p1|518900||p2|517385||p3|519050|+----------------+------------+4rowsinset(0.02sec)

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 partitionsselectid,v1fromtestwhereid=1\G***************************1.row***************************id:1select_type:SIMPLEtable:test

partitions:p3

type:eq_ref

possible_keys:PRIMARYkey:PRIMARYkey_len:8ref:constrows:1Extra:NULL1rowinset(0.00sec)mysql>explain partitionsselectid,v1fromtestwhereid=2\G***************************1.row***************************id:1select_type:SIMPLEtable:test

partitions:p2

type:eq_ref

possible_keys:PRIMARYkey:PRIMARYkey_len:8ref:constrows:1Extra: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 useMysql

Proxy

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值