Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 2005 环境 相关子查询。对于外部集合中的每一行,必须运行相关子查询。那就够了 在WHERE子句中进行数据类型转换([value]>=convert(real,@threshold))。这是一个性能热门 @universe表变量没有主键、索引或集群 在case语句下有一个4级嵌套的相关子查询,该查询最终被转换为XML 3次 总的来说,您的存储过程做得太多了。以某种方式提前卸下这项工作。预先计算事情。添加索引。您关心报告性能,因此围绕报告和尽可能快的响应时间设计您的模式_Sql Server 2005_Optimization - Fatal编程技术网

Sql server 2005 环境 相关子查询。对于外部集合中的每一行,必须运行相关子查询。那就够了 在WHERE子句中进行数据类型转换([value]>=convert(real,@threshold))。这是一个性能热门 @universe表变量没有主键、索引或集群 在case语句下有一个4级嵌套的相关子查询,该查询最终被转换为XML 3次 总的来说,您的存储过程做得太多了。以某种方式提前卸下这项工作。预先计算事情。添加索引。您关心报告性能,因此围绕报告和尽可能快的响应时间设计您的模式

Sql server 2005 环境 相关子查询。对于外部集合中的每一行,必须运行相关子查询。那就够了 在WHERE子句中进行数据类型转换([value]>=convert(real,@threshold))。这是一个性能热门 @universe表变量没有主键、索引或集群 在case语句下有一个4级嵌套的相关子查询,该查询最终被转换为XML 3次 总的来说,您的存储过程做得太多了。以某种方式提前卸下这项工作。预先计算事情。添加索引。您关心报告性能,因此围绕报告和尽可能快的响应时间设计您的模式,sql-server-2005,optimization,Sql Server 2005,Optimization,你需要检查执行计划,寻找高成本。对过程进行小的更改,并比较之前和之后的执行计划,以了解更改对性能的影响。制定基准。知道你从哪里开始,你就能测量你已经走了多远 运行此语句,然后运行过程。 将统计信息设置为ON 去 查看结果,并查看每个涉及的表格的“逻辑读数”。那些逻辑读数最高的需要你注意。它们可以粗略地转换为对该对象上的索引的需要。似乎有很多东西可以选择来解释为什么存储过程很慢。以下是一些想法 执行计划缓存。过程是一个大的程序过程。第一次运行时,它将根据初始参数存储执行计划。根据您的表大小和索引

你需要检查执行计划,寻找高成本。对过程进行小的更改,并比较之前和之后的执行计划,以了解更改对性能的影响。制定基准。知道你从哪里开始,你就能测量你已经走了多远

运行此语句,然后运行过程。
将统计信息设置为ON 去
查看结果,并查看每个涉及的表格的“逻辑读数”。那些逻辑读数最高的需要你注意。它们可以粗略地转换为对该对象上的索引的需要。

似乎有很多东西可以选择来解释为什么存储过程很慢。以下是一些想法

  • 执行计划缓存。过程是一个大的程序过程。第一次运行时,它将根据初始参数存储执行计划。根据您的表大小和索引,首先缓存的计划可能不适合其他场景
  • 表变量。您选择使用表变量(以@开头并存在于内存中)而不是临时表(以#开头并存在于磁盘上)。这可能是好的,也可能是坏的。这取决于你的情况,但如果选择了错误的,可能会造成伤害
  • 点菜。您经常使用它们,而排序是有成本的
  • WHILE循环。非常程序化的方法。您正在使用SQL,因此应该在基于集合的环境中进行思考
  • 相关子查询。对于外部集合中的每一行,必须运行相关子查询。那就够了
  • 在WHERE子句中进行数据类型转换([value]>=convert(real,@threshold))。这是一个性能热门
  • @universe表变量没有主键、索引或集群
  • 在case语句下有一个4级嵌套的相关子查询,该查询最终被转换为XML 3次
  • 总的来说,您的存储过程做得太多了。以某种方式提前卸下这项工作。预先计算事情。添加索引。您关心报告性能,因此围绕报告和尽可能快的响应时间设计您的模式
你需要检查执行计划,寻找高成本。对过程进行小的更改,并比较之前和之后的执行计划,以了解更改对性能的影响。制定基准。知道你从哪里开始,你就能测量你已经走了多远

运行此语句,然后运行过程。
将统计信息设置为ON 去
查看结果,并查看每个涉及的表格的“逻辑读数”。那些逻辑读数最高的需要你注意。它们可以粗略地转化为对该对象的索引需求。

感谢大家的回答

我终于解决了。问题是缺少索引(例如在值字段上),现在它工作得很好

谢谢


布莱恩

谢谢大家的回答

我终于解决了。问题是缺少索引(例如在值字段上),现在它工作得很好

谢谢


Brian

您需要首先使用SQL Server profiler找出SP的哪个部分运行缓慢。一旦你有了这篇文章,这些信息就很难说了,因为SP有很多内容。您可以在某些位置打印GETDATE(),并检查SP中消耗的时间最多的位置,以确定哪一部分最慢。我很好奇您是否有丢失某些索引的问题。正如普里特所建议的,描述一下,但我认为你可能想把你的问题分为两部分。首先,找到一种快速构建五个星系的方法,然后,作为一个单独的调用,构建每个星系的信息。您能提供表定义,包括键和任何索引吗?thnx.这是探查器信息,我不知道您是否需要一些额外的信息:SQL:BatchCompleted Xinfluenced By CycloudGetXML 382,382,“T92906849551”CPU:4859读取:133177写入:0持续时间:5395 SPID:57开始时间:2009-09-04 11:31:03.427结束时间:2009-09-04 11:31:08.833您需要首先使用SQL Server profiler找出SP的哪个部分运行缓慢。一旦你有了这篇文章,这些信息就很难说了,因为SP有很多内容。您可以在某些位置打印GETDATE(),并检查SP中消耗的时间最多的位置,以确定哪一部分最慢。我很好奇您是否有丢失某些索引的问题。正如普里特所建议的,描述一下,但我认为你可能想把你的问题分为两部分。首先,找到一种快速构建五个星系的方法,然后,作为一个单独的调用,构建每个星系的信息。您能提供表定义,包括键和任何索引吗?thnx.这是探查器信息,我不知道您是否需要一些额外的信息:SQL:BatchCompleted Xinfluenced By CycloudGetXML 382382,'T92906849551'CPU:4859读取:133177写入:0持续时间:5395 SPID:57开始时间:2009-09-04 11:31:03.427结束时间:2009-09-04 11:31:08.833+1查看问题的全面列表。与WHILE循环不同,您可能希望使用一个或多个公共表表达式,这些表达式也可以递归执行(这样就可以完全替换@MMIV表)
ALTER proc [dbo].[XInfluencedByYCloudGetXml] (@VisitorId int, @VisitorIdLogged int, @mindTopicId varchar(17))
as
set nocount on
declare @threshold decimal(6,2),
        @FirstObj varchar(17),
        @GalaxyId int,
        @MainObjTitle varchar(255),
        @MyMindTopicId varchar(17),
        @CoId varchar(17)

set @threshold = 0.0001
set @GalaxyId = 1

select @MyMindTopicId = topicid from MyMindTopicVisitor where visitorid = @visitoridLogged

declare @MMIV table
(
    VisitorId int not null,
    AuthorId varchar(17) not null,
    MMIV decimal(6,4),
    PRIMARY KEY(VisitorId, AuthorId)
)


declare @Universe table
(
    GalaxyId int,
    VisitorId int,
    CoId varchar(20),
    ObjType varchar(35),
    ObjTitle varchar(255),
    ObjFontSize tinyint,
    ObjPosition tinyint
)

/* Get the most influencing authors for the visitor */
insert into @MMIV
select distinct top 5
    vi.VisitorIdX,
    vi.AuthorIdY,
    vi.[value]
from
    VisitorsInfluences vi
inner join
    tblcontentobjects co on co.coid = vi.authoridy
where
    vi.visitoridx = @visitorid
    and co.visitorid <> @visitorid
    and vi.[value] >= @threshold
group by
    vi.VisitorIdX,
    vi.AuthorIdY,
    vi.[value]
order by
    vi.[value] desc


/* Loop until MMIV is empty */
WHILE (select count(*) from @MMIV) > 0
BEGIN
    select top 1
        @FirstObj = authorid 
    from    
        @MMIV 
    order by 
        MMIV desc

    --Insert the center object in the current galaxy
    /* DEBUG:   En esta query tenes que hacer lo mismo que te dije para la font. Chequear el valor de influencia para el visitorLogged
                y dependiendo de ese valor setear el tamaño de fuente */
    insert into @Universe
    select
        @GalaxyId,
        tco.visitorid,
        @FirstObj,
        'Person',
        tco.firstname + ' ' + tco.lastname,
        case 
            when 
                (
                    select 
                        [value]
                    from
                        visitorsinfluences vi
                    where 
                        vi.visitoridx = @visitorIdLogged 
                        and vi.authoridy = tco.coid
                ) >= 0.66 
                then 5 
                else 
                    case 
                        when 
                            (
                                select 
                                    [value]
                                from
                                    visitorsinfluences vi
                                where 
                                    vi.visitoridx = @visitorIdLogged 
                                    and vi.authoridy = tco.coid
                            ) >= 0.33 
                            then 3 
                            else 1 
                    end 
        end as font,
        4
    from
        @MMIV mm
    inner join
        tblcontentobjects tco on tco.coid = mm.authorid
    where
        mm.authorid = @FirstObj

    delete from @MMIV where authorid = @FirstObj

    --Insert the cluster objects in the current galaxy
    /* DEBUG:   En esta query tenes que hacer lo que te dije para la font. Chequear el valor de influencia para el visitorLogged
                y dependiendo de ese valor setear el tamaño de fuente */
    **insert into @Universe
    select top 5
        @GalaxyId as galaxyid,
        vi.visitoridx as visitoridx,
        co.coid as coid,
        'Person' as cotype,
        co.firstname + ' ' + co.lastname as visitorname,
        case 
            when 
                (
                    select 
                        [value]
                    from
                        visitorsinfluences vi
                    where 
                        vi.visitoridx = @visitorIdLogged 
                        and vi.authoridy = co.coid
                ) >= 0.66 
                then 5 
                else 
                    case 
                        when 
                            (
                                select 
                                    [value]
                                from
                                    visitorsinfluences vi
                                where 
                                    vi.visitoridx = @visitorIdLogged 
                                    and vi.authoridy = co.coid
                            ) >= 0.33 
                            then 3 
                            else 1 
                    end 
        end as font,
        case when vi.[value] >= 0.66 then 3 else case when vi.[value] >= 0.33 then 2 else 1 end end as position
    from
        VisitorsInfluences vi   
    inner join 
        tblcontentobjects co on vi.visitoridx = co.visitorid
    left join 
        @universe u on u.coid = co.coid
    left join
        @mmiv mm on mm.authorid = co.coid
    where
        vi.authoridy = @FirstObj
        and [value] >= convert(real,@threshold)
        and vi.visitoridx <> @visitorid
        --and vi.visitoridx not in (select visitorid from @Universe)
        --and co.coid not in (select coid from @Universe)
        --and co.coid not in (select authorid from @mmiv)       
        and u.coid is null
        and mm.authorid is null
        and u.visitorid is null
    /*group by
        vi.visitoridx,
        co.coid,
        v.firstname,
        v.lastname,
        case when vi.[value] = 1 then 5 else case when vi.[value] >= (@threshold / 2) then 3 else 1 end end,
        case when vi.[value] >= 0.66 then 3 else case when vi.[value] >= 0.33 then 2 else 1 end end*/
    order by
        vi.[value] desc**




    if ((select count(*) from @Universe where GalaxyId = @GalaxyId) = 1) and @GalaxyId <= 5
    begin
        insert into @Universe
        select top 5
            @GalaxyId as galaxyid,
--              convert(varchar, vi.visitoridx) as visitoridx,
            vi.visitoridx as visitoridx,
            co.coid as coid,
            'Person' as cotype,
            v.firstname + ' ' + v.lastname as visitorname,
            0 as font,
            case when vi.[value] >= 0.66 then 3 else case when vi.[value] >= 0.33 then 2 else 1 end end as position
        from
            VisitorsInfluences vi
        inner join
            tblvisitor v on v.visitorid = vi.visitoridx
        inner join 
            tblcontentobjects co on v.visitorid = co.visitorid
        left join
            @universe u on u.coid = co.coid
        left join
            @mmiv mm on mm.authorid = co.coid
        where
            vi.authoridy=@FirstObj-- and vi.visitoridx = v.visitorid
            and vi.visitoridx <> @visitorid
--              and convert(varchar, vi.visitoridx) not in (select objid from @Universe)
            --and vi.visitoridx not in (select visitorid from @Universe)
            --and co.coid not in (select coid from @Universe)
            --and co.coid not in (select authorid from @mmiv)
            and u.coid is null
            and mm.authorid is null
            and u.visitorid is null
        order by
            vi.[value] desc
    end

--  delete from @MMIV where authorid in (select ObjId from @Universe)
    delete from @MMIV where visitorid in (select visitorid from @Universe)

    set @GalaxyId = @GalaxyId + 1
END

--Getting the XML output

select 
    @MainObjTitle = rtrim(ltrim(firstname)) + ' ' + ltrim(rtrim(lastname))
from 
    tblcontentobjects
where 
    visitorid = @visitorid

select 
    @CoId = co.coid
from
    tblcontentobjects co
where
    co.visitorid = @visitorid


SELECT
    @MainObjTitle as '@MainObjTitle',
    @CoId as '@CoId',
    (
        SELECT
            s.GalaxyID AS [@Id],
            (
                SELECT
                    U.VisitorId AS [@VisitorId],
                    U.CoId AS [@CoId],
                    U.ObjType AS [@Type],
                    U.ObjTitle AS [Title],
                    U.ObjFontSize as [FontSize],
                    U.ObjPosition as [Position],
                    co.[role] as [Role],
                    co.Affiliation as [Org],
                    case when ctr.topicid is null then 0 else 1 end as [IsInMyMind],
                    isnull(imgs.coviewurllink, '') as [coPicture],
                    case 
                        when co.visitorid is null then ''
                        when exists (
                                        select  *
                                        from    visitorrequests vrs
                                        where   vrs.RequestDate > dateadd(mi, -10, getdate()) and
                                                vrs.visitorid = co.visitorid
                                    ) then '_online'
                            else '_offline'
                    end as [IsOnline],
                    case when mctr.topicid is null then 0 else 1 end as [HasSocialNetworkProfile]
                FROM
                    @Universe AS U
                inner join  tblcontentobjects co 
--              on          convert(varchar, co.visitorid) = U.ObjId or co.coid = U.ObjId
                on          co.visitorid = U.VisitorId or co.coid = U.CoId
                inner join  tblvisitor v
                on          v.visitorid = co.visitorid
                left join
                (
                    select  img.*, cir.coidb
                    from    tblcointerrelations cir
                    inner join tblcontentobjects img
                    on      img.coid = cir.coida
                    where   img.cotype='images'
                ) imgs
                on          co.coid = imgs.coidb
                left join   tblCoTopicRelations ctr
                on          ctr.coid = co.coid and ctr.topicid = @MyMindTopicId
                left join   tblCoTopicRelations mctr
                on          mctr.coid = co.coid and mctr.topicid = @mindTopicId
                WHERE       
                    U.GalaxyID = s.GalaxyID
                ORDER BY
                    U.ObjPosition DESC
                FOR XML PATH('Object'), TYPE
            )
        FROM
            (
                SELECT      GalaxyID
                FROM        @Universe
                GROUP BY    GalaxyID
            ) AS s
        ORDER BY
            GalaxyId
        FOR XML PATH('Galaxy'), TYPE
    )
FOR XML PATH('Universe')`
while (select count(*) from @mmiv) > 0
declare @temp_count int
select @temp_count = count(*) from @mmiv

while @temp_count > 0
select @temp_count = (@temp_count - 1)