1

I have this query that a vendor wants to start running on my data warehouse. The version I'm posting runs at 18 seconds if I run via a linked server (SQL Server 2017, 12GB RAM, more CPU) as a remote query, and 4 minutes if I run it directly on the server (4GB RAM, SQL Server 2008).

Yes, I know my servers suck. We are getting a better set.

Question: Why would it be faster to run this:

 select * from [eih-dr01].livefdb.[dbo].[RegAcct_Main]

than going directly onto the server eih-dr01 and running this:

 select * from RegAcct_main

Here's the big, bad query, for reference:

 declare @start datetime 
 set @start = dateadd(minute, -45, getdate())
 SELECT 
 'AST' AS [HDR]
 ,RAM.Facility_MisFacID AS [FID]
 ,MRN.PrefixMedicalRecordNumber AS [MRN]
 ,RAM.AccountNumber AS [VISIT_NBR]
 ,MDSM.[Name] AS [CATEGORY]
 ,PADM.MisDocumentationSectionOid AS [CATEGORY_ID]
 ,MQM.Text
 ,MDSQ.QuestionMnemonic
 --,COALESCE(MQM.Text,MDSQ.QuestionMnemonic) AS [QUESTION]
 ,PADQ.QueryValue
 --,REPLACE(REPLACE(REPLACE(REPLACE(PADQ.QueryValue,'|}',''),'{',''),'}',''),'|',',') AS [FINDING]
 ,PADM.DateTimePerformed
 --,CONVERT(VARCHAR,PADM.DateTimePerformed,101) + ' ' + LEFT(CONVERT(VARCHAR,PADM.DateTimePerformed,108),5) AS [REPORT_DT]
 --,PADM.DateTimePerformed
 --,1 AS Ord
 FROM [eih-dr01].livefdb.[dbo].[PcsAcctAct_IntActAssessments] PAAIAA
 INNER JOIN [eih-dr01].livefdb.[dbo].[RegAcct_Main] RAM
 ON PAAIAA.SourceID = RAM.SourceID
 AND PAAIAA.VisitID = RAM.VisitID
 LEFT JOIN [eih-dr01].livefdb.[dbo].[MisFac_Main] MFM
 ON RAM.SourceID = MFM.SourceID
 AND RAM.Facility_MisFacID = MFM.MisFacID
 LEFT JOIN [eih-dr01].livefdb.[dbo].[MisHimDept_Main] MHDM
 ON MHDM.SourceID = MFM.SourceID
 AND MHDM.MisHimDeptID = MFM.HimDepartment_MisHimDeptID
 LEFT JOIN [eih-dr01].livefdb.[dbo].[HimRec_MedicalRecordNumbers] MRN
 ON RAM.SourceID = MRN.SourceID
 AND RAM.PatientID = MRN.PatientID
 AND MHDM.MedicalRecordNumberPrefix = MRN.MrnPrefixID
 INNER JOIN [eih-dr01].livefdb.[dbo].[PcsAssmntData_Main] PADM
 ON PAAIAA.SourceID = PADM.SourceID
 AND PAAIAA.VisitID + '{A^' + PAAIAA.InterventionActivityAssessment_MisDocSectID + '}' = PADM.PcsAssmntDataID
 AND PAAIAA.InterventionActivityUrnID = PADM.IdentifierID
 INNER JOIN [eih-dr01].livefdb.[dbo].[PcsAssmntData_Queries] PADQ
 ON PADM.SourceID = PADQ.SourceID
 AND PADM.PcsAssmntDataID = PADQ.PcsAssmntDataID
 AND PADM.IdentifierID = PADQ.IdentifierID
 LEFT JOIN [eih-dr01].livefdb.[dbo].[MisDocSect_Main] MDSM
 ON PADM.SourceID = MDSM.SourceID
 AND PADM.MisDocumentationSectionOid = MDSM.MisDocSectID
 LEFT JOIN [eih-dr01].livefdb.[dbo].[MisDocSect_Questions] MDSQ
 ON PADQ.SourceID = MDSQ.SourceID
 AND PADQ.QuerySetID = MDSQ.QuestionSetUrnID
 AND PADQ.QueryNumberID = MDSQ.QuestionUrnID
 AND PADM.MisDocumentationSectionOid = MDSQ.MisDocSectID
 LEFT JOIN [eih-dr01].livefdb.[dbo].[MisQry_Main] MQM
 ON MDSQ.SourceID = MQM.SourceID
 AND MDSQ.QuestionMnemonic = MQM.MisQryID
 where 
 --RAM.AdmitDateTime 
 PADM.DateTimePerformed >= @start
 --and MDSM.[Name] = 'Vital Signs'
 and PADM.MisDocumentationSectionOid like '%VS%'
Hannah Vernon
71k22 gold badges178 silver badges323 bronze badges
asked Apr 26, 2018 at 19:51
3
  • 5
    Perhaps some of the things in this question apply to your situation? Check out the execution plans and add them to the question (pastetheplan.com) Commented Apr 26, 2018 at 19:55
  • 2
    Distributed Query Deep Dive - Conor Cunningham has a lot of good information in it about how and where remote queries are processed. It's possible that the majority of the hard work is done on the better-equipped server. It may also be a Cardinality Estimation and plan choice issue. Without the query plans, it's impossible to say. Like asking why you eat pizza faster left handed. Commented Apr 26, 2018 at 20:34
  • Check out dba.stackexchange.com/questions/77875/… It could be spending the extra time rendering the results on the resource limited server. Commented Apr 29, 2018 at 23:47

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.