Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "runaway query"?

In the context of SQL, what does a runaway query mean?

Does it mean any query that runs wild when it takes too long? Or does it mean when it has some side-effects due to triggers?

like image 333
dance2die Avatar asked Feb 25 '09 21:02

dance2die


People also ask

What causes long running queries?

Queries or updates that take longer than expected to execute can be caused by a variety of reasons. Slow-running queries can be caused by performance problems related to your network or the computer where SQL Server is running. Slow-running queries can also be caused by problems with your physical database design.

What are long running queries?

This query returns all queries in your Workspace with at least one run over the last 90 days, sorted by the average runtime per query run. You can use this query to identify queries in your Workspace consuming the most resources.


3 Answers

A runaway query is a query whose execution time is taking longer than the execution time estimated by the optimizer. Runaway queries can lead to using up all of your processor cycles or other resources during its execution.

like image 191
TheTXI Avatar answered Oct 12 '22 11:10

TheTXI


It's a query that starts running and never comes back (for some value of "never").

Usually it means that the query isn't using an index it's supposed to, or using a bad join method, or a bad join order, or doing a bunch of string conversion/comparison.

It is possible to write SQL queries that take weeks/years to perform.

like image 35
Amy B Avatar answered Oct 12 '22 11:10

Amy B


I apply this term specifically to a query that triggers, usually accidentally, behavior with runtime of unexpected complexity. If you expect a query to take O(n * m) (that is, a single join between two tables) and it takes O(n * n * m) then I would call it runaway, even if n * n * m is acceptably small in the instant case. More commonly this is experienced as a query expected to take O(log(n) * log(m)) taking O(n * n * m * m), which turns out to be unacceptably complex.

like image 2
Sparr Avatar answered Oct 12 '22 10:10

Sparr