學習筆記:MySQL Cluster 的結果順序

denniswwh發表於2009-08-26

最近搭建了MySQL Cluster的環境來學習,發現一個很有意思的現象,在不加order by的情況下,返回的結果順序是隨機的,每次都不一樣,如下

[@more@]

mysql> select * from test_ndb limit 3;
+---+-------+
| i | a |
+---+-------+
| 5 | test5 |
| 1 | test1 |
| 2 | test2 |
+---+-------+
3 rows in set (0.05 sec)

mysql> select * from test_ndb limit 3;
+---+-------+
| i | a |
+---+-------+
| 7 | test7 |
| 3 | test3 |
| 6 | test6 |
+---+-------+
3 rows in set (0.03 sec)

mysql> select * from test_ndb limit 3;
+---+-------+
| i | a |
+---+-------+
| 5 | test5 |
| 1 | test1 |
| 2 | test2 |
+---+-------+
3 rows in set (0.05 sec)

我想這應試與NDB的儲存方式有關吧,NDB實際上將表的資料用hash演算法分佈到不同結點,NDB表的主鍵並不像InnoDB一樣是聚集索引,而是hash索引,所以在取資料的時候每次的順序就不一定一樣了。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/124805/viewspace-1026359/,如需轉載,請註明出處,否則將追究法律責任。

相關文章