SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


chache queries


chache queries

Author
Message
Zohaib Anwar
Zohaib Anwar
SSC Veteran
SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)

Group: General Forum Members
Points: 232 Visits: 192
Hi ,

Do you happen to know of a way to invalidate cached query plans?
I would rather target a specific query instead of invalidating all of them.

Also do you know of any sql server setting that will cause cached query plans to invalidate even though only one character in the queries has changed?

exec sp_executesql N'select
cast(5 as int) as DisplaySequence,
mt.Description + '' '' + ct.Description as Source,
c.FirstName + '' '' + c.LastName as Name,
cus.CustomerNumber Code,
c.companyname as "Company Name",
a.Address1,
a.Address2,
a.City,
sp.Abbreviation,
a.PostalCode,
cphone.PhoneNumber as Phone,
cfax.PhoneNumber as Fax,
ccell.PhoneNumber as Cell,
cemail.EmailAddress as Email,
wa.WebAddress as Web,
cl.Id as Id,
c.Id as ContactId
from
contactlink cl
left join ContactTypes ct on ct.id = cl.ContactTypeID
left join Contacts c on c.ID = cl.ContactID
left join Customers cus on cus.id = cl.CustomerID
left join MasterTypes mt on mt.id = ct.MasterTypeID
left join contactaddresslink cal on cal.ContactID = c.id
left join Addresses a on a.id = cal.AddressID
left join StatesProvinces sp on sp.id = a.StateProvinceID
left join ContactPhoneLink cpl_phone on cpl_phone.ContactID = c.id and cpl_phone.PhoneTypeID = 1
left join phones cphone on cphone.id=cpl_phone.PhoneID
left join ContactPhoneLink cpl_fax on cpl_fax.ContactID = c.id and cpl_fax.PhoneTypeID = 2
left join phones cFax on cFax.id=cpl_fax.PhoneID
left join ContactPhoneLink cpl_cell on cpl_cell.ContactID = c.id and cpl_cell.PhoneTypeID = 3
left join phones cCell on cCell.id=cpl_cell.PhoneID
left join ContactEmailLink cel on cel.ContactID = c.id
left join Emails cEmail on cEmail.id = cel.EmailID
left join ContactWebLink cwl on cwl.ContactID = c.id
left join WebAddresses wa on wa.id = cwl.WebAddressID
where cus.id = @customerId
',N'@CustomerId int',@CustomerId=1065


In this query we have seen (on some databases) simply changing ‘@CustomerId int',@CustomerId=1065’ too ‘@customerId int',@customerId=1065’ fixed the a speed problem….just changed the case on the Customer bind parameter. On other servers this has no effect. I’m thinking the server is using an old cached query plan, but don’t know for sure.
Zohaib Anwar
Zohaib Anwar
SSC Veteran
SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)SSC Veteran (232 reputation)

Group: General Forum Members
Points: 232 Visits: 192
The query seems to have gone bad again on my machine with or without a capital ‘C’
I found a way to target and delete specific query plans, but it still is running slow from within .net.
I am trying to find out why it is slow sometimes and fast at other times, any help would be greatly appreciated.


Here is what I found

Find cached plans
SELECT plan_handle, st.text
FROM sys.dm_exec_cached_plans
CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS st
WHERE text LIKE N'%wa.id = cwl.WebAddressID%'



Remove specific plan
DBCC FREEPROCCACHE (0x06001E00AC6A672F90961F6C0400000001000000000000000000000000000000000000000000000000000000
GilaMonster
GilaMonster
SSC Guru
SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)SSC Guru (226K reputation)

Group: General Forum Members
Points: 226907 Visits: 46335
Please don't start multiple threads for a problem people are already helping you with.

No replies to this thread please, direct replies to http://www.sqlservercentral.com/Forums/Topic1566066-2799-1.aspx

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (99K reputation)SSC Guru (99K reputation)SSC Guru (99K reputation)SSC Guru (99K reputation)SSC Guru (99K reputation)SSC Guru (99K reputation)SSC Guru (99K reputation)SSC Guru (99K reputation)

Group: General Forum Members
Points: 99107 Visits: 33014
This is the third thread for the same problem.

Have you done any of the things I've suggested on the other two?

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search