我在SQL Server中运行以下查询。简而言之,我有3个有点相同的查询“联合”。当我启动查询时,它会在“结果”窗格中运行并生成增量结果。但是,一旦达到264,619条记录(前5分钟),它就会停止生成结果,但查询正在运行并且已运行30分钟。任何想法为什么会这样?我理解下面的查询有点长/半复杂,所以我道歉,我不能让它变得更简单(我希望有人能够指出我的方向,我将能够进行查询下面有点简单)。查询下方是结果窗格的屏幕截图。我想知道查询是在某处死锁还是遇到无限循环/等等:
select
Q1.[Transaction Identifier],
row_number() over (order by (select 1)) as 'Transaction Sequence Number',
Q1.HL_Acct_ID,
Q1.AcctNumber,
Q1.AcctType,
Q1.AcctSource,
Q1.DUNS_NBR,
Q1.DBPLCR_CONTACT_ID,
Q1.CellCode,
Q1.OfferCode,
Q1.ResponseType,
Q1.ResponseDate,
Q1.ResponseQuantity,
Q1.ResponseValue,
Q1.ResponseChannel,
Q1.[Cookie ID],
Q1.[IP Address],
Q1.[Device ID],
Q1.[CUSTOM_TEXT_01],
Q1.[CUSTOM_TEXT_02],
Q1.[CUSTOM_TEXT_03],
Q1.[CUSTOM_TEXT_04],
Q1.[CUSTOM_TEXT_05]
from
(
select
'ACCT PROMORESP' as 'Transaction Identifier',
s.HL_ACCT_ID as 'HL_Acct_ID',
null as [AcctNumber],
null as [AcctType],
null as [AcctSource],
null as [DUNS_NBR],
null as [DBPLCR_CONTACT_ID],
s.CELLCODE as [CellCode],
case
when c.URL is not null then c.URL
else '-1'
end as [OfferCode],
case
when c.EventDate is not null then 'Click'
when c.EventDate is null then
case
when sub.status = 'unsubscribed' then 'Unsubscribe'
when sub.status = 'bounced' then 'Bounce'
when sub.status = 'held' then 'Bounce'
end
end as [ResponseType],
convert(varchar, c.EventDate, 112) as [ResponseDate],
null as [ResponseQuantity],
null as [ResponseValue],
'Email' as [ResponseChannel],
null as [Cookie ID],
null as [IP address],
null as [Device ID],
null as [CUSTOM_TEXT_01],
null as [CUSTOM_TEXT_02],
null as [CUSTOM_TEXT_03],
null as [CUSTOM_TEXT_04],
null as [CUSTOM_TEXT_05]
from C1111111.[151222_Hostess Ensemble] s with (nolock)
inner join C1111111._subscribers sub with (nolock) on sub.SubscriberKey = s.Email
left join C1111111._click c with (nolock) on c.JobID in
(
select j.fkJobId from tblJobs_Lists j with (nolock)
inner join customobject c with (nolock) on j.customobjectid = c.customobjectid
where c.memberid = 1111111
and c.customobjectname like '151222_Hostess Ensemble'
)
and c.SubscriberKey = s.Email
where c.EventDate is not null or (c.EventDate is null and (sub.status in ('unsubscribed','bounced','held'))) and c.isunique = 1
union all
select
'ACCT PROMORESP' as 'Transaction Identifier',
s.HL_ACCT_ID as 'HL_Acct_ID',
null as [AcctNumber],
null as [AcctType],
null as [AcctSource],
null as [DUNS_NBR],
null as [DBPLCR_CONTACT_ID],
s.CELLCODE as [CellCode],
'-1' as [OfferCode],
case
when o.EventDate is not null then 'Message Open'
when o.EventDate is null then
case
when sub.status = 'unsubscribed' then 'Unsubscribe'
when sub.status = 'bounced' then 'Bounce'
when sub.status = 'held' then 'Bounce'
end
end as [ResponseType],
convert(varchar, o.EventDate, 112) as [ResponseDate],
null as [ResponseQuantity],
null as [ResponseValue],
'Email' as [ResponseChannel],
null as [Cookie ID],
null as [IP address],
null as [Device ID],
null as [CUSTOM_TEXT_01],
null as [CUSTOM_TEXT_02],
null as [CUSTOM_TEXT_03],
null as [CUSTOM_TEXT_04],
null as [CUSTOM_TEXT_05]
from C1111111.[151222_Hostess Ensemble] s with (nolock)
inner join C1111111._subscribers sub with (nolock) on sub.SubscriberKey = s.Email
left join C1111111._open o with (nolock) on o.JobID in
(
select j.fkJobId from tblJobs_Lists j with (nolock)
inner join customobject c with (nolock) on j.customobjectid = c.customobjectid
where c.memberid = 1111111
and c.customobjectname like '151222_Hostess Ensemble'
)
and o.SubscriberKey = s.Email
where o.EventDate is not null or (o.EventDate is null and (sub.status in ('unsubscribed','bounced','held'))) and o.isunique = 1
UNION ALL
select
'ACCT PROMORESP' as 'Transaction Identifier',
s.HL_ACCT_ID as 'HL_Acct_ID',
null as [AcctNumber],
null as [AcctType],
null as [AcctSource],
null as [DUNS_NBR],
null as [DBPLCR_CONTACT_ID],
s.CELLCODE as [CellCode],
'-1' as [OfferCode],
null as [ResponseType],
convert(varchar, o.EventDate, 112) as [ResponseDate],
null as [ResponseQuantity],
null as [ResponseValue],
'Email' as [ResponseChannel],
null as [Cookie ID],
null as [IP address],
null as [Device ID],
null as [CUSTOM_TEXT_01],
null as [CUSTOM_TEXT_02],
null as [CUSTOM_TEXT_03],
null as [CUSTOM_TEXT_04],
null as [CUSTOM_TEXT_05]
from C1111111.[151222_Hostess Ensemble] s with (nolock)
inner join C1111111._subscribers sub with (nolock) on sub.SubscriberKey = s.Email
left join C1111111._open o with (nolock) on o.JobID in
(
select j.fkJobId from tblJobs_Lists j with (nolock)
inner join customobject c with (nolock) on j.customobjectid = c.customobjectid
where c.memberid = 1111111
and c.customobjectname like '151222_Hostess Ensemble'
)
left join C1111111._click cl with (nolock) on o.JobID in
(
select j.fkJobId from tblJobs_Lists j with (nolock)
inner join customobject c with (nolock) on j.customobjectid = c.customobjectid
where c.memberid = 1111111
and c.customobjectname like '151222_Hostess Ensemble'
)
and cl.SubscriberKey = s.Email
where cl.EventDate is null and o.EventDate is null and sub.status not in ('unsubscribed','bounced','held')) as Q1
答案 0 :(得分:1)
如果没有表格定义,我无法验证这是否正确,但这将是我对上述内容的简化,假设在连接条件中有两个修正:
set transaction isolation level read uncommitted;
WITH JobIDs AS
(
select j.fkJobId from tblJobs_Lists j
inner join customobject c on j.customobjectid = c.customobjectid
where c.memberid = 1111111
and c.customobjectname = '151222_Hostess Ensemble'
)
select
'ACCT PROMORESP' as 'Transaction Identifier',
row_number() over (order by (select 1)) as 'Transaction Sequence Number',
s.HL_ACCT_ID as 'HL_Acct_ID',
null as [AcctNumber],
null as [AcctType],
null as [AcctSource],
null as [DUNS_NBR],
null as [DBPLCR_CONTACT_ID],
s.CELLCODE as [CellCode],
X.OfferCode,
X.ResponseType,
convert(varchar, X.EventDate, 112) as [ResponseDate],
null as [ResponseQuantity],
null as [ResponseValue],
'Email' as [ResponseChannel],
null as [Cookie ID],
null as [IP address],
null as [Device ID],
null as [CUSTOM_TEXT_01],
null as [CUSTOM_TEXT_02],
null as [CUSTOM_TEXT_03],
null as [CUSTOM_TEXT_04],
null as [CUSTOM_TEXT_05]
from
(
SELECT
s.HL_ACCT_ID,
s.CELLCODE,
s.Email,
case sub.status
when 'unsubscribed' then 'Unsubscribe'
when 'bounced' then 'Bounce'
when 'held' then 'Bounce'
end as [ResponseType],
sub.status
from C1111111.[151222_Hostess Ensemble] s
inner join C1111111._subscribers sub on sub.SubscriberKey = s.Email
) as s
left join C1111111._open o on o.JobID in (select fkJobId from JobIDs)
-- DON'T YOU NEED A "and o.SubscriberKey = s.Email" HERE?
and o.SubscriberKey = s.Email
left join C1111111._click cl on cl.JobID in (select fkJobId from JobIDs)
-- LOOK ABOVE, was "o.JobID", **REALLY**
and cl.SubscriberKey = s.Email
cross apply (
select
'-1' as [OfferCode],
case
when o.EventDate is not null then 'Message Open'
else s.[ResponseType]
end as [ResponseType],
o.EventDate
where o.EventDate is not null or (o.EventDate is null and (s.status in ('unsubscribed','bounced','held'))) and o.isunique = 1
UNION ALL
select
isnull(cl.URL,'-1') as [OfferCode],
case
when c.EventDate is not null then 'Click'
else s.[ResponseType]
end as [ResponseType],
cl.EventDate
where cl.EventDate is not null or (cl.EventDate is null and (s.status in ('unsubscribed','bounced','held'))) and cl.isunique = 1
union all
select
'-1' as [OfferCode],
NULL AS [ResponseType],
null as EventDate
where cl.EventDate is null and o.EventDate is null and s.status not in ('unsubscribed','bounced','held')
) AS X