TempDB usage per active session

  • Comments posted to this topic are about the item TempDB usage per active session

    -- Gianluca Sartori

  • Very interesting, though I'd find a version that looks for not only internal objects, but also explicit objects like #temp and ##global temp tables, and even "real" tables in tempdb, etc. etc., which in my environment are (regrettably, in the case of the "real" tables) common.

  • Thanks for helping me identify a query where by using OPTION(RECOMPILE) I was able to reduce execution time of "completely unpredictable" to a few seconds. 🙂

    ML

    ---
    Matija Lah, SQL Server MVP
    http://milambda.blogspot.com

  • My pleasure, Matija!

    Was the query using a lot of tempdb space? I'm curious to know how OPTION RECOMPILE made it stop doing so. Maybe a wrong cached plan?

    -- Gianluca Sartori

  • The query is used for a rather complex computation needed in the result of a highly used stored procedure.

    Occasionally, the execution plan would include a Hash Join operator in a particular JOIN clause that worked well for some workloads, but ended up creating multi-million-row work tables for other workloads, where a paralel plan using the Merge Join, and Nested Loops, operators would have been more appropriate.

    Because of the complexity of the query (which someone else, other than myself should also be able to maintain ;-)), I didn't want to complicate things further, either by using explicit join hints (i.e. in specific JOIN clauses), or by specifying query-level join hints (e.g. OPTION(MERGE JOIN, LOOP JOIN), which would have prevented the use of the Hash Join operator altogether.

    OPTION(RECOMPILE) does cause some overhead (which isn't completely insignificant), but it keeps the behavior of this particular query predictable. Considering the full scale of what the procedure is used for, this is a highly significant benefit.

    ML

    ---
    Matija Lah, SQL Server MVP
    http://milambda.blogspot.com

  • Thanks so much for this query. Is there a similar one for retrieving tempdb log space used per SPID?

    I'd like to track such a query for an issue where an as-yet unknown query is causing periodic large increases in the percent of log space used.

    Thanks for any help!

    - webrunner

    -------------------
    A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
    Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html

  • Nice and useful script! Thanks!

    ----------------------------------------------------------------------------------------------------------------------------------------------------
    Roshan Joe

    Jeff Moden -Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • Thanks for the script.

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

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