I have a database with data for 24million users and I want to purge 23/24ths of the data evenly across all of the tables.
The delete statements are taking hours, is there anything I can do to improve the efficency of these query:
delete from [feedback] where [key] %24<>0 and [key] not in (50697,9179, 19392753, 3780,14095, 455141,455144,1576550,719307706,10233,706507,315321,2998138,19275591,73037336,23371,11904062,08496,71959,79765,9969,02315,1850,666824,32289,826578,66284,718017,85204,192179,9406787,469844,9843,13801850,8575204,8927569)
If you intend to keep just 1/24th of the data, it will be quicker to select that data out into an alternative location, truncate the original table and copy it back.
If key constraints / operational constraints prevent this, then you should batch the deletions into chunks into a number of thousand rows per deletion, such as 10k rows per deletion and loop that command, to avoid one very large transaction (which is what is occuring with a single delete statement.)