简体   繁体   中英

Slow update/delete on InnoDB table

There is an InnoDB table:

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 

works fast

UPDATE table SET mark_for_delete=1 WHERE id2=5 

works for 40 seconds

DELETE FROM table WHERE id2=5

works for 40 seconds Deleting several rows takes the same time.

The disk reads data at a rate of 40Mb/s while executing last two queries.

How can I speed up updates and deletes?

Added from comment:

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 while running a slow query:

=====================================
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
============================

Which ENGINE? (Please provide full SHOW CREATE TABLE .) It sounds like you are using MyISAM. If so read on. (If InnoDB, I am surprised at the 40 seconds.)

This may be a case where you should use "vertical partitioning". That is, put the LONGTEXT in a parallel table with the same primary key. When SELECTing data... , use a JOIN . When marking for delete, you don't need to touch the second table. The other two queries would need a JOIN , but still might be faster.

Edit

Since id2 is VARCHAR , change id2=5 to id2="5" to keep it from converting to numeric.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM