包括聚合函数,操作体验和mysql单机操作几乎没有什么差异,但实际是分片处理的
代码语言:javascript复制mysql> explain select * from catworld4;
----------- -----------------------------------
| DATA_NODE | SQL |
----------- -----------------------------------
| sd1 | SELECT * FROM catworld4 LIMIT 100 |
| sd2 | SELECT * FROM catworld4 LIMIT 100 |
| sd3 | SELECT * FROM catworld4 LIMIT 100 |
| sd4 | SELECT * FROM catworld4 LIMIT 100 |
----------- -----------------------------------
4 rows in set (0.00 sec)
mysql> explain select count(*) from catworld4;
----------- ----------------------------------------------------
| DATA_NODE | SQL |
----------- ----------------------------------------------------
| sd1 | SELECT COUNT(*) AS COUNT0 FROM catworld4 LIMIT 100 |
| sd2 | SELECT COUNT(*) AS COUNT0 FROM catworld4 LIMIT 100 |
| sd3 | SELECT COUNT(*) AS COUNT0 FROM catworld4 LIMIT 100 |
| sd4 | SELECT COUNT(*) AS COUNT0 FROM catworld4 LIMIT 100 |
----------- ----------------------------------------------------
4 rows in set (0.00 sec)
mysql> explain select distinct(name) from catworld4;
----------- ----------------------------------------------------
| DATA_NODE | SQL |
----------- ----------------------------------------------------
| sd1 | SELECT name FROM catworld4 GROUP BY name LIMIT 100 |
| sd2 | SELECT name FROM catworld4 GROUP BY name LIMIT 100 |
| sd3 | SELECT name FROM catworld4 GROUP BY name LIMIT 100 |
| sd4 | SELECT name FROM catworld4 GROUP BY name LIMIT 100 |
----------- ----------------------------------------------------
4 rows in set (0.00 sec)
mysql>
Tip: 后面的 LIMIT 100 就是由定义 schema 时 sqlMaxLimit 参数配置的
我们可以去其中一个分片节点里查看本地数据
代码语言:javascript复制mysql> select database();
------------
| database() |
------------
| my4 |
------------
1 row in set (0.00 sec)
mysql> show tables;
---------------
| Tables_in_my4 |
---------------
| catworld4 |
---------------
1 row in set (0.00 sec)
mysql> select * from catworld4;
---- ------
| id | name |
---- ------
| 3 | abc |
| 7 | abc |
---- ------
2 rows in set (0.00 sec)
mysql>
修改数据
代码语言:javascript复制mysql> select * from catworld4 where id=9;
---- ------
| id | name |
---- ------
| 9 | def |
---- ------
1 row in set (0.01 sec)
mysql> update catworld4 set name="xxx" where id=9;
Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from catworld4 where id=9;
---- ------
| id | name |
---- ------
| 9 | xxx |
---- ------
1 row in set (0.01 sec)
mysql>