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.
Related
I'm currently import a large CSV file and I'm trying to understand the logs that are coming into my error.log file. The import keeps on going, so this might be nothing, but given that it's logged into the error.log file with a default set-up, and I have no idea what to make out of it, it might be time for me to learn something by reaching out to the MariaDB community.
The log I'm getting is the following:
=====================================
2021-09-30 21:03:22 0x7f0848d41640 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 20 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 564 srv_active, 0 srv_shutdown, 1068 srv_idle
srv_master_thread log flush and writes: 1632
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 309014
--Thread 139674486203968 has waited at trx0undo.cc line 777 for 436.00 seconds the semaphore:
Mutex at 0x56464c440288, Mutex REDO_RSEG created trx0rseg.cc:397, lock var 2
--Thread 139673591895616 has waited at buf0flu.cc line 1214 for 431.00 seconds the semaphore:
SX-lock on RW-latch at 0x7f085fda1ab0 created in file buf0buf.cc line 1563
a writer (thread id 139673460528704) has reserved it in mode exclusive
number of readers 0, waiters flag 1, lock_word: 0
Last time write locked in file trx0rseg.ic line 43
OS WAIT ARRAY INFO: signal count 1296199
RW-shared spins 1239237, rounds 9381718, OS waits 207220
RW-excl spins 865910, rounds 6692891, OS waits 88463
RW-sx spins 375, rounds 11083, OS waits 365
Spin rounds per wait: 7.57 RW-shared, 7.73 RW-excl, 29.55 RW-sx
------------
TRANSACTIONS
------------
Trx id counter 429
Purge done for trx's n:o < 425 undo n:o < 87636886 state: running
History list length 1
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 428, ACTIVE 1482 sec inserting
mysql tables in use 1, locked 1
1 lock struct(s), heap size 1128, 0 row lock(s), undo log entries 51774178
MySQL thread id 48, OS thread handle 139674486203968, query id 78 localhost root Reading file
LOAD DATA INFILE 'file.csv' INTO TABLE TABLE_X
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
lines terminated by '\r\n'
IGNORE 1 LINES
--------
FILE I/O
--------
I/O thread 0 state: waiting for completed aio requests (insert buffer thread)
I/O thread 1 state: waiting for completed aio requests (log thread)
I/O thread 2 state: waiting for completed aio requests (read thread)
I/O thread 3 state: waiting for completed aio requests (read thread)
I/O thread 4 state: waiting for completed aio requests (read thread)
I/O thread 5 state: waiting for completed aio requests (read thread)
I/O thread 6 state: waiting for completed aio requests (write thread)
I/O thread 7 state: waiting for completed aio requests (write thread)
I/O thread 8 state: waiting for completed aio requests (write thread)
I/O thread 9 state: waiting for completed aio requests (write thread)
Pending normal aio reads: [0, 0, 0, 0] , aio writes: [0, 0, 0, 0] ,
ibuf aio reads:, log i/o's:, sync i/o's:
Pending flushes (fsync) log: 0; buffer pool: 1
452318 OS file reads, 589584 OS file writes, 172513 OS fsyncs
66.75 reads/s, 16384 avg bytes/read, 134.49 writes/s, 134.49 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2, 0 merges
merged operations:
insert 0, delete mark 0, delete 0
discarded operations:
insert 0, delete mark 0, delete 0
Hash table size 34679, node heap has 0 buffer(s)
Hash table size 34679, node heap has 104 buffer(s)
Hash table size 34679, node heap has 0 buffer(s)
Hash table size 34679, node heap has 0 buffer(s)
Hash table size 34679, node heap has 0 buffer(s)
Hash table size 34679, node heap has 0 buffer(s)
Hash table size 34679, node heap has 0 buffer(s)
Hash table size 34679, node heap has 0 buffer(s)
0.00 hash searches/s, 0.00 non-hash searches/s
---
LOG
---
Log sequence number 237726885168
Log flushed up to 237726880386
Pages flushed up to 237724062470
Last checkpoint at 237724062470
0 pending log flushes, 0 pending chkp writes
3473 log i/o's done, 0.95 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total large memory allocated 405471232
Dictionary memory allocated 24640
Buffer pool size 8192
Free buffers 0
Database pages 8088
Old database pages 3003
Modified db pages 3448
Percent of dirty pages(LRU & free pages): 42.626
Max dirty pages percent: 75.000
Pending reads 0
Pending writes: LRU 0, flush list 2, single page 1
Pages made young 1119, not young 211124188
0.00 youngs/s, 200.24 non-youngs/s
Pages read 452305, created 195449, written 499116
66.75 reads/s, 0.00 creates/s, 66.75 writes/s
Buffer pool hit rate 900 / 1000, young-making rate 0 / 1000 not 298 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 8088, unzip_LRU len: 0
I/O sum[27390]:cur[946], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
0 read views open inside InnoDB
Process ID=37451, Main thread ID=139673583502912, state: sleeping
Number of rows inserted 51774178, updated 0, deleted 0, read 0
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
Number of system rows inserted 0, updated 0, deleted 0, read 0
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================
I believe this is an output due to something timing out, but I have no idea as to what "that" could be. The import doesn't stop either, it just continues on. Any help (or pointers) on dissecting this log would be greatly appreciated!
MariaDB, myphpadmin
I dropped a table due to issues with creating FK constraint. I am trying to recreate the table but it seems like the FK constraint is still in the DB somewhere. I cannot delete as there is no reference to it, that I can see anyway. I have no idea where to look to drop the constraint
Trying to create the table I get the following error.
=====================================
2020-03-04 18:58:15 0x14c6100cc700 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 40 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 82 srv_active, 0 srv_shutdown, 53679 srv_idle
srv_master_thread log flush and writes: 53761
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 467
OS WAIT ARRAY INFO: signal count 372
RW-shared spins 0, rounds 1085, OS waits 396
RW-excl spins 0, rounds 4555, OS waits 20
RW-sx spins 3, rounds 34, OS waits 1
Spin rounds per wait: 1085.00 RW-shared, 4555.00 RW-excl, 11.33 RW-sx
------------------------
LATEST FOREIGN KEY ERROR
------------------------
2020-03-04 18:58:14 0x14c610081700 Error in foreign key constraint of table moviesdb/movie_genre:
there is no index in the table which would contain
the columns as the first columns, or the data types in the
table do not match the ones in the referenced table
or one of the ON ... SET NULL columns is declared NOT NULL. Constraint:
,
CONSTRAINT `genre_id_fk` FOREIGN KEY (`genre_id`) REFERENCES `genre` (`genre_id`) ON DELETE CASCADE ON UPDATE CASCADE
------------
TRANSACTIONS
------------
Trx id counter 237460
Purge done for trx's n:o < 237460 undo n:o < 0 state: running
History list length 1
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 304315944137048, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 304315944132792, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
--------
FILE I/O
--------
I/O thread 0 state: waiting for completed aio requests (insert buffer thread)
I/O thread 1 state: waiting for completed aio requests (log thread)
I/O thread 2 state: waiting for completed aio requests (read thread)
I/O thread 3 state: waiting for completed aio requests (read thread)
I/O thread 4 state: waiting for completed aio requests (read thread)
I/O thread 5 state: waiting for completed aio requests (read thread)
I/O thread 6 state: waiting for completed aio requests (write thread)
I/O thread 7 state: waiting for completed aio requests (write thread)
I/O thread 8 state: waiting for completed aio requests (write thread)
I/O thread 9 state: waiting for completed aio requests (write thread)
Pending normal aio reads: [0, 0, 0, 0] , aio writes: [0, 0, 0, 0] ,
ibuf aio reads:, log i/o's:, sync i/o's:
Pending flushes (fsync) log: 0; buffer pool: 0
5389 OS file reads, 3086 OS file writes, 1050 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.55 writes/s, 0.20 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2, 0 merges
merged operations:
insert 0, delete mark 0, delete 0
discarded operations:
insert 0, delete mark 0, delete 0
Hash table size 69257, node heap has 1 buffer(s)
Hash table size 69257, node heap has 2 buffer(s)
Hash table size 69257, node heap has 1 buffer(s)
Hash table size 69257, node heap has 2 buffer(s)
Hash table size 69257, node heap has 2 buffer(s)
Hash table size 69257, node heap has 2 buffer(s)
Hash table size 69257, node heap has 3 buffer(s)
Hash table size 69257, node heap has 2 buffer(s)
0.07 hash searches/s, 1.10 non-hash searches/s
---
LOG
---
Log sequence number 845237404
Log flushed up to 845237404
Pages flushed up to 845237404
Last checkpoint at 845237395
0 pending log flushes, 0 pending chkp writes
673 log i/o's done, 0.10 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total large memory allocated 285212672
Dictionary memory allocated 847024
Buffer pool size 16030
Free buffers 10583
Database pages 5432
Old database pages 2018
Modified db pages 0
Percent of dirty pages(LRU & free pages): 0.000
Max dirty pages percent: 75.000
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 0, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 5071, created 361, written 2302
0.00 reads/s, 0.10 creates/s, 0.40 writes/s
Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 5432, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
0 read views open inside InnoDB
Process ID=488, Main thread ID=22840912578304, state: sleeping
Number of rows inserted 820, updated 2, deleted 4, read 134187
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
Number of system rows inserted 0, updated 0, deleted 0, read 0
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================
The error message is right there in the log:
Error in foreign key constraint of table moviesdb/movie_genre
there is no index in the table which would contain
the columns as the first columns, or the data types in the
table do not match the ones in the referenced table
So basically this means that
either the datatype and length of column genre_id in table movie_genre is not the same as column genre_id in table genre
or: there is no index on genre (genre_id) (or in which genre_id appears first); if so, this would indicate another flaw with your table structure as, most probably, genre_id should be the primary key of the genre table.
Running a test suite with hundreds of application unit tests in a GitLab CI server. After ran 10 tests in, somehow it always gets stuck on Waiting for table metadata lock on TRUNCATE TABLE, which is a tearDown step.
I am aware of the SHOW ENGINE INNODB STATUS command . Here are some diagnostic logs:
mysql> \s
--------------
mysql Ver 14.14 Distrib 5.6.30, for Linux (x86_64) using EditLine wrapper
Connection id: 190
Current database:
Current user: root#localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.6.30 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /var/run/mysqld/mysqld.sock
Uptime: 51 min 28 sec
Threads: 4 Questions: 3859 Slow queries: 0 Opens: 715 Flush tables: 1 Open tables: 131 Queries per second avg: 1.249
--------------
mysql> show processlist;
+-----+------+----------------+------------+---------+------+---------------------------------+-----------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-----+------+----------------+------------+---------+------+---------------------------------+-----------------------------+
| 1 | root | 10.0.2.1:52773 | test_3926 | Query | 2961 | Waiting for table metadata lock | TRUNCATE TABLE `capability` |
| 188 | root | 10.0.2.1:53658 | test_3926 | Sleep | 2962 | | NULL |
| 189 | root | 10.0.2.1:53660 | test_3926 | Sleep | 2962 | | NULL |
| 190 | root | localhost | NULL | Query | 0 | init | show processlist |
+-----+------+----------------+------------+---------+------+---------------------------------+-----------------------------+
4 rows in set (0.00 sec)
2016-05-18 16:10:37 7f03be9ba700 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 7 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 126 srv_active, 0 srv_shutdown, 3047 srv_idle
srv_master_thread log flush and writes: 3173
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 2408
OS WAIT ARRAY INFO: signal count 2525
Mutex spin waits 988, rounds 24557, OS waits 747
RW-shared spins 1339, rounds 45580, OS waits 1518
RW-excl spins 3, rounds 5283, OS waits 113
Spin rounds per wait: 24.86 mutex, 34.04 RW-shared, 1761.00 RW-excl
------------
TRANSACTIONS
------------
Trx id counter 7574
Purge done for trx's n:o < 7493 undo n:o < 0 state: running but idle
History list length 778
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0, not started
MySQL thread id 190, OS thread handle 0x7f03be9ba700, query id 3941 localhost root init
SHOW ENGINE INNODB STATUS
---TRANSACTION 7489, not started
MySQL thread id 188, OS thread handle 0x7f03bea3c700, query id 3824 10.0.2.1 root cleaning up
---TRANSACTION 7548, not started
MySQL thread id 1, OS thread handle 0x7f03bea7d700, query id 3855 10.0.2.1 root Waiting for table metadata lock
TRUNCATE TABLE `capability`
---TRANSACTION 7490, ACTIVE 3047 sec
MySQL thread id 189, OS thread handle 0x7f03be9fb700, query id 3840 10.0.2.1 root cleaning up
Trx read view will not see trx with id >= 7491, sees < 7491
--------
FILE I/O
--------
I/O thread 0 state: waiting for completed aio requests (insert buffer thread)
I/O thread 1 state: waiting for completed aio requests (log thread)
I/O thread 2 state: waiting for completed aio requests (read thread)
I/O thread 3 state: waiting for completed aio requests (read thread)
I/O thread 4 state: waiting for completed aio requests (read thread)
I/O thread 5 state: waiting for completed aio requests (read thread)
I/O thread 6 state: waiting for completed aio requests (write thread)
I/O thread 7 state: waiting for completed aio requests (write thread)
I/O thread 8 state: waiting for completed aio requests (write thread)
I/O thread 9 state: waiting for completed aio requests (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: 0
Pending flushes (fsync) log: 0; buffer pool: 0
173 OS file reads, 6858 OS file writes, 6022 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2, 0 merges
merged operations:
insert 0, delete mark 0, delete 0
discarded operations:
insert 0, delete mark 0, delete 0
Hash table size 276671, node heap has 2 buffer(s)
0.00 hash searches/s, 0.00 non-hash searches/s
---
LOG
---
Log sequence number 10549488
Log flushed up to 10549488
Pages flushed up to 10549488
Last checkpoint at 10549488
0 pending log writes, 0 pending chkp writes
2555 log i/o's done, 0.00 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 137363456; in additional pool allocated 0
Dictionary memory allocated 545426
Buffer pool size 8191
Free buffers 7354
Database pages 835
Old database pages 288
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 4257, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 160, created 4341, written 863
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
No buffer pool page gets since the last printout
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 835, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
1 read views open inside InnoDB
Main thread process no. 1, id 139654053570304, state: sleeping
Number of rows inserted 1187, updated 37, deleted 0, read 650
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
Now my question is, why TRUNCATE table would get stuck on table metalock? And how can this be resolved?
The problem here seems straightforward enough.
---TRANSACTION 7490, ACTIVE 3047 sec
MySQL thread id 189, OS thread handle 0x7f03be9fb700, query id 3840 10.0.2.1 root cleaning up
Trx read view will not see trx with id >= 7491, sees < 7491
---
Thread 189 (a client connection) is idle, and as been for a while, but it has left a transaction running. This is probably a bug in the code that's using the database, since it doesn't make sense to leave a running transaction going for almost an hour.
mysql> KILL 189;
That should release the metadata lock... but you need to find out why this is happening. Bad Things™ will happen if an application doesn't behave better than this.
Also... your application should not be connecting as root. Not related to the problem, but not good, if that's what this is.
The question is already well answered by #Michael - sqlbot but I want to add some additional details. You can look through it why thread id 189 is waiting for this long.
The Waiting for table metadata lock may occur when we DELETE or CREATE an index and modify the table’s structure.
It can also occur when we perform maintenance operations on tables, DELETE tables, or try to access the WRITE lock on table-level (using this query LOCK TABLE table_name WRITE;).
Different types of active transactions can lead to metadata lock waits. Some cases are listed below where the metadata lock wait can occur.
Query to a table that has been present for a long period.
Failed to COMMIT or ROLLBACK the transaction opened implicitly or explicitly.
When we have an unsuccessful query transaction on a table.
Truncate lock bug can also occur if you have a large buffer pool, you may have noticed a complete server lock-up or stall of multiple seconds. You can find more information how this bug occur in this MySQL troubleshooting article.
I performed a schema alteration which involved (among other things) two linked tables.
DROP TABLE `Bump`; # this used to have a foreign key to Place
ALTER TABLE `Place`
...
DROP PRIMARY KEY, #it used to be a composite key from two decmals
ADD PRIMARY KEY (`id`) USING BTREE;
After that, I tried to change the engine of the table:
ALTER TABLE `Place` ENGINE = MyISAM;
But it gives me:
mysql> ALTER TABLE `mydb`.`Place` ENGINE = MyISAM;
ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails
This happens consistently for a brand-new table. Here is the trace below. But in an empty table, it does not say anything.
But for a previously populated Place, it had mentioned the Bump table by name. Why is this happening to me, when the parent table does not have its previous primary key and the child table does not exist?
I am converting to MyISAM to avoid transactions overhead for a large number of inserts.
mysql> show engine innodb status;
+--------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Type | Name | Status |
+--------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| InnoDB | |
=====================================
120806 18:49:20 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 28 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 1 1_second, 1 sleeps, 0 10_second, 1 background, 1 flush
srv_master_thread log flush and writes: 1
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 3, signal count 3
Mutex spin waits 1, rounds 30, OS waits 1
RW-shared spins 2, rounds 60, OS waits 2
RW-excl spins 0, rounds 0, OS waits 0
Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 0.00 RW-excl
------------
TRANSACTIONS
------------
Trx id counter 2D00
Purge done for trx's n:o < 2BB0 undo n:o < 0
History list length 2467
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0, not started
MySQL thread id 37, OS thread handle 0xa6affb40, query id 182 localhost root
show engine innodb status
---TRANSACTION 0, not started
MySQL thread id 36, OS thread handle 0xb625ab40, query id 177 localhost 127.0.0.1 root
--------
FILE I/O
--------
I/O thread 0 state: waiting for i/o request (insert buffer thread)
I/O thread 1 state: waiting for i/o request (log thread)
I/O thread 2 state: waiting for i/o request (read thread)
I/O thread 3 state: waiting for i/o request (read thread)
I/O thread 4 state: waiting for i/o request (read thread)
I/O thread 5 state: waiting for i/o request (read thread)
I/O thread 6 state: waiting for i/o request (write thread)
I/O thread 7 state: waiting for i/o request (write thread)
I/O thread 8 state: waiting for i/o request (write thread)
I/O thread 9 state: waiting for i/o request (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: 0
Pending flushes (fsync) log: 0; buffer pool: 0
671 OS file reads, 3 OS file writes, 3 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2, 0 merges
merged operations:
insert 0, delete mark 0, delete 0
discarded operations:
insert 0, delete mark 0, delete 0
Hash table size 553193, node heap has 2 buffer(s)
0.00 hash searches/s, 0.00 non-hash searches/s
---
LOG
---
Log sequence number 10825171
Log flushed up to 10825171
Last checkpoint at 10825171
0 pending log writes, 0 pending chkp writes
8 log i/o's done, 0.00 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 135987200; in additional pool allocated 0
Dictionary memory allocated 358285
Buffer pool size 8191
Free buffers 7529
Database pages 660
Old database pages 263
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 0, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 660, created 0, written 0
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
No buffer pool page gets since the last printout
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 660, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
1 read views open inside InnoDB
Main thread process no. 26970, id 2791775040, state: waiting for server activity
Number of rows inserted 0, updated 0, deleted 0, read 0
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================
|
+--------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
It seems that there must be another foreign key on the table (or linking to the table).
What do you get back from 'show create table mydb.Place'?
I'm having following table structure.
reservation: (InnoDB)
------------------------------------------
id INT,
date DATE,
item_id INT,
slot VARCHAR(50);
PRIMARY KEY(id), UNIQUE KEY(item_id,date).
Now i'm trying to use SELECT.....FOR UPDATE on reservation table inside a transaction to lock specific rows within date range(eg:2012-06-15 to 2012-06-16) of a particular item_id.
SELECT availability FROM reservation WHERE item_id={$item_id} AND (date>='{$to_date}' AND date<='{$from_date}') FOR UPDATE
NOW when i use the above statement, it is blocking all the rows of particular item_id even beyond the date range.I'm also using this UNIQUE KEY(item_id,date).
How to lock only particular date range of a specific item_id?
regards,
ravi.
ADDED:
|
=====================================
120615 20:14:13 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 24 seconds
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 12, signal count 12
Mutex spin waits 0, rounds 180, OS waits 4
RW-shared spins 10, OS waits 5; RW-excl spins 2, OS waits 2
------------
TRANSACTIONS
------------
Trx id counter 0 15147
Purge done for trx's n:o < 0 15136 undo n:o < 0 0
History list length 2
Total number of lock structs in row lock hash table 2
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0 0, not started, OS thread id 2940
MySQL thread id 76, query id 1487 localhost 127.0.0.1 root
SHOW innodb status
---TRANSACTION 0 15143, not started, OS thread id 2588
MySQL thread id 10, query id 578 localhost 127.0.0.1 root
---TRANSACTION 0 15144, ACTIVE 11526 sec, OS thread id 2740
3 lock struct(s), heap size 320
MySQL thread id 11, query id 577 localhost 127.0.0.1 root
--------
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 (write thread)
Pending normal aio reads: 0, aio writes: 0,
ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
Pending flushes (fsync) log: 0; buffer pool: 0
187 OS file reads, 75 OS file writes, 29 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 0, seg size 2,
0 inserts, 0 merged recs, 0 merges
Hash table size 62383, used cells 0, node heap has 1 buffer(s)
0.00 hash searches/s, 0.00 non-hash searches/s
---
LOG
---
Log sequence number 0 8287163
Log flushed up to 0 8287163
Last checkpoint at 0 8287163
0 pending log writes, 0 pending chkp writes
24 log i/o's done, 0.00 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 23277934; in additional pool allocated 1430400
Buffer pool size 960
Free buffers 895
Database pages 64
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages read 64, created 0, written 51
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 1000 / 1000
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
1 read views open inside InnoDB
Main thread id 1544, state: waiting for server activity
Number of rows inserted 10, updated 0, deleted 0, read 66
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================
|