I have a webapp that lets you run querys from a DB using a simple textarea in a form. I have one problem:
I need to check the query memory consumption before it runs (so it won’t crash my server).
Is there a way using PHP or MySQL to do that?
For example, i have 3 tables:
News (idNews,created,idMedio,state)
NewsAreaMain (idNewsAreaMain,idNews,idAreaMain)
AreaMain (idAreaMain)
and someone tried the following query that actually crashed the server:
SELECT DISTINCT News.*
FROM NewsAreaMain, News
WHERE
(
(
NewsAreaMain.idNews=News.idNews
AND News.idNews IN
(
SELECT DISTINCT News.idNews
FROM News, NewsAreaMain
WHERE NewsAreaMain.idNews=News.idNews
AND NewsAreaMain.idAreaMain="1"
)
)
AND idMedio="5"
OR ( idMedio="6" )
)
AND News.state=1
ORDER BY created DESC
LIMIT 0, 20;
Not that I know of. If there were one, I’m sure all the shared hosting sites out there would use it and block queries that are too intensive rather than using such a dirty method as killing queries that run too long.
That would probably be your only option. Have a process that periodically checked the first entry in
SHOW PROCESSLIST, and if “Time” is above a certain value (it’s in seconds, so 10 would probably be an ok, if tight, value. Anything above 60 is asking for trouble), kill it withKILL QUERY #####(using the relevant ID number returned as part ofSHOW PROCESSLIST).