DNN计数用户查询

时间:2013-06-10 09:35:55

标签: sql-server performance tsql dotnetnuke

为什么DNN会不断运行此查询:

Select count(*) 
from dbo.DNN_vw_users 
where portalID = @PortalID and IsDeleted = 0

此查询占用的总CPU时间超过600,000毫秒且仍在增加。

USE [gssdb]

GO

ALTER VIEW [dbo].[DNN_vw_Users]  

AS
SELECT     
    U.UserID, 
    UP.PortalId, 
    U.Username, 
    U.FirstName, 
    U.LastName, 
    U.DisplayName, 
    U.IsSuperUser, 
    U.Email, 
    U.AffiliateId, 
    U.UpdatePassword, 
    UP.Authorised, 
            (CASE WHEN UP.PortalId IS NULL THEN U.IsDeleted ELSE UP.IsDeleted END) AS IsDeleted, 
    UP.RefreshRoles, 
    U.LastIPAddress,
    U.CreatedByUserID, 
    U.CreatedOnDate, 
    U.LastModifiedByUserID, 
    U.LastModifiedOnDate
FROM dbo.DNN_Users AS U 
    LEFT OUTER JOIN dbo.DNN_UserPortals AS UP ON U.UserID = UP.UserId

3 个答案:

答案 0 :(得分:0)

尝试直接使用SELECT(来自表格) -

SELECT COUNT(1)
FROM dbo.DNN_tbl_users
WHERE portalID = @PortalID
    AND IsDeleted = 0

UPDATE2:

SELECT COUNT(1)
FROM dbo.DNN_Users U --WITH(NOWAIT)
WHERE U.IsDeleted = 0
    AND U.UserID IN (
        SELECT UP.UserID
        FROM dbo.DNN_UserPortals UP --WITH(NOWAIT)
        WHERE UP.portalID = @PortalID
            AND UP.IsDeleted = 0
    )

更新3:

SELECT COUNT(1)
FROM dbo.DNN_Users U --WITH(NOWAIT)
JOIN (
    SELECT UP.UserID
    FROM dbo.DNN_UserPortals UP --WITH(NOWAIT)
    WHERE UP.portalID = @PortalID
        AND UP.IsDeleted = 0
) UP ON U.UserID = UP.UserID

答案 1 :(得分:0)

DEVART建议的是正确的...尝试依靠列而不是所有列,因为如果你的列列表包含例如,它会花费更长的时间来获取计数。一个“图像”栏目。

注 -

如果上面的情况并非如此,我想建议如果你是出于某种目的对某些东西进行单元测试,那么你暂时删除视图或表上的事务,以便计数查询给你有限的时间,因为它将没有交易。但请确保当我提到单元测试时,我认为您不在生产数据库/环境中,因为这会对在该环境中删除事务产生灾难性影响。

答案 2 :(得分:0)

如果您未使用DNN的“用户在线”功能,则可以在“主机设置”中禁用该功能。我想这可能是导致计数持续运行的原因。