Today I came across an interesting performance issue with a stored procedure running on Sql Server 2005 SP2 in db running at compatible level 80 (SQL2000).
The run lasts about 8 minutes, and the execution plan indicates the use of an index with the actual number of rows 1.339.241.423, which is about 1000 times higher than the actual actual row number of the table, which is 1.144.640 as shown by the correctly estimated number of rows. So the actual row count set by the query plan optimizer is definitely wrong!

It is interesting that when copying the values ββof procs parameters inside proc into local variables and using local variables in a real query, everything works fine - proc works for 18 seconds, and the correct actual line counter is displayed in the execution plan.
EDIT: As suggested by TrickyNixon, this seems to be a sign of the problem of sniffing a parameter. But in fact, I get in both cases the exact execution plan. The same indexes are used in the same order. The only difference I see is the path to the high actual number of rows in the PK_ED_Transitions index with direct use of parametervalues.
I have been doing dbcc dbreindex and UPDATE STATISTICS without any success. dbcc show_statistics also shows good data for the index.
The process is created using RECOMPILE, so every time it starts a new execution plan, compilation takes place.
To be more specific - this one runs quickly:
CREATE Proc [dbo].[myProc]( @Param datetime ) WITH RECOMPILE as set nocount on declare @local datetime set @local = @Param select some columns from table1 where column = @local group by some other columns
And this version is very slow, but it creates exactly the same execution plan (in addition to the very high actual number of rows in the index used):
CREATE Proc [dbo].[myProc]( @Param datetime ) WITH RECOMPILE as set nocount on select some columns from table1 where column = @Param group by some other columns
Any ideas? Does anyone know where Sql Server gets the actual row counter value when calculating query plans?
Update . I tried the request on another server if the copy mode is set to 90 (Sql2005). This is the same behavior. I think I will open the ms support call because it looks like an error.