Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Seeing a lot of top 5 "email0".Subject as "subject", "email0".Description as "description" FROM Email as "email0" WITH (NOLOCK)

Posted on by Microsoft Employee

My 8.2 on-prem deployment has 25 orgs but only 14 orgs use email router.  I monitor sql performance with sp_whoisactive and one of the queries that I see a lot is:

<?query --

select
top 5 "email0".Subject as "subject"
, "email0".Description as "description"
, "email0".PriorityCode as "prioritycode"
, "email0".ActivityId as "activityid"
, "email0".ModifiedOn as "modifiedon"
, "email0".StateCode as "statecode"
, "email0".StatusCode as "statuscode"
, "email0".DeliveryAttempts as "deliveryattempts"
, "email0".AttachmentCount as "attachmentcount"
, convert(bigint, "email0".VersionNumber) as "versionnumber"
, N'' as "safedescription"
from
Email as "email0" WITH (NOLOCK) join ActivityParty as "activityparty1" WITH (NOLOCK) on ("email0".ActivityId = "activityparty1".ActivityId and (((("activityparty1".ParticipationTypeMask = @ParticipationTypeMask0 and ("activityparty1".PartyId in (@PartyId0
, @PartyId1
, @PartyId2
, @PartyId3
, @PartyId4)))))))
where
(("email0".StateCode = @StateCode0 and ("email0".StatusCode != @StatusCode0 or "email0".StatusCode is null) and "email0".DirectionCode = @DirectionCode0 and (((((("email0".DeliveryAttempts = @DeliveryAttempts0)))))))) order by
"email0".ActualEnd asc
--?>

My first question is, is this coming from email router?  Or is it specifically a workflow that sends out an email?  Regardless of which, why and where is the query choosing to select the top 5?  When looking at the execution plan, there is no suggested missing index that needs to be created but I'd be willing to if needed.  Most of the cost in the execution plan goes to a non-clustered index seek and clustered key lookup to the ActivityPointerBase table.  Any insight is appreciated.

*This post is locked for comments

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Seeing a lot of top 5 "email0".Subject as "subject", "email0".Description as "description" FROM Email as "email0" WITH (NOLOCK)

    Sorry, don't really have an answer from you, but I think logically this is the email router calling the Application Layer to pull the next email batch that is due for delivery. The reason that it is pulling in 5's is due to the fact that the communication between email router and mail server only processes a small batch of emails at a time. If there are no emails returned it will wait till the next times in queries the db. If there are it will pull the next batch after these are processed.

    The sort order is by the ActualEnd date in Ascending order, which is how the logic is processed.

    I can't confirm this, but I've seen similar code using email router previously.

    Hope this helps.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Seeing a lot of top 5 "email0".Subject as "subject", "email0".Description as "description" FROM Email as "email0" WITH (NOLOCK)

    Bumping this again in case someone has any info.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Seeing a lot of top 5 "email0".Subject as "subject", "email0".Description as "description" FROM Email as "email0" WITH (NOLOCK)

    None of these are helpful but thank you for offering.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Seeing a lot of top 5 "email0".Subject as "subject", "email0".Description as "description" FROM Email as "email0" WITH (NOLOCK)

    Have a look here:

    https://social.msdn.microsoft.com/Forums/ie/en-US/3d51dda8-ec2c-4b26-9380-59ec9744fbec/crm-email-router-sql-query?forum=crm

    https://social.msdn.microsoft.com/Forums/windows/en-US/a7aa8b70-24fa-4f96-aff6-d132c0272a90/sql-timeout-causing-email-router-to-halt?forum=crmdevelopment

    https://community.dynamics.com/crm/f/117/t/144027

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Seeing a lot of top 5 "email0".Subject as "subject", "email0".Description as "description" FROM Email as "email0" WITH (NOLOCK)

    Bump - any help is appreciated.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans