sql - How to use EXIST to improve speed in mySQL subquery? -


i stuck query below. takes forever complete query. have been using describe me find best way pull data. can come far. take forever pull 1000 records . recommendations / suggestions on how approve issue ? i'm stuck.

i have read "exists" can use improve subquery , not quite understand how work in situation.

i have used primary keys as ( id , contact_id , flag_if ) => ending _id primary keys.

thanks.

select ac.id,       acc.category,       ac.value,        fg.*  contact ac join application app on app.id = ac.id join category acc using (contact_id)  left join (select af.name_short                  ,att.value                  ,att.flag_id     attribute att         left join attribute_flag af on af.flag_id = att.flag_id         left join application app on                  (       (att.level = 'customer' , att.related_id = app.customer_id)                         or  (att.level = 'application' , att.related_id = app.id)                                  )         app.id in  (001,002,003)                 ) fg on ac.value = fg.value  ac.id in  (001,002,003) 

== update == here result explain query'

enter image description here


Comments