select count 时 *速度快还是ID速度快
select count(*) from list 还是 select count(ID) from list
这两天查询语句哪个速度更快? list表大概有800多万行数据, ID是主键!
我试了一下,感觉没什么区别! 请各位大虾,亲们解答!
统计时,牵扯的表多了,有时需要10多秒才能执行完毕,纠结啊。。。! 必须优化!
附上存储过程,各位大虾看看有什么可以优化的
USE [MetenSite]
GO
/****** 对象: StoredProcedure [dbo].[GetCurrentMonthRegisterNum] 脚本日期: 06/22/2011 10:15:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[GetCurrentMonthRegisterNum](@beginTime dateTime,@endTime dateTime, @ids nvarchar(1000))
as
IF @ids IS NOT NULL
BEGIN
select
(select count(*) from dbo.Member where registerTime BETWEEN @beginTime AND @endTime AND [SupportID] IN (SELECT IDS FROM f_split(@ids, ',') )) as monthRegisterUser,
(select count(*) from dbo.CustomerList where ViewDate BETWEEN @beginTime AND @endTime AND [TID] IN (SELECT IDS FROM f_split(@ids, ',') )) as monthIp,
(select Sum(pv) from dbo.CustomerList where ViewDate BETWEEN @beginTime AND @endTime AND [TID] IN (SELECT IDS FROM f_split(@ids, ',') )) as monthPV,
(select count(*) from dbo.Member where supportId<>2 and registerTime BETWEEN @beginTime AND @endTime AND [SupportID] IN (SELECT IDS FROM f_split(@ids, ',') )) as monthSupportRegisterUser,
(select count(*) from dbo.CustomerList where TID !=-1 and ViewDate BETWEEN @beginTime AND @endTime AND [TID] IN (SELECT IDS FROM f_split(@ids, ',') )) as monthSupportIp,
(select sum(pv) from dbo.CustomerList where TID !=-1 and ViewDate BETWEEN @beginTime AND @endTime AND [TID] IN (SELECT IDS FROM f_split(@ids, ',') )) as monthSupportPV
END
ELSE
BEGIN
select
(select count(*) from dbo.Member where registerTime BETWEEN @beginTime AND @endTime) as monthRegisterUser,
(select count(*) from dbo.CustomerList where ViewDate BETWEEN @beginTime AND @endTime) as monthIp,
(select Sum(pv) from dbo.CustomerList where ViewDate BETWEEN @beginTime AND @endTime) as monthPV,
(select count(*) from dbo.Member where supportId<>2 and registerTime BETWEEN @beginTime AND @endTime ) as monthSupportRegisterUser,
(select count(*) from dbo.CustomerList where TID !=-1 and ViewDate BETWEEN @beginTime AND @endTime) as monthSupportIp,
(select sum(pv) from dbo.CustomerList where TID !=-1 and ViewDate BETWEEN @beginTime AND @endTime) as monthSupportPV
END