mysql - Efficiency of query using NOT IN()? -


i have query runs on server:

delete pairing id not in (select f.id info f) 

it takes 2 different tables, pairing , info , says delete entries pairing whenever id of pairing not in info.

i've run issue on server beginning take long execute, , believe has efficiency (or lack of constraints in select statement).

however, took @ mysql slow_log , number of compared entries lower should be. understanding, should o(mn) time m number of entries in pairing , n number of entries in info. number of entries in pairing 26,868 , in info 34,976.

this should add 939,735,168 comparisons. slow_log saying there 543,916,401: half amount.

i wondering if please explain me how efficiency of specific query works. realize fact it's performing quicker think should blessing in case, still need understand optimization comes can further improve upon it.

i haven't used slow query log (at all) isn't possible difference can chalked simple... can't think of word. basically, 939,735,168 theoretical worst case scenario query literally checks every single row except 1 needs first. realistically, distribution (and no use of indexing), check of row in pairing on average compare half rows in info.

it looks real world performance 15% off (worse) expected "average comparisons".

edit: actually, "worse expected" should expected when have rows in pairing not in info, skew number of comparisons.


...which still not great. if have id indexed in both tables, should work lot faster.

delete pairing  pairing left join info on pairing.id = info.id  info.id null ; 

this should take advantage of index on id make comparisons needed o(nlogm).


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -