I have the following query:
SELECT
COUNT(*)
FROM
FirstTable ft
INNER JOIN SecondTable st ON ft.STID = st.STID
As you can guess, "STID" is the primary key on "SecondTable"... and "FirstTable" will have a pointer to that second table. Here are the indexes that I have:
FirstTable: NONCLUSTERED INDEX on column "STID"
SecondTable: CLUSTERED PRIMARY KEY
INDEX on "STID"
The query above gives me a subtree cost of 19.90 and takes 2 seconds.
After running the database tuning advisor for that query, they suggested making the very same index that I had on second table... but non-clustered. So I tried it with these results.
FirstTable: NONCLUSTERED INDEX on column "STID"
SecondTable: NONCLUSTERED
INDEX on "STID"
Now, the query above gives me a subtree cost of 10.97 and takes <1 second!
This 100% shatters my brain... Why would a NONCLUSTERED index perform faster than a CLUSTERED index in this scenario?