SQLTeam.com | Weblogs | Forums

Query Cache Safe


#1

I was listening to a Plural Sight course from Kimberly Tripp. She stated that most Ad-hoc query statements are not 'safe', meaning not cached for re-use. And she also stated that an ad-hoc query with more than one Table in the From clause is not safe. And also that if there is an exact textual match, the query plan will get re-used.

I had never heard of the term 'safe' (with regards to query plan reuse) and couldn't find anything on this when I googled it. Is this a standard term?

I tried this in SQL 2014. I ran some ad-hoc queries, some with one table in the from clause and some with more than one table in the from clause. The number of tables made no difference. If the exact same statement (i.e. exact same text) was re-ran, the query plan was reused, otherwise it wasn't reused. So I'm wondering if I've misunderstood something or what.


#2

Maybe this will add some extra information. https://www.sqlpassion.at/archive/2015/04/27/the-pain-of-simple-parameterization-in-sql-server/

Always it's good to re-listen the course.


#3

You're telling me to re-listen the course?