February 27, 2014 at 1:42 am
Hi All,
Please provide your suggestion on this issue.
Original Query :
select distinct
d.researchDocumentId,
d.isDeleted,
d.isExist,
case when d.purchaseDate > dateadd(day, -1, getdate()) then 1 else null end as hasPurchased, --1 day of download availabilityd.hasPurchased,
d.researchContributorId,
d.isBindingContributor,
p.researchProductId,
p.researchContentViewTypeId,
p.researchProductSalesModelId ,
case when p.researchEmbargoDays > 0 then p2d.embargoPeriodDate else null end as embargoEnd,
case when lm.researchConsumptionLimitId is not null then 1 else 0 end as limitExceeded,
case when p.researchProductTypeId=3 then 0 else p2d.price end as price,
d.purchaseDate
from
docsCte d
left join ResearchProductToDocument_tbl (nolock) p2d
on p2d.researchDocumentId=d.researchDocumentId
inner join #products p
on p2d.researchProductId = p.researchProductId
or (p.researchProductTypeId=3 and p.researchContributorId=d.researchContributorId)
left join #limitsExceeded lm
on
lm.researchProductSalesModelId = p.researchProductSalesModelId
and lm.researchDocumentId = p2d.researchDocumentId
where
p.researchEmbargoDays is null or p.researchEmbargoDays=0
or
(p.researchEmbargoDays > 0 and p2d.embargoPeriodDate < getdate()) --Embargo date check, don't include docs that we shouldn't see
February 27, 2014 at 1:47 am
Please post the actual execution plan as a .sqlplan file attachment.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
February 27, 2014 at 2:04 am
pls find the original execution plan.
February 27, 2014 at 2:44 am
Table definitions and index definitions as well please
Could you post the plan for just that query run in isolation, not that and every single other statement in what looks like a long procedure?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply