Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Performance switched with parameter
Message
From
20/09/2014 13:23:47
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
Indexing
Title:
Performance switched with parameter
Environment versions
SQL Server:
SQL Server 2012
Application:
Web
Miscellaneous
Thread ID:
01607903
Message ID:
01607903
Views:
72
If I have this:
DECLARE @NoClient Int

SET @NoClient=3831141

SELECT TOP 1 Invoice.AddUser,Invoice.NoFormat
 FROM Invoice (NOLOCK)
 WHERE Invoice.NoClient=@NoClient AND
  (Invoice.NoStatus=5 OR Invoice.NoStatus=6 OR Invoice.NoStatus=7 OR Invoice.NoStatus=10)
 ORDER BY Invoice.AddDate DESC
This provides an adequate execution plan with simply one item at 100% exactly to the index I have created.

But, if I have this:
DECLARE @NoClient Int
DECLARE @NoStatus Int
DECLARE @NoStatus2 Int
DECLARE @NoStatus3 Int
DECLARE @NoStatus4 Int

SET @NoClient=3831141
SET @NoStatus=5
SET @NoStatus2=6
SET @NoStatus3=7
SET @NoStatus4=10

SELECT TOP 1 Invoice.AddUser,Invoice.NoFormat
 FROM Invoice (NOLOCK)
 WHERE Invoice.NoClient=@NoClient AND
  (Invoice.NoStatus=@NoStatus OR Invoice.NoStatus=@NoStatus2 OR Invoice.NoStatus=@NoStatus3 OR Invoice.NoStatus=@NoStatus4)
 ORDER BY Invoice.AddDate DESC
The execution goes completely weird simply because I passed a parameter.

Anyone can explain why the execution plan is showing a very complex plan simply because I pass my values as parameters?
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Next
Reply
Map
View

Click here to load this message in the networking platform