3000多万条记录的一个表,查询很费时
一个表有3000多万条记录,做一个简单的查询 select count(*) from table ,就要3分钟才能返回结果,不知道这个算不算正常?通过资源管理器看,CPU使用率只有1%,磁盘使用率100%,难道是磁盘的速度跟不上?
------解决方案--------------------[u][/u]CREATE FUNCTION ROW_COUNT
( @table sysname )
RETURNS int
AS
BEGIN
DECLARE @row_count int
SELECT @row_count = rows FROM sysindexes
WHERE id = OBJECT_ID(@table) AND indid < 2
RETURN @row_count
END
GO
Examples
This example returns the total row count of the authors table
in the pubs database:
USE pubs
GO
SELECT dbo.ROW_COUNT('authors')
GO
------解决方案--------------------select count(*) from table
=>
select rows from sysindexes where id = object_id('表名') and indid < 2