While converting SQL statements for a database change, I discovered a
big performance hit in MYSQL with subqueries vices Sybase. I'm hoping
that someone might be able to help me understand why?
I have two tables USERS (2200 records) and JOB Decriptions (163
records). I wanted to retrieve all the job description not in the
USER table. (No Indexes on JOBDESC currently)
select JOBDESC from JOBS where JOBDESC not in ( select JOBDESC from
USERS where JOBDESC not NULL )
In Sybase the query returns in about .56 secs
In Mysql 4.1.7 query returns in about 8.78 secs
The funny thing is if I run the query like so
select JOBDESC from JOBS where JOBDESC not in ('President','Vice
President','Treasaur','Secretary')
returns in .03 secs.
Those four descriptions are returned by the inner select.
All select statements individually return in .03 secs.
I created indexes on both tables for JOBDESC and reduced the time to
..97 secs. I used explain command to help understand what is going on
hence the indexes, but why the difference in speed?
I would appreciate any help.
Kevin