mysqli - Better MySQL Query -


i have small email newsletter system , when new email address added (through mass import) defaults "subscribed int(11) default '1'`".

i have below query looks email address , updates in table un-subscribed :

update emaildata set subscribed =  '0' subscribed = '1' , emailaddress in  (   select emailaddress   (select emailaddress emaildata  subscribed = '0' group emailaddress) tmptable  )  

with around 5000 duplicates takes around 15 seconds execute (vm server) , wanted know if there better / faster way this?

regards, chris

you may performance below steps-

1. need change query per below-      update emaildata ed join emaildata ed1      on ed.emailaddress = ed1.emailaddress      set ed.subscribed =  '0'     ed.subscribed = '1' , ed1.subscribed = '0';  2. emailaddress field data length should short possible may varchar(50) or varchar(60) if possible.  3. make composit index on emailaddress , subscribed fields.  note: if emailaddress field text or varchar(250) etc , can't short make partial index first 50 characters enough , fast. 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -