Bug #14182 | Large query with subselects gets stuck in state 'statistics', can lock server | ||
---|---|---|---|
Submitted: | 20 Oct 2005 14:16 | Modified: | 21 Oct 2005 10:37 |
Reporter: | [ name withheld ] | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server | Severity: | S1 (Critical) |
Version: | 4.1.13, 4.1.14, mysql.com RPMs | OS: | Linux (RHEL4, RH 9.0) |
Assigned to: | CPU Architecture: | Any |
[20 Oct 2005 14:16]
[ name withheld ]
[20 Oct 2005 14:18]
[ name withheld ]
The large query associated with this bug report.
Attachment: statsquery.txt (text/plain), 18.78 KiB.
[20 Oct 2005 15:37]
Valeriy Kravchuk
Thank you for a problem report. You'll be able to upload private files using the File tab (up to 200 K in size), but for now, please, just inform about the number of rows in tables involved. Or you may just send the results of EXPLAIN for that huge query from your machine.
[20 Oct 2005 15:42]
[ name withheld ]
Here are the row counts for each table. mysql> select count(*) from content; +----------+ | count(*) | +----------+ | 100636 | +----------+ 1 row in set (0.00 sec) mysql> select count(*) from stories; +----------+ | count(*) | +----------+ | 10248 | +----------+ 1 row in set (0.00 sec) mysql> select count(*) from content_relationships; +----------+ | count(*) | +----------+ | 271004 | +----------+ 1 row in set (0.00 sec) I'll try to do the explain but it may take some time as I need to create a suitable development instance to run it on as I'm worried about running it on the production database servers where the bug is occuring.
[20 Oct 2005 15:50]
[ name withheld ]
I've fired off an EXPLAIN on that query in one of our dev mysql instances (4.1.13 on RH9.0) and it's in a state of 'statistics' as well. I'll leave it running for a while, but I expect it may never return. I'll provide another update after it's run for a few hours or finished whichever comes first. Thanks, Tabor
[20 Oct 2005 16:09]
[ name withheld ]
Sorry for the comment flurry. I've had to kill the EXPLAIN on that query because it was impacting the performance of that dev instance which is used for other development work. I'll re-run it later when the system is idle. One thing I did note is that while it was in this state, mysql used up all available CPU on the system for the 15 minutes it ran before being killed. When I have more data to report on the EXPLAIN, I'll update the ticket again. Thanks, Tabor
[20 Oct 2005 17:42]
MySQL Verification Team
Hi ! I have analysed your incomplete query (found in statement.txt) and it looks very much a kind of problem that will be fixed by a new optimizer that will be cost based and is scheduled for MySQL 5.2. You could also try 5.0 and try to set those optimizer variables (described in our manual) and see if you get any better timing, but I doubt it.
[20 Oct 2005 18:54]
[ name withheld ]
Sinisa, Thanks for the update. Just so that I understand more fully what's happening here is the following an accurate description of the issue?: We have a ridiculously large query that isn't actually stuck but that is attempting to be optimized by the query optimizer (I'm assuming that's what the state of 'statistics' means -- gathering statistics about optimization?). Presumably if left alone for some indeterminate amount of time it will end up determining what the best execution method is and execute it. That amount of time could be hours or even days. At least that's how I read the text in http://dev.mysql.com/doc/refman/5.0/en/controlling-optimizer.html So really our best choice is to optimize how our CMS creates that query to generate something much less taxing on the system. But barring that 5.2 should have a fix which would allow this to be optimized more efficiently? I'm guessing the ETA on a stable 5.2 is probably a year or more off? That's unfortunate because I just upgraded from 4.0.24 to 4.1.13/14 to support this CMS. Upgrading again is undesirable but if the variables like optimizer_search_depth (I'm assuming that's what you're talking about) help we may do that. One question though, why would the optimizer cause all queries against the tables to block if two of these very large queries are run at the same time? Why would any have to block at all if they're all read-only queries? That strikes me as ungraceful behavior on the part of the server. Thanks for the help Tabor
[21 Oct 2005 10:37]
Sergei Golubchik
A couple of more comments. First - our optimizer is cost based (at least since 3.22, but probably earlier). Second - the problem is - you have too many tables in a join and MySQL is trying to chose a best join order by doing an exhaustive search over all possible combination (8!= 40320). Usually it doesn't have to do it, because indexes, statistics, etc allows to stop this process early, but it does not happen in yout case. Workaround - use STRAIGHT_JOIN instead of INNER JOIN when you join content_relationships to itself. Solution - upgrade to 5.0, it uses a different search logic (see the manual for "greedy search") that does not have to try all the combinations and is much faster when many tables are joined.