Slow Query Hash Match

Hi, We are runnig one query which takes one jour to finish. How can i make it faster? I have attached the execution plan below. Any idea?

Plan.pesession (300.5 kB)
avatar image By tharmen 1 asked Dec 04, 2016 at 04:20 AM
more ▼
(comments are locked)
avatar image Matak Dec 11, 2016 at 10:34 PM

Your stats seem way out. Do you do any maintenance around them ? nolock hints are generally not a good idea. Any reason why you are using them (they dont make queries go faster). For a small improvement you can tweak your indexes to remove the key lookups.

avatar image Aaron Bertrand ♦ Jan 08 at 05:09 PM

Multiple DISTINCTs are definitely a warning sign for me, as is the hash match which results from a self-join. What are the actual requirements for this query? I also agree with Matak about the key lookups (it should be easy to add the missing columns to those indexes to eliminate those) and stats (SQL Server seems to have absolutely no clue how many rows might be in the Trend table).

10|10000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 50 attachments (including images) can be used with a maximum of 209.7 MB each and 209.7 MB total.

Follow this question



asked: Dec 04, 2016 at 04:20 AM

Seen: 358 times

Last Updated: Jan 08 at 05:09 PM