mysql - Optimize the query time with multiple joins and cross join -


i have 3 tables given structure

cron_mails  --- contains mails fired each job ____________________________________ | id | user_id | vehicle_id | date | _____________________________________________________ cron_jobs  --- contains jobs new vehicle added users |  id  | user_id (sender_id)   | vehicle_id  | date  | _____________________________________________________   users | id    | email | email_option | status | _________________________________________   select u.id reciever_id , u.email user_email, cj.user_id sender_id ,  group_concat(cj.user_id) sender_id , group_concat(cj.vechile_id) vechile_id users u  cross join cron_jobs cj left join cron_mails cm on cj.vechile_id = cm.vechile_id                            , cm.type = 1 , cm.user_id = u.id cm.user_id null  , u.id != cj.user_id  , u.status = 1  , u.user_type = 3  , now() > cj.date  , u.email_option = 1 order cj.date 

this query taking lot of time in execution.

is there other way execute same queries?

required result find users not in corn_mails table same vehicle id having same vehicle id in cron_job table

  • users in 'user' table
  • users add jobs , jobs logged in cron_jobs table vehicle_id
  • now need find users excluding user added job users table , excluding users in cron_mails table same vehicle_id

result of explain query :

 id     select_type     table   type    possible_keys   key     key_len     ref     rows        1      simple           cj         null            null    null    null        138     using where; using temporary; using filesort  1      simple            u         null            null    null    null        983     using where; using join buffer  1      simple           cm         null            null    null    null        41872   using where; not exists 


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -