1

为什么 DNN 连续运行此查询:

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

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

USE [gssdb]

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
4

3 回答 3

0

尝试SELECT直接使用(从表中) -

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

更新2:

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
于 2013-06-10T09:43:43.417 回答
0

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

于 2013-06-10T21:58:41.857 回答
0

DEVART 的建议是正确的...尝试根据列而不是所有列进行计数,因为如果您的列列表包含例如,它会花费更长的时间来获得计数。“图像”列。

笔记-

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

于 2013-06-10T09:59:00.447 回答