Quantcast
Channel: Forum SQL Server Database Engine
Viewing all articles
Browse latest Browse all 15889

Different Execute Plan for same query

$
0
0

We are using the Following 2 queries:

1.) DECLARE @Search VARCHAR(500) = 'Harry Potter'

SELECT ProductID, ProductName

FROM Product 
WHERE ProductName   LIKE  '%'+@Search+'%'

2.) 

SELECT ProductID, ProductName

FROM Product 
WHERE ProductName   LIKE '%Harry Potter%'

We have clustered index created on the ProductID column since it is a primary key and a Non Clustered Index on the Product Name. It takes >10 Seconds to execute 1st query while it only takes <1 Second to execute the 1st.

The execute plan shows Index Seek on the Non Clustered index for the 1st query but a Index Scan on the Non Clustered Index for the 2nd one. 

Please help me understand this different behavior of the same query.

Thanks in advance.


Pavan Sharma K


Viewing all articles
Browse latest Browse all 15889

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>