Improved getAnnotationAuditsChronologyByItemIDandUnitID execution speed

Improved getContentAuditsChronologyByItemIDandUnitID execution speed
Improved getContentAuditsSummaryByItemIDandUnitID execution speed
This commit is contained in:
Rich 2012-12-05 20:57:02 +00:00
parent 8d7072d3b7
commit 5302c8a95f

View File

@ -4622,6 +4622,17 @@ AS
begin begin
declare @dts datetime declare @dts datetime
set @dts = (select dts from items where itemid = @procitemid) set @dts = (select dts from items where itemid = @procitemid)
declare @tci table
(
ItemID int,
IContentID int,
IDeleteStatus int,
ProcDTS datetime,
Path nvarchar(max),
OrdinalPath nvarchar(max)
)
insert into @tci
select * from vefn_tblchilditems(@ProcItemID,@ItemID,0)
select select
case case
when lastauditid is null and dts > itemdts then 'Added' when lastauditid is null and dts > itemdts then 'Added'
@ -4659,7 +4670,7 @@ begin
,tci.ordinalpath ,tci.ordinalpath
from tblannotations aa from tblannotations aa
inner join items ii on aa.itemid = ii.itemid inner join items ii on aa.itemid = ii.itemid
join vefn_tblchilditems(@procitemid,@itemid,0) tci on tci.itemid = ii.itemid join @tci tci on tci.itemid = ii.itemid
where aa.deletestatus = 0 where aa.deletestatus = 0
union union
select select
@ -4681,7 +4692,7 @@ join vefn_tblchilditems(@procitemid,@itemid,0) tci on tci.itemid = ii.itemid
,tci.ordinalpath ,tci.ordinalpath
from annotationaudits aa from annotationaudits aa
inner join items ii on aa.itemid = ii.itemid inner join items ii on aa.itemid = ii.itemid
join vefn_tblchilditems(@procitemid,@itemid,0) tci on tci.itemid = ii.itemid join @tci tci on tci.itemid = ii.itemid
) ah ) ah
where itemid in (select itemid from vefn_tblchilditems (@procitemid,@itemid,0)) where itemid in (select itemid from vefn_tblchilditems (@procitemid,@itemid,0))
and dts > @dts and dts > @dts
@ -4726,35 +4737,36 @@ CREATE PROCEDURE [dbo].[getContentAuditsChronologyByItemIDandUnitID]
WITH EXECUTE AS OWNER WITH EXECUTE AS OWNER
AS AS
begin begin
select distinct [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName,ordinalpath select * from vefn_GetMyChronology(@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren)
from -- select distinct [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName,ordinalpath
( -- from
select -- (
case -- select
when lastauditid is null then 'Added' -- case
when r.deletestatus > 0 then 'Deleted' -- when lastauditid is null then 'Added'
when lastauditid = -1 then 'Changed' -- when r.deletestatus > 0 then 'Deleted'
when DeletedAuditID is not null then 'Restored' -- when lastauditid = -1 then 'Changed'
-- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored' -- when DeletedAuditID is not null then 'Restored'
else 'Changed' ---- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
end actionwhat -- else 'Changed'
,actiondts actionwhen -- end actionwhat
-- ,case --,actiondts actionwhen
-- when lastauditid is null then dts ---- ,case
-- when r.deletestatus > 0 then ActionDTS ---- when lastauditid is null then dts
-- when lastauditid = -1 then dts ---- when r.deletestatus > 0 then ActionDTS
-- when DeletedAuditID is not null then ActionDTS ---- when lastauditid = -1 then dts
-- else dts ---- when DeletedAuditID is not null then ActionDTS
-- end actionwhen ---- else dts
,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName ---- end actionwhen
,* --,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t -- ,*
inner join vefn_chronologyreport(@ProcedureItemID) r -- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
on t.icontentid = r.contentid -- inner join vefn_chronologyreport(@ProcedureItemID) r
-- where ActionDTS > procdts or dts > procdts -- on t.icontentid = r.contentid
) ah ---- where ActionDTS > procdts or dts > procdts
-- ) ah
where dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%' where dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%'
order by OrdinalPath, contentid,auditid--actionwhen -- order by OrdinalPath, contentid,auditid--actionwhen
RETURN RETURN
end end
GO GO
@ -4795,146 +4807,173 @@ WITH EXECUTE AS OWNER
AS AS
begin begin
select xyz.* from DECLARE @Chrono TABLE
( (
select z.* from [AuditID] bigint,
( [ContentID] int,
select contentid,min(auditid) auditid from [Number] nvarchar(max),
( [Text] nvarchar(max),
select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName [Type] int,
from [FormatID] int,
( [Config] nvarchar(max),
select [DTS] datetime,
case [UserID] nvarchar(max),
when lastauditid is null then 'Added' [DeleteStatus] int,
when r.deletestatus > 0 then 'Deleted' [ActionDTS] datetime,
when lastauditid = -1 then 'Changed' [ActionWhat] nvarchar(max),
when DeletedAuditID is not null then 'Restored' [ActionWhen] datetime,
-- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored' [Path] nvarchar(max),
else 'Changed' ItemID int,
end actionwhat TypeName nvarchar(max),
,actiondts actionwhen ordinalpath nvarchar(max)
-- ,case )
-- when lastauditid is null then dts insert into @Chrono
-- when r.deletestatus > 0 then ActionDTS select * from vefn_GetMyChronology(@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren)
-- when lastauditid = -1 then dts where dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%'
-- when DeletedAuditID is not null then ActionDTS select * from @Chrono
-- else dts where AuditID is null OR AuditID in (select min(auditID) from @Chrono group by contentid UNION select max(auditID) from @Chrono group by contentid)
-- end actionwhen order by OrdinalPath, contentid,auditid
,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
,* --select xyz.* from
from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t --(
inner join vefn_chronologyreport(@ProcedureItemID) r --select z.* from
on t.icontentid = r.contentid --(
-- where dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%' --select contentid,min(auditid) auditid from
-- where ActionDTS > procdts or dts > procdts --(
) ah -- select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName
) x -- from
group by contentid -- (
) y -- select
inner join -- case
( -- when lastauditid is null then 'Added'
select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName,appl,ordinalpath -- when r.deletestatus > 0 then 'Deleted'
from -- when lastauditid = -1 then 'Changed'
( -- when DeletedAuditID is not null then 'Restored'
select ---- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
case -- else 'Changed'
when lastauditid is null then 'Added' -- end actionwhat
when r.deletestatus > 0 then 'Deleted' --,actiondts actionwhen
when lastauditid = -1 then 'Changed' ---- ,case
when DeletedAuditID is not null then 'Restored' ---- when lastauditid is null then dts
-- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored' ---- when r.deletestatus > 0 then ActionDTS
else 'Changed' ---- when lastauditid = -1 then dts
end actionwhat ---- when DeletedAuditID is not null then ActionDTS
,actiondts actionwhen ---- else dts
-- ,case ---- end actionwhen
-- when lastauditid is null then dts --,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
-- when r.deletestatus > 0 then ActionDTS -- ,*
-- when lastauditid = -1 then dts -- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
-- when DeletedAuditID is not null then ActionDTS -- inner join vefn_chronologyreport(@ProcedureItemID) r
-- else dts -- on t.icontentid = r.contentid
-- end actionwhen ---- where dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%'
,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName ---- where ActionDTS > procdts or dts > procdts
,dbo.ve_GetItemApplicability(ItemID) appl -- ) ah
,* --) x
from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t --group by contentid
inner join vefn_chronologyreport(@ProcedureItemID) r --) y
on t.icontentid = r.contentid --inner join
-- where dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%' --(
-- where ActionDTS > procdts or dts > procdts -- select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName,appl,ordinalpath
) ah -- from
) z on y.contentid = z.contentid and y.auditid = z.auditid -- (
union -- select
select z.* from -- case
( -- when lastauditid is null then 'Added'
select contentid,max(auditid) auditid from -- when r.deletestatus > 0 then 'Deleted'
( -- when lastauditid = -1 then 'Changed'
select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName -- when DeletedAuditID is not null then 'Restored'
from ---- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
( -- else 'Changed'
select -- end actionwhat
case --,actiondts actionwhen
when lastauditid is null then 'Added' ---- ,case
when r.deletestatus > 0 then 'Deleted' ---- when lastauditid is null then dts
when lastauditid = -1 then 'Changed' ---- when r.deletestatus > 0 then ActionDTS
when DeletedAuditID is not null then 'Restored' ---- when lastauditid = -1 then dts
-- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored' ---- when DeletedAuditID is not null then ActionDTS
else 'Changed' ---- else dts
end actionwhat ---- end actionwhen
,actiondts actionwhen --,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
-- ,case --,dbo.ve_GetItemApplicability(ItemID) appl
-- when lastauditid is null then dts -- ,*
-- when r.deletestatus > 0 then ActionDTS -- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
-- when lastauditid = -1 then dts -- inner join vefn_chronologyreport(@ProcedureItemID) r
-- when DeletedAuditID is not null then ActionDTS -- on t.icontentid = r.contentid
-- else dts ---- where dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%'
-- end actionwhen ---- where ActionDTS > procdts or dts > procdts
,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName -- ) ah
,* --) z on y.contentid = z.contentid and y.auditid = z.auditid
from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t --union
inner join vefn_chronologyreport(@ProcedureItemID) r --select z.* from
on t.icontentid = r.contentid --(
-- where dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%' --select contentid,max(auditid) auditid from
-- where ActionDTS > procdts or dts > procdts --(
) ah -- select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName
) x -- from
group by contentid -- (
) y -- select
inner join -- case
( -- when lastauditid is null then 'Added'
select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName,appl,ordinalpath -- when r.deletestatus > 0 then 'Deleted'
from -- when lastauditid = -1 then 'Changed'
( -- when DeletedAuditID is not null then 'Restored'
select ---- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
case -- else 'Changed'
when lastauditid is null then 'Added' -- end actionwhat
when r.deletestatus > 0 then 'Deleted' --,actiondts actionwhen
when lastauditid = -1 then 'Changed' ---- ,case
when DeletedAuditID is not null then 'Restored' ---- when lastauditid is null then dts
-- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored' ---- when r.deletestatus > 0 then ActionDTS
else 'Changed' ---- when lastauditid = -1 then dts
end actionwhat ---- when DeletedAuditID is not null then ActionDTS
,actiondts actionwhen ---- else dts
-- ,case ---- end actionwhen
-- when lastauditid is null then dts --,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
-- when r.deletestatus > 0 then ActionDTS -- ,*
-- when lastauditid = -1 then dts -- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
-- when DeletedAuditID is not null then ActionDTS -- inner join vefn_chronologyreport(@ProcedureItemID) r
-- else dts -- on t.icontentid = r.contentid
-- end actionwhen ---- where dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%'
,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName ---- where ActionDTS > procdts or dts > procdts
,dbo.ve_GetItemApplicability(ItemID) appl -- ) ah
,* --) x
from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t --group by contentid
inner join vefn_chronologyreport(@ProcedureItemID) r --) y
on t.icontentid = r.contentid --inner join
-- where dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%' --(
-- where ActionDTS > procdts or dts > procdts -- select [AuditID],[ContentID],[Number],[Text],[Type],[FormatID],[Config],[DTS],[UserID],[DeleteStatus],[ActionDTS],[ActionWhat],[ActionWhen],[Path],ItemID,TypeName,appl,ordinalpath
) ah -- from
) z on y.contentid = z.contentid and y.auditid = z.auditid -- (
) xyz -- select
where appl = '-1' or ',' + appl + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%' -- case
order by OrdinalPath, contentid,auditid--actionwhen -- when lastauditid is null then 'Added'
-- when r.deletestatus > 0 then 'Deleted'
-- when lastauditid = -1 then 'Changed'
-- when DeletedAuditID is not null then 'Restored'
---- when DeletedAuditID is not null and lastauditid = deletedauditid then 'Restored'
-- else 'Changed'
-- end actionwhat
--,actiondts actionwhen
---- ,case
---- when lastauditid is null then dts
---- when r.deletestatus > 0 then ActionDTS
---- when lastauditid = -1 then dts
---- when DeletedAuditID is not null then ActionDTS
---- else dts
---- end actionwhen
--,(select dbo.vefn_GetStepTypeNameByItemIDandTypeID(t.itemid,r.type)) TypeName
--,dbo.ve_GetItemApplicability(ItemID) appl
-- ,*
-- from vefn_tblchilditems (@ProcedureItemID,@SelectedItemID,@IncludeDeletedChildren) t
-- inner join vefn_chronologyreport(@ProcedureItemID) r
-- on t.icontentid = r.contentid
---- where dbo.ve_GetItemApplicability(ItemID) = '-1' or ',' + dbo.ve_GetItemApplicability(ItemID) + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%'
---- where ActionDTS > procdts or dts > procdts
-- ) ah
--) z on y.contentid = z.contentid and y.auditid = z.auditid
--) xyz
-- where appl = '-1' or ',' + appl + ',' like '%,' + cast(@UnitID as varchar(10)) + ',%'
-- order by OrdinalPath, contentid,auditid--actionwhen
RETURN RETURN
end end
GO GO