June 28, 2010 at 3:46 pm
Have you tried forcing it to used the clustered index with a query hint?
I know that index is bigger, and SQL is probably not choosing it for a good reason, but I just wondered if the clustered index would scan faster since it's physically contiguous.
June 28, 2010 at 3:47 pm
ya i thought of that about 8mins ago, the query is still running.
June 28, 2010 at 3:49 pm
Jeff Moden (6/28/2010)
@Jason,The SQLPlan you posted seems to be an "estimated" plan... can you include an "Actual" plan?
Now THAT's interesting... although an INDEX SEEK is listed, no predicates are listed and the entire table is being scanned. Of course, even seeking (turns into a range scan in this case) a 2 billion row table is going to be a bit slow. Do ALL the rows in the table meet the date criteria? In other words, does the table contain only data that meets the date criteria?
--Jeff Moden
Change is inevitable... Change for the better is not.
June 28, 2010 at 3:54 pm
Jeff Moden (6/28/2010)
Jeff Moden (6/28/2010)
@Jason,The SQLPlan you posted seems to be an "estimated" plan... can you include an "Actual" plan?
Now THAT's interesting... although an INDEX SEEK is listed, no predicates are listed and the entire table is being scanned. Of course, even seeking (turns into a range scan in this case) a 2 billion row table is going to be a bit slow. Do ALL the rows in the table meet the date criteria? In other words, does the table contain only data that meets the date criteria?
I think you might be right about that, it appears the where clause on this is pointless at least on the production box, It might have been left over from development. I'll try it without it and see how long it takes.
June 28, 2010 at 4:04 pm
Ya it still took about 6mins. There is the plan.
June 28, 2010 at 8:54 pm
Why not try this:
select max(tbl.rn) from
(
select row_number() over(order by [SkuNumber]) rn from BALEOD2009
) tbl
It might produce the "baddest" ever result, but u can just try it out..:w00t:
June 28, 2010 at 11:12 pm
or:
Declare @r_Count1 bigint
select top 1 @r_Count1 = tbl.rn from
(
select row_number() over(order by (select 0)) rn
from MyTable
) tbl
order by tbl.rn desc
SELECT @r_Count1
I put COUNT(*) and ROW_NUMBER() to test and found count(*) is way above ROW_NUMBER() in performance..
************* COUNT(*)
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 1 ms.
SQL Server Execution Times:
CPU time = 3920 ms, elapsed time = 1095 ms.
************* row_number()
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 1 ms.
SQL Server Execution Times:
CPU time = 8578 ms, elapsed time = 8380 ms.
Hmmm.....
June 29, 2010 at 8:13 am
I didnt have any luck with these queries.
June 29, 2010 at 8:19 am
Jason Messersmith (6/29/2010)
I didnt have any luck with these queries.
:doze: i dint quite get u , Jason ; pls elaborate !
June 29, 2010 at 8:28 am
Have you ever updated statistics on this table? 😀
June 29, 2010 at 8:45 am
ColdCoffee (6/29/2010)
Jason Messersmith (6/29/2010)
I didnt have any luck with these queries.:doze: i dint quite get u , Jason ; pls elaborate !
they ran for about 10mins and I shut them down.
June 29, 2010 at 8:46 am
Eugene Elutin (6/29/2010)
Have you ever updated statistics on this table? 😀
That's a good call, I'll give that a try and let you know.
June 29, 2010 at 10:59 am
I would probably use:
select sum(rows)
from sys.partitions
where
index_id <= 1
and
object_id = object_id('[dbo].[BALEOD2009]')
Even if Microsoft has described the rows field as "approximate number of rows" I still have not seen a single case when this value has been wrong compared to COUNT(*)
I suppose that there might be some problem if you make this query while there are insert or delete operations in progress, but if you do it on a silent table the result is in my experience accurate.
You can test it for a while in your environment.
Use the query above and your standard COUNT(*) and compare the results. If there are no differences for a week maybe you can start trusting the values from sys.partitions.
June 29, 2010 at 4:33 pm
Jason Messersmith (6/29/2010)
Eugene Elutin (6/29/2010)
Have you ever updated statistics on this table? 😀That's a good call, I'll give that a try and let you know.
Have you tried?
June 30, 2010 at 8:13 am
No dice on the updating of stats, It still takes about the same amount of time. 5-6mins.
I'm going to start logging from a few system views and see if those are accurate enough like Stefan_G said.
Viewing 15 posts - 16 through 30 (of 33 total)
You must be logged in to reply to this topic. Login to reply