I've got a strange problem with SQL Server 2000, and I just can't think of a reason for this to happen.
There are two tables, both having a combined primary key with a clustered index on it, both keys have the same structure:
(VARCHAR(11), INT, DATETIME) /* can't change this, so don't suggest I should */
So, joining them like this is easy enough:
SELECT t1.Foo, t2.Bar
FROM table1 t1 INNER JOIN table2 t2 ON t1.VarcharKey = t2.VarcharKey
WHERE t1.VarcharKey = 'Foo'
Looking at the query execution plan, I see this:
- Clustered Index Seek [db].[dbo].[table1].[PK_table1] (48%)
- Clustered Index Seek [db].[dbo].[table2].[PK_table2] (51%)
- Nested Loops (Inner Join) (1%) Warning: NO JOIN PREDICATE
- Select (0%)
Now if I do this (note the NVARCHAR string!):
SELECT t1.Foo, t2.Bar
FROM table1 t1 INNER JOIN table2 t2 ON t1.VarcharKey = t2.VarcharKey
WHERE t1.VarcharKey = N'Foo'
I get:
- Clustered Index Scan [db].[dbo].[table1].[PK_table1] (98%)
- Clustered Index Seek [db].[dbo].[table2].[PK_table2] (1%)
- Nested Loops (Inner Join) (1%) no warning here
- Select (0%)
This behavior leaves me a bit puzzled.
- Why is there a "NO JOIN PREDICATE" warning, and why does it go away when I change
'Foo'
toN'Foo'
? My key columns are not of type NVARCHAR, so this should not make any difference, or should it? - Does the presence of this warning have negative implications or can I ignore it?
- Why does it switch from an Index Seek to an Index Scan?
Some background info: Table cardinality is ca. 25,000 records one table, ca. 12,000 records in the other. Database compatibility level is 80 (SQL Server 2000) default collation is SQL_Latin1_General_CP1_CI_AS
, if that makes any difference at all.
Here's the contents of @@VERSION
:
Microsoft SQL Server 2000 - 8.00.2273 (Intel X86) Mar 7 2008 22:19:58 Copyright (c) 1988-2003 Microsoft Corporation Enterprise Edition on Windows NT 5.0 (Build 2195: Service Pack 4)
P.S.: I am aware of KB322854, but this is not it, obviously.