Mysql IN absurdly slow, how to refactor

0

I have an inquiry like this

SELECT destinationCode 
FROM destinations 
WHERE destinationCode NOT IN (
  SELECT DISTINCT(destinationCode) FROM hotels
);

Which is absurdly slow.

I read that mysql evaluates the IN subquery for each row.

How do you think of refactoring this? I do not see it with inner joins

    
asked by Emanuel Friedrich 22.01.2018 в 14:25
source

1 answer

0

You have tried to make a left join is null ?

SELECT destinations.destinationCode FROM destinations LEFT JOIN hotels ON destinations.destinationCode = hotels.destinationCode WHERE hotels.destinationCode IS NULL;

I think it could also help to make it more agile if you add that field as an index of the table ...

    
answered by 22.01.2018 в 14:41