![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hello, I want to delete a large amount of records (~200K) from a large table (~500K records) in my MySql DB. I want to make this call as efficient as possible because i dont want the DB to become "unresponsive" while executing the call. I need to delete records that are "older" than 10 days (according to created_at column), currently I use: delete from table_name where created_at< DATE_SUB(CURDATE(),INTERVAL 10 DAY) The table also have a primary key id if it helps. Any thoughts? |
#3
| |||
| |||
|
|
Hello, I want to delete a large amount of records (~200K) from a large table (~500K records) in my MySql DB. I want to make this call as efficient as possible because i dont want the DB to become "unresponsive" while executing the call. I need to delete records that are "older" than 10 days (according to created_at column), currently I use: delete from table_name where created_at < DATE_SUB(CURDATE(),INTERVAL 10 DAY) The table also have a primary key id if it helps. Any thoughts? |
#4
| |||
| |||
|
|
On 3/25/2011 11:06 AM, Ran Margaliot wrote: Hello, I want to delete a large amount of records (~200K) from a large table (~500K records) in my MySql DB. I want to make this call as efficient as possible because i dont want the DB to become "unresponsive" while executing the call. I need to delete records that are "older" than 10 days (according to created_at column), currently I use: delete from table_name where created_at< DATE_SUB(CURDATE(),INTERVAL 10 DAY) The table also have a primary key id if it helps. Any thoughts? Your primary key would have no effect in a case like this. First thing to do is to EXPLAIN your query and see if there are any indexes being used (i.e. is there an index on created_at?). Also: How often are you running this query? How long does it take to run currently? What is the age range of the rows you want to delete? |
#5
| |||
| |||
|
|
I want to delete a large amount of records (~200K) from a large table (~500K records) in my MySql DB. I want to make this call as efficient as possible because i dont want the DB to become "unresponsive" while executing the call. I need to delete records that are "older" than 10 days (according to created_at column), currently I use: delete from table_name where created_at< DATE_SUB(CURDATE(),INTERVAL 10 DAY) The table also have a primary key id if it helps. Any thoughts? |
#6
| ||||
| ||||
|
|
I want to delete a large amount of records (~200K) from a large table (~500K records) in my MySql DB. |
|
I want to make this call as efficient as possible because i dont want the DB to become "unresponsive" while executing the call. I need to |
|
delete records that are "older" than 10 days (according to created_at column), currently I use: delete from table_name where created_at < DATE_SUB(CURDATE(),INTERVAL 10 DAY) |
|
The table also have a primary key id if it helps. |
#7
| |||
| |||
|
|
I want to delete a large amount of records (~200K) from a large table (~500K records) in my MySql DB. For "large" read "small". I want to make this call as efficient as possible because i dont want the DB to become "unresponsive" while executing the call. I need to Efficiency may not be the issue here. If the DELETE query keeps the table locked, it may block queries that modify that table. I recall having a problem with this on an older system, expiring old login records. (Perhaps deleting 20 million records out of 250 million daily). Initially, with once-a-day expiration, it locked up the table for 45 minutes. Not good. As this was a 24x7 operation, doing it overnight still caused problems. Some caveats on this example: 1) It used 10-year-old hardware. 2) It used MyISAM tables (InnoDB wasn't around or not mature enough then). InnoDB I believe uses more selective locking. 3) Finding the records to delete wasn't the issue (with an appropriate index); it seemed that actually deleting the records was taking the time. 4) MySQL has improved a lot since then. 5) Running the query more often, and with LIMIT, divided the lockout into shorter lockouts that were more tolerable. However, from the point of view of server load, this was a LOT less efficient, as it was finding the records 100 times a day instead of once. |
![]() |
| Thread Tools | |
| Display Modes | |
| |