Home Forums SQL Server 2008 SQL Server Newbies Join performance gets much worse after combining two selects that are each fairly fast RE: Join performance gets much worse after combining two selects that are each fairly fast

  • The .sqlplan files for the queries that I put in the first message are attached.

    MainDocumentAndAddendaActualPlan.sqlplan is from the first query

    MainDocumentAndDiagnosesActualPlan.sqlplan is from the second query

    MainDocumentAddendaAndDiagnosesEstimatedPlan.sqlplan is from the third query

    MainDocumentAndAddendaIntoTempTableActualPlan.sqlplan is from saving the first query results in a temp table

    MainDocumentAndDiagnosesIntoTempTableActualPlan.sqlplan is from saving the second query results in a temp table

    MainDocumentAddendaAndDiagnosesFromTempTablesActualPlan.sqlplan is like the third query, but it uses the temp tables. That query looks like this:

    SELECT doc_ad.TIUDocumentSID, doc_ad.ScrSSN, doc_ad.TIUDocumentSID, doc_dx.ICDCode

    FROM #DocAndAdID AS doc_ad

    LEFT JOIN #DocAndDxID AS doc_dx

    ON doc_ad.TIUDocumentSID = doc_dx.TIUDocumentSID

    ORDER BY doc_ad.TIUDocumentSID, doc_ad.TIUAddendumSID