web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

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

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Community Member Profile Picture
    on at

    Bump - any help is appreciated.

  • Community Member Profile Picture
    on at
  • Community Member Profile Picture
    on at

    None of these are helpful but thank you for offering.

  • Community Member Profile Picture
    on at

    Bumping this again in case someone has any info.

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans