Sign in or Join FriendFeed
FriendFeed is the easiest way to share online. Learn more »
Paul Buchheit
Does MySql have a query option to limit the amount of time spent on a query? (e.g., spend no more than 2 seconds on this query, and return an error if not complete by then) If not, it should.
Nope. Some scripts exist to avoid that, but they are "external" to the MySQL server. See http://faemalia.net/mysqlUt... - Claudio Cicali ♋
I normally just use limit to restrict the number of rows. Probably not what you were looking for but... - Seth Gottlieb
We have a cron that checks the DB's health and sets a flag on shared memory if the slave or master's are down, so that the web servers avoid making further requests - Jorge Escobar
Depending on the programming language you are executing the queries from, there may be strategies available. See this for PHP: http://snurl.com/6um2v [www_mysqlperformanceblog_com] - Seth Gottlieb
@Paul - do you mean wall clock time? If so set an alarm() in your client before making the query. (I bet you're already doing that.) Even more interesting would be to set a per query CPU limit inside the DB. Like setrlimit(RLIMIT_CPU) but on a per-query/per-transaction basis. - DeWitt Clinton
Wall clock time would be fine DeWitt, but I want the db to give up on the query since it's probably interfering with other queries. It's crazy that mysql doesn't have such a basic feature -- timeouts are very important for any real service. - Paul Buchheit
Interesting. Here's a discussion about adding RLIMIT_CPU_THREAD to setrlimit() in Linux: http://lkml.indiana.edu/hyperma.... Given that mysql handles each request in its own thread (iirc) this would give a per request cpu limit. And the wall clock limit is easy to achieve. - DeWitt Clinton
@Paul - not sure if your client API exposes it, but try a mysql_query('KILL QUERY;') to end the current thread when the SIGALRM is fired (http://dev.mysql.com/doc...). According to http://dev.mysql.com/doc... that's the modern way of doing mysql_kill(). - DeWitt Clinton
DeWitt: RLIMIT_CPU_THREAD is the wrong approach for a few reasons. First, it measures CPU time, which is irrelevant in queries that are I/O-bound; second, it means you can't reuse threads; third, it prevents any future use of things like user-mode threads. - Gabe
It is really too bad that PostgreSQL failed so miserably at the basics. It has this feature and many more that MySQL doesn't have. Unfortunately, they ported to Windows too late and didn't pay attention to out of the box clustering... - Sam Pullara