0

I have a table with several hundred million rows of data. I want to delete the table, but every operation I perform on the table loses connection after running for 50,000+ seconds (about 16 hours), which is under the 60,000 second time out condition I have set in the database. I've tried creating a stored procedure with the Drop Table code thinking that if I send the info to the DB to perform the operation it will not need a connection to process it, but it does the same thing. Is it just timing out? Or do I need to do something else?

1 Answers1

0

Instead do TRUNCATE TABLE. Internally it creates an equivalent, but empty, table, then swaps. This technique might take a second, even for a very big table.

If you are deleting most of a table, then it is usually faster (sometimes a lot faster), to do

CREATE TABLE new LIKE real;
INSERT INTO new
    SELECT ... FROM real
        WHERE ... -- the rows you want to keep

Why do you need to delete everything?

For other techniques in massive deletes, including big chunks out of a huge table, see https://mariadb.com/kb/en/mariadb/big-deletes/

Rick James
  • 135,179
  • 13
  • 127
  • 222
  • I tried TRUNCATE also, but it just runs until it times out. I changed the time out session limit and am trying these methods again. I'm deleting because every time I run a query on the table it times out close to the original 60,000 seconds. So, I was hoping to just start over and split the table into smaller segments in order to reduce the time for queries. There is also duplicate information in the table, so it made sense to just start over. – VaderFlavoredIceCream Jun 06 '17 at 02:32
  • InnoDB should have "rolled back" the inserts if it died before finishing??? Please provide `SHOW CREATE TABLE`. – Rick James Jun 06 '17 at 02:36