Revised vefn_getChronology to speed up performance
This commit is contained in:
parent
e95c0aa52d
commit
676ec9fb30
@ -215,6 +215,12 @@ DeletedAuditID int
|
||||
WITH EXECUTE AS OWNER
|
||||
AS
|
||||
BEGIN
|
||||
--added rhm/jcb 20121218i
|
||||
declare @tmpTable table
|
||||
(
|
||||
icontentid int primary key
|
||||
)
|
||||
insert into @tmpTable select icontentid from vefn_tblchilditems(@ProcItemID,@ProcItemID,1)
|
||||
--added jcb 20111122
|
||||
declare @dts datetime
|
||||
set @dts = (select dts from items where itemid = @ProcItemID )
|
||||
@ -242,6 +248,7 @@ set @dts = (select dts from items where itemid = @ProcItemID )
|
||||
where Number is not null
|
||||
--added jcb 20111028_1827
|
||||
and ca.contentid != (select contentid from items where itemid = @procitemid)
|
||||
and ca.contentid in (select icontentid from @tmpTable)
|
||||
--end added jcb 20111028_1827
|
||||
--added jcb 20111122
|
||||
--and ca.ContentID in (SELECT [ContentID] FROM ContentAudits where dts > (select dts from items where itemid = @ProcItemID ))
|
||||
@ -303,11 +310,12 @@ and ca.dts > @dts
|
||||
-- inner join tblitems ti on ca.contentid = ti.contentid
|
||||
WHERE ca.DeleteStatus = 0 AND
|
||||
--added jcb 20111028_1827
|
||||
ca.contentid != (select contentid from items where itemid = @procitemid) and
|
||||
ca.contentid != (select contentid from items where itemid = @procitemid)
|
||||
and ca.contentid in (select icontentid from @tmpTable)
|
||||
--end added jcb 20111028_1827
|
||||
--added jcb 20111122
|
||||
--ca.dts > (select dts from items where itemid = @ProcItemID )
|
||||
(ca.dts > @dts or ca.actiondts > @dts)
|
||||
and (ca.dts > @dts or ca.actiondts > @dts)
|
||||
--end added jcb 20111122
|
||||
UNION
|
||||
SELECT distinct
|
||||
@ -330,13 +338,14 @@ ca.contentid != (select contentid from items where itemid = @procitemid) and
|
||||
,(select max(auditid) from contentaudits where ca.contentid = contentid and number is not null and deletestatus > 0 and ca.dts = dts) DeletedAuditID
|
||||
FROM ContentAudits ca
|
||||
-- inner join tblitems ti on ca.contentid = ti.contentid
|
||||
WHERE ca.DeleteStatus > 0 AND
|
||||
WHERE ca.DeleteStatus > 0
|
||||
--added jcb 20111028_1827
|
||||
--ca.contentid != (select contentid from items where itemid = @procitemid) and
|
||||
--end added jcb 20111028_1827
|
||||
--added jcb 20111122
|
||||
--ca.dts > (select dts from items where itemid = @ProcItemID )
|
||||
(ca.dts > @dts or ca.actiondts > @dts)
|
||||
and ca.contentid in (select icontentid from @tmpTable)
|
||||
and (ca.dts > @dts or ca.actiondts > @dts)
|
||||
--end added jcb 20111122
|
||||
order by ca.DTS,ActionDTS
|
||||
|
||||
@ -362,6 +371,7 @@ order by ca.DTS,ActionDTS
|
||||
inner join @Report rpt on ca.contentid = rpt.contentid and ca.auditid = rpt.lastauditid
|
||||
where ca.auditid not in (select auditid from @report)
|
||||
and rpt.lastauditid is not null
|
||||
and ca.contentid in (select icontentid from @tmpTable)
|
||||
return
|
||||
end
|
||||
GO
|
||||
|
@ -2699,6 +2699,12 @@ DeletedAuditID int
|
||||
WITH EXECUTE AS OWNER
|
||||
AS
|
||||
BEGIN
|
||||
--added rhm/jcb 20121218i
|
||||
declare @tmpTable table
|
||||
(
|
||||
icontentid int primary key
|
||||
)
|
||||
insert into @tmpTable select icontentid from vefn_tblchilditems(@ProcItemID,@ProcItemID,1)
|
||||
--added jcb 20111122
|
||||
declare @dts datetime
|
||||
set @dts = (select dts from items where itemid = @ProcItemID )
|
||||
@ -2726,6 +2732,7 @@ set @dts = (select dts from items where itemid = @ProcItemID )
|
||||
where Number is not null
|
||||
--added jcb 20111028_1827
|
||||
and ca.contentid != (select contentid from items where itemid = @procitemid)
|
||||
and ca.contentid in (select icontentid from @tmpTable)
|
||||
--end added jcb 20111028_1827
|
||||
--added jcb 20111122
|
||||
--and ca.ContentID in (SELECT [ContentID] FROM ContentAudits where dts > (select dts from items where itemid = @ProcItemID ))
|
||||
@ -2787,11 +2794,42 @@ and ca.dts > @dts
|
||||
-- inner join tblitems ti on ca.contentid = ti.contentid
|
||||
WHERE ca.DeleteStatus = 0 AND
|
||||
--added jcb 20111028_1827
|
||||
ca.contentid != (select contentid from items where itemid = @procitemid) and
|
||||
ca.contentid != (select contentid from items where itemid = @procitemid)
|
||||
and ca.contentid in (select icontentid from @tmpTable)
|
||||
--end added jcb 20111028_1827
|
||||
--added jcb 20111122
|
||||
--ca.dts > (select dts from items where itemid = @ProcItemID )
|
||||
(ca.dts > @dts or ca.actiondts > @dts)
|
||||
and (ca.dts > @dts or ca.actiondts > @dts)
|
||||
--end added jcb 20111122
|
||||
UNION
|
||||
SELECT distinct
|
||||
5 src,
|
||||
-- cast(ident_current('contentaudits') + 1 as bigint) auditid
|
||||
-- (select max(auditid) + 1 from contentaudits) [AuditID]
|
||||
ca.[AuditID]
|
||||
,ca.[ContentID]
|
||||
,[Number]
|
||||
,[Text]
|
||||
,[Type]
|
||||
,[FormatID]
|
||||
,[Config]
|
||||
,ca.[DTS] cadts
|
||||
,ca.[UserID]
|
||||
,ca.[DeleteStatus]
|
||||
,ActionDTS
|
||||
,(select min(dts) from itemaudits where contentid = ca.contentid) ItemDTS
|
||||
,(select max(auditid) from contentaudits where ca.contentid = contentid and number is not null) LastAuditID
|
||||
,(select max(auditid) from contentaudits where ca.contentid = contentid and number is not null and deletestatus > 0 and ca.dts = dts) DeletedAuditID
|
||||
FROM ContentAudits ca
|
||||
-- inner join tblitems ti on ca.contentid = ti.contentid
|
||||
WHERE ca.DeleteStatus > 0
|
||||
--added jcb 20111028_1827
|
||||
--ca.contentid != (select contentid from items where itemid = @procitemid) and
|
||||
--end added jcb 20111028_1827
|
||||
--added jcb 20111122
|
||||
--ca.dts > (select dts from items where itemid = @ProcItemID )
|
||||
and ca.contentid in (select icontentid from @tmpTable)
|
||||
and (ca.dts > @dts or ca.actiondts > @dts)
|
||||
--end added jcb 20111122
|
||||
order by ca.DTS,ActionDTS
|
||||
|
||||
@ -2817,6 +2855,7 @@ order by ca.DTS,ActionDTS
|
||||
inner join @Report rpt on ca.contentid = rpt.contentid and ca.auditid = rpt.lastauditid
|
||||
where ca.auditid not in (select auditid from @report)
|
||||
and rpt.lastauditid is not null
|
||||
and ca.contentid in (select icontentid from @tmpTable)
|
||||
return
|
||||
end
|
||||
GO
|
||||
|
@ -2508,8 +2508,20 @@ DeletedAuditID int
|
||||
WITH EXECUTE AS OWNER
|
||||
AS
|
||||
BEGIN
|
||||
--added rhm/jcb 20121218i
|
||||
declare @tmpTable table
|
||||
(
|
||||
icontentid int primary key
|
||||
)
|
||||
insert into @tmpTable select icontentid from vefn_tblchilditems(@ProcItemID,@ProcItemID,1)
|
||||
--added jcb 20111122
|
||||
declare @dts datetime
|
||||
set @dts = (select dts from items where itemid = @ProcItemID )
|
||||
--set @dts = (SELECT .[dbo].[vefn_GetPreviousRevisionDTSByItemID] (@ProcItemID))
|
||||
--end added jcb 20111122
|
||||
insert into @Report
|
||||
SELECT
|
||||
1 src,
|
||||
[AuditID]
|
||||
,ca.[ContentID]
|
||||
,[Number]
|
||||
@ -2517,7 +2529,7 @@ BEGIN
|
||||
,[Type]
|
||||
,[FormatID]
|
||||
,[Config]
|
||||
,ca.[DTS]
|
||||
,ca.[DTS] cadts
|
||||
,ca.[UserID]
|
||||
,ca.[DeleteStatus]
|
||||
,ActionDTS
|
||||
@ -2527,8 +2539,50 @@ BEGIN
|
||||
FROM ContentAudits ca
|
||||
-- inner join tblitems ti on ca.contentid = ti.contentid
|
||||
where Number is not null
|
||||
--added jcb 20111028_1827
|
||||
and ca.contentid != (select contentid from items where itemid = @procitemid)
|
||||
and ca.contentid in (select icontentid from @tmpTable)
|
||||
--end added jcb 20111028_1827
|
||||
--added jcb 20111122
|
||||
--and ca.ContentID in (SELECT [ContentID] FROM ContentAudits where dts > (select dts from items where itemid = @ProcItemID ))
|
||||
and ca.ContentID in (SELECT [ContentID] FROM ContentAudits where dts > @dts)
|
||||
--and ca.dts > (select dts from items where itemid = @ProcItemID )
|
||||
and ca.dts > @dts
|
||||
--end added jcb 20111122
|
||||
-- UNION
|
||||
-- SELECT
|
||||
--2 src,
|
||||
-- cast(ident_current('contentaudits') + 1 as bigint) auditid
|
||||
---- (select max(auditid) + 1 from contentaudits) [AuditID]
|
||||
---- 0 [AuditID]
|
||||
-- ,ca.[ContentID]
|
||||
-- ,[Number]
|
||||
-- ,[Text]
|
||||
-- ,[Type]
|
||||
-- ,[FormatID]
|
||||
-- ,[Config]
|
||||
-- ,ca.[DTS] cadts
|
||||
-- ,ca.[UserID]
|
||||
-- ,ca.[DeleteStatus]
|
||||
-- ,ActionDTS
|
||||
-- ,(select min(dts) from itemaudits where contentid = ca.contentid) ItemDTS
|
||||
--,(select max(auditid) from contentaudits where ca.contentid = contentid and number is not null) LastAuditID
|
||||
--,(select max(auditid) from contentaudits where ca.contentid = contentid and number is not null and deletestatus > 0 and ca.dts = dts) DeletedAuditID
|
||||
-- FROM tblContents ca
|
||||
---- inner join tblitems ti on ca.contentid = ti.contentid
|
||||
--WHERE ca.DeleteStatus = 0 AND
|
||||
----added jcb 20111028_1827
|
||||
--ca.contentid != (select contentid from items where itemid = @procitemid) and
|
||||
----end added jcb 20111028_1827
|
||||
----ca.ContentID in (SELECT [ContentID] FROM ContentAudits where dts > (select dts from items where itemid = @ProcItemID ))
|
||||
----added jcb 20111122
|
||||
----ca.ContentID in (SELECT [ContentID] FROM Contents where dts > (select dts from items where itemid = @ProcItemID ))
|
||||
--ca.ContentID in (SELECT [ContentID] FROM Contents where dts > @dts)
|
||||
----end added jcb 20111122
|
||||
----order by ca.DTS,ActionDTS
|
||||
UNION
|
||||
SELECT
|
||||
3 src,
|
||||
cast(ident_current('contentaudits') + 1 as bigint) auditid
|
||||
-- (select max(auditid) + 1 from contentaudits) [AuditID]
|
||||
-- 0 [AuditID]
|
||||
@ -2538,7 +2592,7 @@ BEGIN
|
||||
,[Type]
|
||||
,[FormatID]
|
||||
,[Config]
|
||||
,ca.[DTS]
|
||||
,ca.[DTS] cadts
|
||||
,ca.[UserID]
|
||||
,ca.[DeleteStatus]
|
||||
,ActionDTS
|
||||
@ -2548,9 +2602,69 @@ BEGIN
|
||||
FROM tblContents ca
|
||||
-- inner join tblitems ti on ca.contentid = ti.contentid
|
||||
WHERE ca.DeleteStatus = 0 AND
|
||||
(ca.ContentID in (SELECT [ContentID] FROM ContentAudits) or
|
||||
ca.dts > (select dts from items where itemid = @ProcItemID ))
|
||||
--added jcb 20111028_1827
|
||||
ca.contentid != (select contentid from items where itemid = @procitemid)
|
||||
and ca.contentid in (select icontentid from @tmpTable)
|
||||
--end added jcb 20111028_1827
|
||||
--added jcb 20111122
|
||||
--ca.dts > (select dts from items where itemid = @ProcItemID )
|
||||
and (ca.dts > @dts or ca.actiondts > @dts)
|
||||
--end added jcb 20111122
|
||||
UNION
|
||||
SELECT distinct
|
||||
5 src,
|
||||
-- cast(ident_current('contentaudits') + 1 as bigint) auditid
|
||||
-- (select max(auditid) + 1 from contentaudits) [AuditID]
|
||||
ca.[AuditID]
|
||||
,ca.[ContentID]
|
||||
,[Number]
|
||||
,[Text]
|
||||
,[Type]
|
||||
,[FormatID]
|
||||
,[Config]
|
||||
,ca.[DTS] cadts
|
||||
,ca.[UserID]
|
||||
,ca.[DeleteStatus]
|
||||
,ActionDTS
|
||||
,(select min(dts) from itemaudits where contentid = ca.contentid) ItemDTS
|
||||
,(select max(auditid) from contentaudits where ca.contentid = contentid and number is not null) LastAuditID
|
||||
,(select max(auditid) from contentaudits where ca.contentid = contentid and number is not null and deletestatus > 0 and ca.dts = dts) DeletedAuditID
|
||||
FROM ContentAudits ca
|
||||
-- inner join tblitems ti on ca.contentid = ti.contentid
|
||||
WHERE ca.DeleteStatus > 0
|
||||
--added jcb 20111028_1827
|
||||
--ca.contentid != (select contentid from items where itemid = @procitemid) and
|
||||
--end added jcb 20111028_1827
|
||||
--added jcb 20111122
|
||||
--ca.dts > (select dts from items where itemid = @ProcItemID )
|
||||
and ca.contentid in (select icontentid from @tmpTable)
|
||||
and (ca.dts > @dts or ca.actiondts > @dts)
|
||||
--end added jcb 20111122
|
||||
order by ca.DTS,ActionDTS
|
||||
|
||||
insert into @Report
|
||||
SELECT
|
||||
4 src,
|
||||
ca.[AuditID]
|
||||
,ca.[ContentID]
|
||||
,ca.[Number]
|
||||
,ca.[Text]
|
||||
,ca.[Type]
|
||||
,ca.[FormatID]
|
||||
,ca.[Config]
|
||||
,ca.[DTS] cadts
|
||||
,ca.[UserID]
|
||||
,ca.[DeleteStatus]
|
||||
,ca.ActionDTS
|
||||
,(select min(dts) from itemaudits where contentid = ca.contentid) ItemDTS
|
||||
,(select max(auditid) from contentaudits where ca.contentid = contentid and ca.auditid > auditid and number is not null) LastAuditID
|
||||
,(select max(auditid) from contentaudits where ca.contentid = contentid and ca.auditid > auditid and number is not null and deletestatus > 0 and ca.dts = dts) DeletedAuditID
|
||||
FROM ContentAudits ca
|
||||
-- inner join tblitems ti on ca.contentid = ti.contentid
|
||||
inner join @Report rpt on ca.contentid = rpt.contentid and ca.auditid = rpt.lastauditid
|
||||
where ca.auditid not in (select auditid from @report)
|
||||
and rpt.lastauditid is not null
|
||||
and ca.contentid in (select icontentid from @tmpTable)
|
||||
return
|
||||
end
|
||||
GO
|
||||
|
Loading…
x
Reference in New Issue
Block a user