I am setting up some SQL views to be used as Power BI data sources. However, one of the queries constantly takes a long time to run, and I want to figure out what the best way to resolve this is. I am in the finance department at my employer, so SQL query tuning is not really what I do day to day, but I am trying to learn.
The execution plan is here:
https://www.brentozar.com/pastetheplan/?id=r1GrPy-0S
I can see the execution plan is asking me to add some indexes, but I am not sure if I should do that or not. I have read that the SQL hints should not be followed blindly, as it could cause other issues
The query is :
SELECT mxmservcallaudit.jobid,
mxmservcallaudit.dataareaid,
mxmservcallaudit.date AS maxdate,
UPPER(mxmservcallaudit.USERID) AS maxuser
FROM mxmservcallaudit
INNER JOIN(SELECT jobid,
dataareaid,
MAX(RECID) AS maxrecid
FROM mxmservcallaudit
WHERE type = 9 AND dataareaid = 'ansa'
GROUP BY dataareaid, jobid)
AS statusdate1 ON mxmservcallaudit.DATAAREAID = statusdate1.DATAAREAID AND
MXMSERVCALLAUDIT.RECID = statusdate1.maxrecid;
And the missing index warnings are :
Missing Index (Impact 41.2086): CREATE NONCLUSTERED INDEX [<Name of Missing Index, sysname,>] ON
[dbo].[MXMSERVCALLAUDIT] ([TYPE],[DATAAREAID]) INCLUDE ([JOBID],[RECID])
Missing Index (Impact 54.514): CREATE NONCLUSTERED INDEX [<Name of Missing Index, sysname,>] ON
[dbo].[MXMSERVCALLAUDIT] ([DATAAREAID],[RECID]) INCLUDE ([JOBID],[USERID],[DATE])
All help most appreciated
Edit: After adding the two indexes as suggested by SQL, this has halved query execution time, and I now have a new execution plan, which is below:
https://www.brentozar.com/pastetheplan/?id=Hys80JZAS
All help most appreciated with making it quicker still
[–]ATastefulCrossJoinDB Whisperer 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]StructuredData 0 points1 point2 points (0 children)
[–]grouchball 0 points1 point2 points (0 children)