is it okay to use the following query? how is the performance?
select * from table where id not in ( 2000 or much more ids here)
my initial test comes up very fast, but I guess it is because I am the only who is using the server right now.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you have an index it can be very fast.
However there is a bug in MySQL (possibly fixed in MySQL 5.5) where if there is no index, it won’t just be slow, it will be incredibly slow. This because the subquery can be detected as a
DEPENDENT SUBQUERY(correlated subquery) even when it is not. You can see whether MySQL is using the correct query plan by runningEXPLAIN SELECT ...and checking thatkeyis not NULL for your subquery. I have made another post about this bug with some more details:You can also consider rewriting your query to use
JOINinstead ofINto avoid this bug.