2013-10-24 24 views
0

如果我提出300,000行從表中(無論是InnoDB的或NDB)成NDB表所示:INSERT INTO ndbtable SELECT FROM表使用荒謬數量的內存在MySQL集羣

INSERT INTO ndbtable2 
SELECT a, b,IFNULL(c,UTC_TIMESTAMP()),CASE WHEN b = 'X' THEN e ELSE d END,f 
FROM ndbtable1; 

Query OK, 308372 rows affected (5 min 12.59 sec) 
Records: 308372 Duplicates: 0 Warnings: 0 

NDB使用日益龐大關於數據內存直到它完成。 /峯前/後如下

ndb_mgm -e "all report memoryusage" 
Connected to Management Server at: fl-prd-mysql1:1186 
Node 1: Data usage is 2%(5752 32K pages of total 262144) 
Node 1: Index usage is 0%(2428 8K pages of total 262176) 
Node 2: Data usage is 2%(5752 32K pages of total 262144) 
Node 2: Index usage is 0%(2428 8K pages of total 262176) 

Connected to Management Server at: fl-prd-mysql1:1186 
Node 1: Data usage is 62%(164013 32K pages of total 262144) 
Node 1: Index usage is 1%(3136 8K pages of total 262176) 
Node 2: Data usage is 62%(164013 32K pages of total 262144) 
Node 2: Index usage is 1%(3136 8K pages of total 262176) 

Connected to Management Server at: fl-prd-mysql1:1186 
Node 1: Data usage is 3%(10293 32K pages of total 262144) 
Node 1: Index usage is 1%(4590 8K pages of total 262176) 
Node 2: Data usage is 3%(10293 32K pages of total 262144) 
Node 2: Index usage is 1%(4590 8K pages of total 262176) 

如果我的數學是正確的我插入10293 - 5752 = 4541 = 142 MB但內存峯值的164013 - 5752 = 158261 = 4945 MB

而且如果我將插入限制爲50,000行,差異前後只有3MB,則峯值爲780MB。

顯然,這將是問題,當ndb不是空的......這裏發生了什麼?!

回答

0

在不存在的說明手冊確實確認的限制如下

如本章別處指出的,MySQL簇不處理大事務井;最好用少量操作來執行大量小事務,而不是嘗試包含大量操作的單個大事務。除了其他考慮,大型交易需要非常大量的內存

http://dev.mysql.com/doc/refman/5.5/en/mysql-cluster-limitations-transactions.html

「正如本章其他地方提到」 ......我已經看了,但尚未找到具體的事情。

FYI的替代品:

  1. 遍歷迭代與行LIMIT(說10,000)
  2. 如果插入一個空表考慮LOAD DATA甚至使用InnoDB和最後ALTER TABLE ... ENGINE = ndbcluster(既不是事務)