Estimation of Query Execution Time

  • After issuing a query or running a stored procedure in SQL Server 2005, is there a way to know when a query/stored procedure will complete.

    e.g. In file manager, when a file is copied it will mention approximately, how long it will take to complete. In oracle, looking at longops, it can be determined how much time(approximation) the query will take to complete.

  • I think no but iam interested if someone can come up with something.

    "Keep Trying"

  • I don't think what you are asking is feasable.

    The only thing I remember is a percent_complete and estimated_completion_time in sys.dm_exec_requests, but only for these commands:

    ALTER INDEX REORGANIZE

    AUTO_SHRINK option with ALTER DATABASE

    BACKUP DATABASE

    CREATE INDEX

    DBCC CHECKDB

    DBCC CHECKFILEGROUP

    DBCC CHECKTABLE

    DBCC INDEXDEFRAG

    DBCC SHRINKDATABASE

    DBCC SHRINKFILE

    KILL (Transact-SQL)

    RESTORE DATABASE,

    UPDATE STATISTICS.

    I don't think it can be predicted for arbitrary statements.

    -- Gianluca Sartori

  • Uhhh.. wait: maybe you can query sys.dm_exec_query_stats and get statistics for statement you already have executed, something like:

    select b.text, *

    from sys.dm_exec_query_stats as a

    cross apply sys.dm_exec_sql_text(sql_handle) as b

    For stored procedures you could query sys.dm_exec_procedure_stats.

    Hope this helps

    Gianluca

    -- Gianluca Sartori

  • We can get the data related to queries already executed. I think the OP wants to know the time before executing the query.

    Only way you can predict the time required is making a knowledgeable guess based on previous experience with similar queries. You can the estimated execution plan to get an idea .

    "Keep Trying"

  • Maybe I'm wrong, but I took a look at the data returned by the view in my system and it looks like it holds statistics for sql handles of queries and procedure already executed.

    If you execute the same procedure or query you could look in the dm views and guess the new execution times.

    -- Gianluca Sartori

  • Hi

    You are right. We can find out times of queries already executed. I assumed the OP wanted to the execution time of a new query which has not been executed even once.

    "Keep Trying"

  • You can make something of an educated guess if, over time, you establish a relationship between 'query cost' as reported in the execution plan, and the actual time it took to execute. For example, I have an 8 proc server with 32GB RAM, 2.2Ghz cpu, on top of a small SAN configured to provide a max disk IO of 18000 Ops/sec. I have established that a query cost of 13000 units equates to roughly 5 minutes if there are no other competing operations. Note that this relationship will not be the same on any server and DB that is not exactly the same in every way.

    The bottom line is that if you can establish an approximate relationship you will, under a fairly strict set of conditions, be able to predict the approximate execution time and by extension, the approximate time to complete at any point during execution. However, if you had to bet your life or job on when it would complete...don't.

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

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