How to rewrite query to take small time when executed ?

ahmed salah 3,216 Reputation points
2020-08-27T14:12:25.687+00:00

I work on SQL server 2012 it take too much time to enhance it

so how to enhance it to take small time

how to write query this best enhance to take less time ?

it take too much time near to half hour to return 50000 rows

execution plan
https://www.brentozar.com/pastetheplan/?id=H1XwcNHXv

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,624 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Stratos Matzouranis 36 Reputation points
    2020-08-27T15:22:06.963+00:00

    [Nop_PartsFamilyAttribute].[_dta_in… index fragmentation?

    0 comments No comments

  2. Erland Sommarskog 110.3K Reputation points
    2020-08-27T21:50:45.077+00:00

    First of all, remove all those NOLOCK in the query. I assume that you want your queries to return the correct result? If you put in NOLOCK on every table you are basically say "I don't care if the result is correct or not".

    Next the execution plan you provided only has estimated values. This makes it more difficult to assess where time is being spent. However, I notice that the plan estimates that the query will return two rows, and you say that it returns 50000. This indicates that there is a problem with the estimates somewhere. Maybe your statistics are out of date?

    0 comments No comments

  3. MelissaMa-MSFT 24,196 Reputation points
    2020-08-28T06:25:37.29+00:00

    Hi @ahmed salah ,

    According to the exection plan you provided, no enhancement is needed since it is already index seek and seek predicate under it.

    21048-ep.png

    It is better for you to provide the execution plan of your complete query which returns 50000 rows so that we could proceed to check any enhancement needed.

    In addition, there are some suggetions with your query provided.

    1. Manually update statistics.
    2. Use trace flag 2371(DBCC TRACEON(2371,-1))
    3. Find any possible to change from too many joins to exists.
    4. Consider to use some tune tools like Database Engine Tuning Advisor (DTA).

    If the response is helpful, please click "Accept Answer" and upvote it.

    Best regards
    Melissa

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.