Click here to Skip to main content
14,972,640 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have got SQL query for its performance tuning as it gets executed in 2+ hours. It has lots of Joins, Left Joins, Group By and CTE

Any suggestion over it please

What I have tried:

I tried to figure out of its due to lots of joins
Posted
Updated 18-Jun-21 2:53am
Comments
Maciej Los 16-Jun-21 14:47pm
   
There's tons of reason...
mohit Gupta 2021 16-Jun-21 14:50pm
   
If you can suggest some in context of my query
Patrice T 16-Jun-21 15:03pm
   
No, because you didn't gave any context

Quote:
Why SQL server query running too slow around 2+ hours?

All in your title, because : "It has lots of joins, left joins and ctes."
You start to understand why SQL database design and optimization is a whole job.
We have no way to turn you in an expert over night.

A good database design is a match between tables structures, tables indexes and queries. The way one is designed impacts the 2 others.
Unfortunately, there is no magic trick to solve your problem, only a deep study of your database can pinpoint where is the mismatch.

Since you didn't have any detail, it is impossible to help you any further than general indications.
   
Comments
Maciej Los 16-Jun-21 14:58pm
   
I was lazy to explain that. 5ed!
Patrice T 16-Jun-21 15:01pm
   
Thank you.
I know, wheater getting hot theses days in Europe.
Maciej Los 16-Jun-21 15:12pm
   
Oh, yeah. Few minutes after 9PM and there's over 20°C.
Patrice T 16-Jun-21 15:34pm
   
about 24°C here in France. :)
Maciej Los 16-Jun-21 15:36pm
   
Wow!
_-_-_-me 18-Jun-21 9:27am
   
29 degree C at 9 Pm for us.
Richard MacCutchan 16-Jun-21 16:23pm
   
Same here even after a short rain storm.
The best place to start is to look at the execution plan in MS Server management studio to find out what parts of the
query are the most costly and try and see if you can improve them.
   
Add appropriate indexes. Usually on the columns that are used in JOINs or in the WHERE conditions
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900