Mysql – DELETE LOW_PRIORITY row visibility

deletelockingmysql-5.5

I have a large MyISAM table on MySQL 5.5(Windows XP x64) on which I will have to run DELETE LOW_PRIORITY queries. Does DELETE LOW_PRIORITY make the rows invisible to SELECT statements immediately and actually delete the rows from disk when no clients are accessing the table, or is the point delaying removal of visibility?

Best Answer

The rows remain visible. Test (1) shows that the delete does not prevent any rows from being visible to subsequent queries. Test (2) illustrates the table-lock taken immediately by a normal delete - the query waits until the delete finishes and returns a zero count.

testbed and long running query:

create database stack;
use stack;
--
create table my_table (id int auto_increment primary key, varchar_val varchar(10));
insert into my_table (varchar_val)
select 'HELLO'
from (select 0 union all select 1 union all select 3 union all select 4 union all select 5 union all select 6 union all select 6 union all select 7 union all select 8 union all select 9) s1,
     (select 0 union all select 1 union all select 3 union all select 4 union all select 5 union all select 6 union all select 6 union all select 7 union all select 8 union all select 9) s2,
     (select 0 union all select 1 union all select 3 union all select 4 union all select 5 union all select 6 union all select 6 union all select 7 union all select 8 union all select 9) s3,
     (select 0 union all select 1 union all select 3 union all select 4 union all select 5 union all select 6 union all select 6 union all select 7 union all select 8 union all select 9) s4;
--
select avg(t1.id), avg(t2.id), count(*) from my_table t1 cross join my_table t2;
--

test (1): with low_priority:

--session 2:
delete low_priority from stack.my_table;
/*
Query OK, 10000 rows affected (21.84 sec)
*/

--session 3:
select count(*) from stack.my_table;
/*
+----------+
| count(*) |
+----------+
|    10000 |
+----------+
1 row in set (0.00 sec)
*/

test (2): without low_priority

--session 2:
delete low_priority from stack.my_table;
/*
Query OK, 10000 rows affected (21.15 sec)
*/

--session 3:
select count(*) from stack.my_table;
/*
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (18.10 sec)

*/