SELECT object_oid,
       parent_oid,
       object_type,
       filetype,
       token
FROM TemporaryFiles
WHERE token NOT IN (SELECT DISTINCT
                           TemporaryFiles.token
                    FROM TemporaryFiles
                         INNER JOIN Tokens ON TemporaryFiles.token = Tokens.token);
TemporaryFiles Table - Table has around ~5,000 Rows
----------------------------------------------------
Column Name     DataType
OBJECT_OID      int 
PARENT_OID      int 
OBJECT_TYPE     varchar(100)    
FileType        varchar(255)    
Token           varchar(255)    
DBKEY           int    ------------------------Primary Key
This table has one clustered index on Primary Key DBKey
Tokens Table - Table has around ~900,000 Rows
--------------------------------------------------------------
Column Name     DataType
OBJECT_OID      int
PARENT_OID      int
OBJECT_TYPE     nvarchar(64)
CHILD_TYPE      nvarchar(64)
FileType        nvarchar(32)
Token           nvarchar(255)
CreationTime    datetime
Contextual      bit
DBKEY           int      ------------------------Primary Key
There is one clustered index on Primary Key on DBKey And one non clustered index on OBJECT_OID ,OBJECT_TYPE,Contextual,
I tried to create one more non clustered index on Token for both tables. Still the query is taking infinite time to execute.
Even i tried to change "Not in" to "NOT EXIST" statement. But still issue i see.