Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Linked Server slow performance
    primarykey
    data
    text
    <p>I'm still quite new to database performance and understanding all of the intricacies that management studio does for us behind the scenes so any help or reference to learning material is appreciated.</p> <p>My issue is I'm writing a query to grab data from a linked server and join it to my local db table to insert particular info. I'm using 2 cte's and joining 2 tables in the cte for the linked server data. I then use sub queries to add columns to my result set so I can filter on a row by row situation. I did it this way because I'm not that good at using PIVOT. </p> <pre><code> with ap AS ( SELECT DISTINCT col1 ,col2 ,col3 ,col4 from [linkedServer].[db].[dbo].[table] st JOIN [linkedServer].[db].[dbo].[table2] vs ON vs.col1 = st.col1 AND vs.col2 = st.col2 WHERE vs.col3 = '' and ... ,pre as ( SELECT * ,COALESCE( (SELECT 1 from ap where sss.col1 = ap.col1 and ap.col3 = '') ,(SELECT 2 from ap where sss.col1 = ap.col1 and ap.col3 = '') ,(SELECT 3 from ap where sss.col1 = ap.col1 and ap.col3 = '') ,(SELECT 4 from ap where sss.col1 = ap.col1 and ap.col3 = '') ) Monday ,COALESCE( (SELECT 1 from ap where sss.col1 = ap.col1 and ap.col3 = '') ,(SELECT 2 from ap where sss.col1 = ap.col1 and ap.col3 = '') ,(SELECT 3 from ap where sss.col1 = ap.col1 and ap.col3 = '') ,(SELECT 4 from ap where sss.col1 = ap.col1 and ap.col3 = '') ) Tuesday ,COALESCE( (SELECT 1 from ap where sss.col1 = ap.col1 and ap.col3 = '') ,(SELECT 2 from ap where sss.col1 = ap.col1 and ap.col3 = '') ,(SELECT 3 from ap where sss.col1 = ap.col1 and ap.col3 = '') ,(SELECT 4 from ap where sss.col1 = ap.col1 and ap.col3 = '') ) Wednesday ,COALESCE( (SELECT 1 from ap where sss.col1 = ap.col1 and ap.col3 = '') ,(SELECT 2 from ap where sss.col1 = ap.col1 and ap.col3 = '') ,(SELECT 3 from ap where sss.col1 = ap.col1 and ap.col3 = '') ,(SELECT 4 from ap where sss.col1 = ap.col1 and ap.col3 = '') ) Thursday FROM local_Table sss ) UPDATE tar SET tar.monday = pre.Monday ,tar.Tuesday = pre.Tuesday ,tar.Wednesday = pre.Wednesday ,tar.Thursday = pre.Thursday FROM local_table tar JOIN pre on tar.column = pre.column </code></pre> <p>This takes about 5 minutes to run. </p> <p>From what I've learned so far my options are to use temp tables or create a view on the linked server so I'm not doing any joins in my query. </p> <p>Any help in optimizing this is greatly appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload