Hi Team,
Select query on table with millions of records is taking very long time. It took 50mins, the below query is joining on multiple table from two databases DB1.dbo.Table1 contains 100 million records and also Table3 and Table4 (of different database) might contain close to 1million records.
Select T1.* From DB1.dbo.Table1 T1 Join DB1.dbo.Table2 T2 on RTRIM(T1.Col3) = RTRIM(T2.Col3) Join Table4 CA on RTRIM(T1.Col1) + T2.Col2 = CA.Col1 Join Table3 U on CA.Col2 = U.Col2 AND RTRIM(T2.Col2) = U.Col3 Where U.Col4 NOT IN ('A1', 'A2', 'A3', 'A4', 'A5', 'A6','A7','A8','A9') And (T1.flg IS NULL OR T1.flg = 'N') And LTRIM(RTRIM(T2.Col2)) NOT IN ('B1','B2')
How can i improve the performance of this query. Actual thing is update the data in Db1.dbo.table1 based on the conditions but if the select is taking close to 1hr then update will take hours together. Indexes already implemented on all the tables.
Thanks,
Eshwar.
Please don't forget to Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful. It will helpful to other users.