473,408 Members | 1,601 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Speed of InnoDB DELETEs on large tables

I am finding delete queries on large InnoDB tables very slow - are
there ways to speed this up?

I have a table with about 100 million rows:

I am trying to delete just a few of these rows (the following select
takes a couple of seconds):
SELECT count(*) -> FROM UserSnap
-> WHERE LogDate<now() - INTERVAL 750 DAY;
+----------+
| count(*) |
+----------+
| 308969 |
+----------+
DELETE FROM UserSnap WHERE LogDate<now() - INTERVAL 750 DAY;
That delete query takes hours to run. The structure of the table is:
desc UserSnap;

+----------+-------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------------------+-------+
| LogDate | datetime | | PRI | 0000-00-00 00:00:00 | |
| Period | tinyint(4) | | PRI | 0 | |
| UserName | varchar(50) | | PRI | | |
| RateType | varchar(50) | | PRI | default | |
| Rate | float | YES | | NULL | |
+----------+-------------+------+-----+---------------------+-------+

Any suggestions on why this is slow, and what to do about it?
Jul 20 '05 #1
3 17626
I too discovered that InnoDB tables are horrible when it comes to deletions.

I have found that increasing the key_buffer_size will speed up deletes on
very large tables. Also, the number of indexes on a table directly affects
the performance of the delete.

Another thing to be concerned about is data file fragmentation and slow
overall performance for InnoDB tables. If you have a table that
continuously grows and you want to delete the oldest records, oldest is
maintained by insertion time, then you can use an auto_increment column as
your table index. The count of records in such a table is very fast to
compute, and deletion by this index can be fast as well.
"Jeremy Howard" <j+******@howard.fm> wrote in message
news:27*************************@posting.google.co m...
I am finding delete queries on large InnoDB tables very slow - are
there ways to speed this up?

I have a table with about 100 million rows:

I am trying to delete just a few of these rows (the following select
takes a couple of seconds):
SELECT count(*)

-> FROM UserSnap
-> WHERE LogDate<now() - INTERVAL 750 DAY;
+----------+
| count(*) |
+----------+
| 308969 |
+----------+
DELETE FROM UserSnap WHERE LogDate<now() - INTERVAL 750 DAY;


That delete query takes hours to run. The structure of the table is:
desc UserSnap;

+----------+-------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------------------+-------+
| LogDate | datetime | | PRI | 0000-00-00 00:00:00 | |
| Period | tinyint(4) | | PRI | 0 | |
| UserName | varchar(50) | | PRI | | |
| RateType | varchar(50) | | PRI | default | |
| Rate | float | YES | | NULL | |
+----------+-------------+------+-----+---------------------+-------+

Any suggestions on why this is slow, and what to do about it?

Jul 20 '05 #2
"Steve McGregory" <st************@yahoo.com> wrote in message news:<cB****************@newssvr22.news.prodigy.co m>...
I too discovered that InnoDB tables are horrible when it comes to deletions.

I have found that increasing the key_buffer_size will speed up deletes on
very large tables. Also, the number of indexes on a table directly affects
the performance of the delete.
OK I'll try that - thanks.
Another thing to be concerned about is data file fragmentation and slow
overall performance for InnoDB tables. If you have a table that
continuously grows and you want to delete the oldest records, oldest is
maintained by insertion time, then you can use an auto_increment column as
your table index. The count of records in such a table is very fast to
compute, and deletion by this index can be fast as well.
That's a great idea - exactly the situation I'm in. I'll give that a
try - something like 'SELECT @m_id=MAX(ID) FROM tbl WHERE
LastUpdate>@time; DELETE FROM tbl WHERE ID<@m_id;' I guess...
"Jeremy Howard" <j+******@howard.fm> wrote in message
news:27*************************@posting.google.co m...
I am finding delete queries on large InnoDB tables very slow - are
there ways to speed this up?

I have a table with about 100 million rows:

I am trying to delete just a few of these rows (the following select
takes a couple of seconds):
SELECT count(*)

-> FROM UserSnap
-> WHERE LogDate<now() - INTERVAL 750 DAY;
+----------+
| count(*) |

+----------+
| 308969 |
+----------+
DELETE FROM UserSnap WHERE LogDate<now() - INTERVAL 750 DAY;


That delete query takes hours to run. The structure of the table is:
desc UserSnap;

+----------+-------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |

+----------+-------------+------+-----+---------------------+-------+
| LogDate | datetime | | PRI | 0000-00-00 00:00:00 | |
| Period | tinyint(4) | | PRI | 0 | |
| UserName | varchar(50) | | PRI | | |
| RateType | varchar(50) | | PRI | default | |
| Rate | float | YES | | NULL | |
+----------+-------------+------+-----+---------------------+-------+

Any suggestions on why this is slow, and what to do about it?

Jul 20 '05 #3
You got it, however MySQL is horrible with < than arguments on a query. I'd
recommend that you
use a between;

SELECT @l_id=MIN(ID) FROM tbl; SELECT @m_id=MAX(ID) FROM tbl WHERE
LastUpdate>@time; DELETE FROM tbl WHERE ID between @l_id and @m_id;

Also, when I'm deleting out of our system, usually in the order of many
millions at a time, I
split the deletion into chunks.

"Jeremy Howard" <j+******@howard.fm> wrote in message
news:27**************************@posting.google.c om...
"Steve McGregory" <st************@yahoo.com> wrote in message

news:<cB****************@newssvr22.news.prodigy.co m>...
I too discovered that InnoDB tables are horrible when it comes to deletions.
I have found that increasing the key_buffer_size will speed up deletes on very large tables. Also, the number of indexes on a table directly affects the performance of the delete.


OK I'll try that - thanks.
Another thing to be concerned about is data file fragmentation and slow
overall performance for InnoDB tables. If you have a table that
continuously grows and you want to delete the oldest records, oldest is
maintained by insertion time, then you can use an auto_increment column as your table index. The count of records in such a table is very fast to
compute, and deletion by this index can be fast as well.


That's a great idea - exactly the situation I'm in. I'll give that a
try - something like 'SELECT @m_id=MAX(ID) FROM tbl WHERE
LastUpdate>@time; DELETE FROM tbl WHERE ID<@m_id;' I guess...
"Jeremy Howard" <j+******@howard.fm> wrote in message
news:27*************************@posting.google.co m...
I am finding delete queries on large InnoDB tables very slow - are
there ways to speed this up?

I have a table with about 100 million rows:

I am trying to delete just a few of these rows (the following select
takes a couple of seconds):

> SELECT count(*)
-> FROM UserSnap
-> WHERE LogDate<now() - INTERVAL 750 DAY;
+----------+
| count(*) |

+----------+
| 308969 |
+----------+

> DELETE FROM UserSnap WHERE LogDate<now() - INTERVAL 750 DAY;

That delete query takes hours to run. The structure of the table is:

> desc UserSnap;

+----------+-------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |

+----------+-------------+------+-----+---------------------+-------+
| LogDate | datetime | | PRI | 0000-00-00 00:00:00 | |
| Period | tinyint(4) | | PRI | 0 | |
| UserName | varchar(50) | | PRI | | |
| RateType | varchar(50) | | PRI | default | |
| Rate | float | YES | | NULL | |
+----------+-------------+------+-----+---------------------+-------+

Any suggestions on why this is slow, and what to do about it?

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: StealthBananaT | last post by:
My database has two tables - films has 10,000 records and reviews has 20,000 records. Whenever I try to list all the films and the count of its reviews, MySQL locks and I have to restart the...
2
by: Kevin Crosbie | last post by:
Hi all, (Sorry for the cross-post, there doesn't appear to be much activity on comp.database.oracle)I'm trying to get the last 300 rows from the difference between 2 large tables and my queries...
0
by: Joseph Norris | last post by:
Group, I have been working with Mysql for about 5 years - mainly in LAMP shops. The tables have been between 20-100 thousand records size. Now I have a project where the tables are in the...
3
by: Jeremy Howard | last post by:
I am finding delete queries on large InnoDB tables very slow - are there ways to speed this up? I have a table with about 100 million rows: I am trying to delete just a few of these rows (the...
57
by: Bing Wu | last post by:
Hi all, I am running a database containing large datasets: frames: 20 thousand rows, coordinates: 170 million row. The database has been implemented with: IBM DB2 v8.1
1
by: Cedric | last post by:
We have a table in db2 that has about 40 million rows added to it daily and want to keep a rolling period of 180 days worth of data on the table. We want to remove either one day or a few days...
2
by: Molly | last post by:
Does anyone know of any good tools for fast, on-line reorgs of a very large DB2 UDB table? We need to reorg a couple of our large (+1 billion rows) tables. We migrated from V7.2 to V8.1, but we...
1
by: Dino Vliet | last post by:
Hi folks, I'm busy with analyzing some data and therefore will have to store 2 big tables containing 50 million obs & 25 million obs. Selecting some interesting obs can decrease these tables with...
4
by: jswill | last post by:
The main problems are: - adding rows to tables via appendChild is slow if there is markup in any cell. (My rows have only 3-8 cells) - the same markup seems to increase the "lag" time to...
1
by: ozzii | last post by:
Hi, I have a table called products which consist of various supplier products and has the following fields: ID int not null primary key auto_increment SupplierID int not null ProductCode...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.