Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Optimizing a query
Message
 
 
To
08/09/2008 22:46:56
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 6.5 and older
Miscellaneous
Thread ID:
01345942
Message ID:
01345996
Views:
11
You can try
SELECT Client.Numero FROM Client
  WHERE Client.NoEntity=@NoEntity AND Client.Fic_Date<@Fic_Date 
 	AND Client.Loss_Code=@Loss_Code AND Client.CType=@CType
 	AND EXISTS ( SELECT 1 FROM Invoice WHERE Client.Numero=Invoice.NoClient AND Invoice.Amount=@Amount)
>I have this query which is causing a lot of deadlock error messages from SQL Server. When I look at it, every where clause fields and inner join related fields are indexed. But, we have this deadlock situation appearing about 4 times a day. Tonight, I took a look at what could cause this. I have found something interesting by changing the SQL command a little bit. From the SSMS interface, it takes about 2 seconds to return 45 records. This is when all my where clauses values are parameterized. But, one of those where clauses is from a INNER JOIN table. At that specific location, if I remove the parameterized value and put the value as is, the result is instant.
>
>Here is an example:
>
>
>SELECT Client.Numero FROM Client
> INNER JOIN Invoice ON Client.Numero=Invoice.NoClient
> WHERE Client.NoEntity=@NoEntity AND Client.Fic_Date<@Fic_Date AND Invoice.Amount=@Amount 
  AND Client.Loss_Code=@Loss_Code AND Client.CType=@CType
>
>
>This would take 2 seconds to return 45 records. But, the following would be instant:
>
>
>SELECT Client.Numero FROM Client
> INNER JOIN Invoice ON Client.Numero=Invoice.NoClient
> WHERE Client.NoEntity=@NoEntity AND Client.Fic_Date<@Fic_Date AND Invoice.Amount=1000 
 AND Client.Loss_Code=@Loss_Code AND Client.CType=@CType
>
>
>I tried to change a lot of things in there. The only way I can have my query to be optimized is by avoiding the parameter on the foreign table. But, I really need to have everything parameterized. What can I do?
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform