select docid from A where docid IN ( select distinct(docid) from B)
When I execute above query in mysql it takes 33 seconds, which is too long as per the size of data.
Below is the details of both tables.
Table A :
| docid | int(11) | NO | PRI | NULL | |
Total number of entries = 500 (all entries are unique)
Table B:
| docid | int(11) | YES | | NULL | |
Total number of entries = 66508
(number of unique entries are 500)
mysql version : 5.2
If I execute only select docid from A it will take 0.00 seconds,
while select docid from B is taking 0.07 seconds.
Then why IN query with subquery takes 33 seconds? Am I doing something wrong?
desc select docid from A where docid IN ( select distinct(docid) from B);-- the overhead is because of the number rows require to scan in order to match theIN()