I have 2 huge tables 1 with 580 Million recs and other with 1200 Million recs which i need to join on 3 columns. The 2nd table has multiple recs for the same join columns (with other columns being different).
The 2 tables have a non clustered index on the 3 join columns. I also have a filter to get 1 year at a time as the table has 5 years data.
Select det.Year,
det.Claim_Nbr,
det.Last_DOS,
det.mbr_id AS Mbr_ID,
diag.diag,
diag.status
INTO #Temp_Table_1
FROM A det WITH (NOLOCK)
INNER LOOP JOIN B diag WITH (NOLOCK)
ON det.Claim_Nbr = diag.claim_nbr
AND det.mbr_id = diag.mbr_id
AND det.Last_DOS = diag.last_dos
WHERE det.YEAR = '2023' AND diag.last_dos >= '2023-01-01 00:00:00.000' AND diag.last_dos <= '2023-12-31 00:00:00.000'
Currently this keeps timing out after running for few hours. Is there any way to optimize this better without adding any more indexes? (as I do not own the tables)
The original query also has few other small temp tables that are being left joined to the above query to get some more columns. I tried to dissect the query into temp tables so that it executes faster.
Srkuno is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1