Ignoring cache?

  • I now you can flush and clear the cache but is there an option to ignore it?

    Say rather than clearing the cache of a db/server you wanted to run a query but have it not look for any cache plans, is this possible?

    Cheers

  • EXECUTE <procedure name> WITH RECOMPILE will generate a new plan just for this execution, the generated plan won't be cached and the cached plan won't be affected.

    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
  • Other than what Gail outlines, which is a good way to get a new plan every time, why are you trying to "ignore the cache"?

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

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • GilaMonster (3/21/2014)


    EXECUTE <procedure name> WITH RECOMPILE will generate a new plan just for this execution, the generated plan won't be cached and the cached plan won't be affected.

    Thanks, and adding OPTION (RECOMPILE) to the end of a insert/update statement will fore that not to use a previously cached plan?

    was looking to run a quick test to see if there was a significant time decrease in a change to a few methods currently used and unable to clear the cache.

  • roblew 15918 (3/21/2014)


    GilaMonster (3/21/2014)


    EXECUTE <procedure name> WITH RECOMPILE will generate a new plan just for this execution, the generated plan won't be cached and the cached plan won't be affected.

    Thanks, and adding OPTION (RECOMPILE) to the end of a insert/update statement will fore that not to use a previously cached plan?

    was looking to run a quick test to see if there was a significant time decrease in a change to a few methods currently used and unable to clear the cache.

    Not only will it not use a previously cached plan, it won't cache plans at all for that statement.

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

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Grant Fritchey (3/21/2014)


    roblew 15918 (3/21/2014)


    GilaMonster (3/21/2014)


    EXECUTE <procedure name> WITH RECOMPILE will generate a new plan just for this execution, the generated plan won't be cached and the cached plan won't be affected.

    Thanks, and adding OPTION (RECOMPILE) to the end of a insert/update statement will fore that not to use a previously cached plan?

    was looking to run a quick test to see if there was a significant time decrease in a change to a few methods currently used and unable to clear the cache.

    Not only will it not use a previously cached plan, it won't cache plans at all for that statement.

    That's what i was hoping for thanks 🙂

  • Just bear in mind that OPTION(RECOMPILE) has other effects as well. It allows 'parameter sniffing' on variables, it can result in a row estimate for table variables which is not 1, it can result in an optimal plan for a catch-all query. It's not just ignoring the cached plan, there's a few more changes

    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

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply