Jump to content

SQL query with LEFT JOIN ... AS d WHERE d.id IS NULL seems so slow


jamiesensei

Recommended Posts

Hi all,

 

I have a db with 7000 user records (in mdl_user) in it and around 7,000 records from another table of 28,000 records of related data (in mdl_user_info_data). I want to do a query to find all users with no related data in the second table. I tried two queries using phpmyadmin. First :

 

SELECT * FROM `mdl_user` AS u LEFT JOIN `mdl_user_info_data` as d ON (u.id=d.userid AND d.fieldid=1) WHERE d.id IS NULL

 

Then I tried a using a sub select :

 

SELECT *

FROM `mdl_user` AS u

WHERE NOT

EXISTS (

 

SELECT *

FROM `mdl_user_info_data` AS d

WHERE (

u.id = d.userid

AND d.fieldid =1

)

)

LIMIT 0 , 30

 

The first query took 229 seconds and the second took about the same.

 

Is it normal that these queries should take so long. Is there some way that I can improve the queries so that mysql can optimize them better??

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.