New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
Comments
Mentioned already, I don't have direct control over it. Someone else decided that design.
if they need tableB as log of deleted records then you need tableC for this process or you may die in the intent
iowait ?
Nope, its not log of deleted records from tableA, its more like a log of records to be deleted from tableA.
iostat when running the query :
trying to clarify:
foremost it is simply faster to join the smaller table on the right side of the bigger table, hence why using LEFT JOIN , besides using this to filter out only matching entries.
hmm, just to have that clarified, those accessIDs are occuring totally and overall only ONCE in the whole table A?
(that would be more like my first setup which proved the left join to be very fast)
I did try a somewhat other approach, consisting of concatinating the whole table B into one single string with GROUP_CONCAT to search for accessIDs in this string without the need to run a subquery select against table B every time.
(I omitted the semicolon from every line, as cloudflare would not let me post it otherwise)
this took around 75 seconds to erase around 400k entries from table A ...
yet you have to note that you need to raise group_concat_max_len even more to gather all entries on table B which for sure will increase time taken for the delete againby factors.
25k of 10 digit entries will need >250k as limit... and raising this only worked global for me, which probably wont be the case in every case as you may not have be granted permissions to do so...
actually I am out of further ideas, haven't tried or measured the table copy process suggested by @elgs but as it does also check every single row from table A against a subquery asking for the accessID in table B I'd guess it won't be faster after all.
Thanks for your time @Falzo, really appreciate it.
So, I looked into lots of things, CPU time, disk io, even tried ram disk.. however, solution came when I just added index to tableA.accessID and bam.. same query finished in 0.29 sec. Earlier had added to tableB but had no effect as I remember because it was the first thing I did.
Feeling duped and stupid as from last 3-4 days, was not able to think of anything else apart of this issue..
INSERT in Mysql is much faster than DELETE. This is the normal way we use to remove part of data from large data set, especially removing the tailing data on a rolling widow of a period of time, a year, let's say. As the OP is using MyISAM, rather than Innodb, ACID is not applicable for MyISAM. There is no reason not to give a try.
IN is slowest, IN should be replaced by EXISTS at least.
yes I agree on that, but the thing that may break the times spend on running the whole is the subquery itself, which has to be run for every row from the large table. even if that small select is done in 0.001 seconds it will add up with 500k rows ;-)
I'll go and verify that later, yet I can say that this most likely may be the cause, as I also removed the index on my table at some point while trying to reproduce your issues...
glad you found a way to fix it though. kind of a weird thing but good example about how important correct use of indizes is...
Yes , and it also refreshed some of my know-how about mysql I did years back..