2015-06-15 198 views
-1

有一個InnoDB表:慢更新/刪除

id PRIMARY AI 
id2 INDEX varchar 
data LONGTEXT - contains 100k to 5 MB of text 
mark_for_delete TINYINT 
NUM ROWS = approx. 25000 
SIZE=1.7G 
MySQL 5.5 

UPDATE table SET data='longtext here' WHERE id2=5 

工作快速

UPDATE table SET mark_for_delete=1 WHERE id2=5 

作品40秒

DELETE FROM table WHERE id2=5 

作品40秒 刪除幾個行需要同一時間。

磁盤在執行最後兩個查詢時以40Mb/s的速率讀取數據。

如何加快更新和刪除?而運行緩慢的查詢

CREATE TABLE b.table (
    id INT(11) NOT NULL AUTO_INCREMENT , 
    TradeCardId VARCHAR(255) NOT NULL , 
    TradeCardHTML LONGTEXT NOT NULL , 
    MarkForDelete TINYINT(4) NOT NULL DEFAULT '0', 
    PRIMARY KEY (id) , 
    KEY TradeCardId (TradeCardId) 
) ENGINE = INNODB DEFAULT CHARSET = utf8; 

INNODB SHOW STATUS:

===================================== 
150712 4:51:15 INNODB MONITOR OUTPUT 
===================================== 
Per second averages calculated from the last 28 seconds 
----------------- 
BACKGROUND THREAD 
----------------- 
srv_master_thread loops: 1172 1_second, 1172 sleeps, 113 10_second, 56 background, 56 flush 
srv_master_thread log flush and writes: 1224 
---------- 
SEMAPHORES 
---------- 
OS WAIT ARRAY INFO: reservation count 921, signal count 923 
Mutex spin waits 1470, rounds 11716, OS waits 206 
RW-shared spins 645, rounds 18932, OS waits 569 
RW-excl spins 5, rounds 4309, OS waits 142 
Spin rounds per wait: 7.97 mutex, 29.35 RW-shared, 861.80 RW-excl 
------------ 
TRANSACTIONS 
------------ 
Trx id counter 7B100A 
Purge done for trx's n:o < 7B1006 undo n:o < 0 
History list length 2752 
LIST OF TRANSACTIONS FOR EACH SESSION: 
---TRANSACTION 0, not started 
MySQL thread id 411, OS thread handle 0x29fc, query id 62926 localhost 127.0.0.1 root 
SHOW ENGINE INNODB STATUS 
---TRANSACTION 7B05CE, not started 
MySQL thread id 269, OS thread handle 0xf6c, query id 58184 localhost 127.0.0.1 root 
---TRANSACTION 7AEA37, not started 
MySQL thread id 268, OS thread handle 0x142c, query id 45581 localhost 127.0.0.1 root 
---TRANSACTION 7B0FF6, not started 
MySQL thread id 267, OS thread handle 0x1cc, query id 62861 localhost 127.0.0.1 root 
---TRANSACTION 7AE808, not started 
MySQL thread id 266, OS thread handle 0xa84, query id 44520 localhost 127.0.0.1 root 
---TRANSACTION 7AEBF1, not started 
MySQL thread id 133, OS thread handle 0x24ac, query id 46431 localhost 127.0.0.1 root 
---TRANSACTION 7ACEE4, not started 
MySQL thread id 116, OS thread handle 0x1970, query id 32435 localhost 127.0.0.1 root 
---TRANSACTION 7AD73D, not started 
MySQL thread id 85, OS thread handle 0xfb8, query id 36383 localhost 127.0.0.1 root 
---TRANSACTION 7AEA14, not started 
MySQL thread id 84, OS thread handle 0x2b10, query id 45519 localhost 127.0.0.1 root 
---TRANSACTION 7ACEC0, not started 
MySQL thread id 83, OS thread handle 0x17e8, query id 32180 localhost 127.0.0.1 root 
---TRANSACTION 7AD7A5, not started 
MySQL thread id 81, OS thread handle 0x2900, query id 36585 localhost 127.0.0.1 root 
---TRANSACTION 7AF77F, not started 
MySQL thread id 56, OS thread handle 0x1a1c, query id 51611 localhost 127.0.0.1 root 
---TRANSACTION 7ACEA2, not started 
MySQL thread id 3, OS thread handle 0x2080, query id 31915 localhost 127.0.0.1 root 
---TRANSACTION 7B069A, not started 
MySQL thread id 2, OS thread handle 0x2a2c, query id 58548 localhost 127.0.0.1 root 
---TRANSACTION 7A5300, not started 
MySQL thread id 1, OS thread handle 0x2188, query id 3 localhost 127.0.0.1 root 
---TRANSACTION 7B1009, ACTIVE 42 sec fetching rows 
mysql tables in use 1, locked 1 
277 lock struct(s), heap size 27968, 5127 row lock(s) 
MySQL thread id 82, OS thread handle 0x21c8, query id 62893 localhost 127.0.0.1 root updating 
DELETE FROM `tradecards_raw` WHERE `TradeCardId`=430931 
-------- 
FILE I/O 
-------- 
I/O thread 0 state: wait Windows aio (insert buffer thread) 
I/O thread 1 state: wait Windows aio (log thread) 
I/O thread 2 state: wait Windows aio (read thread) 
I/O thread 3 state: wait Windows aio (read thread) 
I/O thread 4 state: wait Windows aio (read thread) 
I/O thread 5 state: wait Windows aio (read thread) 
I/O thread 6 state: wait Windows aio (write thread) 
I/O thread 7 state: wait Windows aio (write thread) 
I/O thread 8 state: wait Windows aio (write thread) 
I/O thread 9 state: wait Windows aio (write thread) 
Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] , 
ibuf aio reads: 0, log i/o's: 0, sync i/o's: 1 
Pending flushes (fsync) log: 0; buffer pool: 0 
295450 OS file reads, 69254 OS file writes, 3663 OS fsyncs 
375.38 reads/s, 16384 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s 
------------------------------------- 
INSERT BUFFER AND ADAPTIVE HASH INDEX 
------------------------------------- 
Ibuf: size 1, free list len 5, seg size 7, 4 merges 
merged operations: 
insert 29, delete mark 2, delete 0 
discarded operations: 
insert 0, delete mark 0, delete 0 
Hash table size 4425293, node heap has 1 buffer(s) 
0.00 hash searches/s, 0.00 non-hash searches/s 
--- 
LOG 
--- 
Log sequence number 16969722405 
Log flushed up to 16969722405 
Last checkpoint at 16969722405 
0 pending log writes, 0 pending chkp writes 
41513 log i/o's done, 0.00 log i/o's/second 
---------------------- 
BUFFER POOL AND MEMORY 
---------------------- 
Total memory allocated 1087897600; in additional pool allocated 0 
Dictionary memory allocated 28146 
Buffer pool size 65536 
Free buffers  0 
Database pages  65534 
Old database pages 24171 
Modified db pages 0 
Pending reads 1 
Pending writes: LRU 0, flush list 0, single page 0 
Pages made young 261024, not young 0 
375.34 youngs/s, 0.00 non-youngs/s 
Pages read 295310, created 13003, written 26379 
375.34 reads/s, 0.00 creates/s, 0.00 writes/s 
Buffer pool hit rate 555/1000, young-making rate 445/1000 not 0/1000 
Pages read ahead 0.00/s, evicted without access 370.24/s, Random read ahead 0.00/s 
LRU len: 65534, unzip_LRU len: 0 
I/O sum[20617]:cur[77], unzip sum[0]:cur[0] 
-------------- 
ROW OPERATIONS 
-------------- 
0 queries inside InnoDB, 0 queries in queue 
1 read views open inside InnoDB 
Main thread id 2256, state: waiting for server activity 
Number of rows inserted 37683, updated 2503, deleted 65762, read 18023414 
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 92.46 reads/s 
---------------------------- 
END OF INNODB MONITOR OUTPUT 
============================ 

回答

0

該款發動機

從評論添加? (請提供完整的SHOW CREATE TABLE。)這聽起來像您正在使用MyISAM。如果是這樣讀的話。 (如果是InnoDB,我驚訝於40秒。)

這個可能是你應該使用「垂直分區」的情況。也就是說,將LONGTEXT放在一個具有相同主鍵的並行表中。當SELECTing data...時,請使用JOIN。標記爲刪除時,您不需要觸摸第二個表格。其他兩個查詢將需要JOIN,但仍可能會更快。

編輯

由於id2VARCHAR,改變id2=5id2="5"以防止其轉化爲數字。

+0

CREATE TABLE'b'.'table'( 'id' INT(11)NOT NULL AUTO_INCREMENT, 'TradeCardId' VARCHAR(255)NOT NULL, 'TradeCardHTML' LONGTEXT NOT NULL, 'MarkForDelete' TINYINT( 4)NOT NULL DEFAULT'0', PRIMARY KEY('id'), KEY'TradeCardId'('TradeCardId') )ENGINE = INNODB DEFAULT CHARSET = utf8; 所以,引擎是正確的:InnoDB 我感到自豪,但它堅持40秒更新tinyint ... –

+0

當它發生時,運行'SHOW ENGINE INNODB STATUS;'並將其添加到您的問題。 –

+0

從表格中刪除15000行。不能重複這個問題 - 現在工作良好。但很快分析將會繼續,並且會有更多的數據。 –