views:

62

answers:

1

hi i tried a select query that contains an left outer join on SQL Server CE and its taking like 30 seconds to execute.
and then i changed the same query to be an inner join and its taking less then 1 second.
the same outer query is very fast on SQL server 2008.
does anyone knows why is that?
also what is the fix for this performance problem?
i am thinking of 2 queries that i union but i don't like this solution really cause of code repetition.
thanks

Edit:
another query that have bad performance is select * from table where item not in (select item from table2)
very strange really but this query need to be changed to left outer join so the performance is fixed

+3  A: 

I found the problem
It Appears that SQL server CE have problem with optimizing outer joins.
So the problem occurs where is there is an index in one table and no index in other one.
See http://msdn.microsoft.com/en-us/library/ms172984(SQL.100).aspx the part "Limit Using Outer JOINs"
The fix was to add an index on the foreign key and the performance was fixed

Karim
Approve now you own answer as correct
abatishchev
i cant approve my own answer until 2 days are elapsed :( "You can accept your own answer in 2 days (click on this box to dismiss)"
Karim