Home Forums SQL Server 2014 Development - SQL Server 2014 SQL uses 2 different executions plan (slow and fast) for a simple query. Need a new index ? RE: SQL uses 2 different executions plan (slow and fast) for a simple query. Need a new index ?

  • Some questions and ideas about this, it's difficult to be precise since we're just looking at a picture of the execution plan:
    -  in the pictures you can see a variable @p2, but that's not in your query posted above, is that used as a parameter in the query?  I could see different results because of more reads as hinted at in your pictures if this is a parameter.
    -  in the query posted above, you have a SELECT *, this means that SQL Server will always need to do a LOOKUP operation for any NONCLUSTERED index you put on the table.  LOOKUPs are often expensive and depending on the number of rows the optimizer expects it may just decide to do a table scan.  The query in the picture looks different, so I can't really tell what columns are involved in that query.
    -  of the columns that are equal conditions (PARTITION, DATAAREAID, DATASOURCE, FILEREFRECID), how selective are each column?  (meaning how well does a single value filter the query)