[MDEV-9222] unacceptable slow SQL query Created: 2015-12-01 Updated: 2019-03-15 Resolved: 2019-03-15 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.1.9 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Moshe L | Assignee: | Unassigned |
| Resolution: | Incomplete | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Linux debian, Windows 2008 R2 |
||
| Description |
|
SELECT 144 as f_id, M_ID, m_video,m_audio,m_album, m_topic, M_Linear, M_NUM, M_TITLE, M_Content, M_User, M_DATE FROM forum_messages WHERE m_visible=1 and m_forum =144 and m_id>8292603 and m_topic=759799 order by m_id asc running fastly on 10.0.22 1/10000 I see an unacceaptable slow (about 2-5 minutes or more). the slowest state is `sending data`. table:
explain:
Optimizer switch:
what I need to upload to help solving this issue? I can see it on three servers with the same data. |
| Comments |
| Comment by Elena Stepanova [ 2015-12-02 ] | |||||||||||||||||||||||||||||||||||||
|
Is this query plan from when the query is slow, or from when the query is fast? Could you please provide the other explain and specify which is which?
| |||||||||||||||||||||||||||||||||||||
| Comment by Moshe L [ 2015-12-02 ] | |||||||||||||||||||||||||||||||||||||
|
Hi Elena! 1. the query itself is slow from time to time. (1-5minutes for sometims). show index:
the workaround (for now) is to add new index for (m_topic, m_id), but I think the old one need to work for this situation. | |||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2015-12-02 ] | |||||||||||||||||||||||||||||||||||||
|
Moshe L, Yes, I understand it's the same query. However, to have such a big difference, either the query has to use a different execution plan, or tables must be locked. We can rule out the 2nd option because you would see lock waits in the processlist,
Optionally, you can also configure long_query_time (in seconds) to define how long a query must be to be considered a slow one. Since your slow query takes really long, you can set it lets say to 60 seconds. Please also attach your cnf file(s) as requested before. | |||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2015-12-02 ] | |||||||||||||||||||||||||||||||||||||
I hope you mean slow_query_log. Also make sure you've set log_slow_verbosity as above, otherwise there will be no query plan in the log! | |||||||||||||||||||||||||||||||||||||
| Comment by Moshe L [ 2015-12-03 ] | |||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2016-01-07 ] | |||||||||||||||||||||||||||||||||||||
|
So, as I understand, this is the difference in query plans:
Have you ever used engine-independent statistics before? It would be interesting to see if it helps (or, on the contrary, if it makes the slow plan to become persistent). If you want to try, you need to do the following:
After that, try to run EXPLAIN for your query and the query itself. If it returns a good plan, and the query is fast, wait to see if you are still getting those delays. The idea of using statistics is that the query should be always executed the same way, until the data changes and you run ANALYZE again. It can cause a good or bad plan, that's another story (and if it produces a bad plan, it needs to be fixed); but it should be deterministic, unlike the current default behavior of InnoDB, where it uses random data samples. Please let us know about the result, or if you cannot do this experiment. | |||||||||||||||||||||||||||||||||||||
| Comment by Moshe L [ 2016-01-08 ] | |||||||||||||||||||||||||||||||||||||
|
I tried to enable stat_tables from your comments and do analyze table. it seems works right now. I will wait some days to see if the problem repeats. I also checked the tables mysql.table_stats, mysql.column_stats and mysql.index_stats, and these tables are empty. the innodb_* version of them is updated to ANALYZE TABLE time, but for other tables I can see a dates from the past (2-5 months ago). Thanks | |||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2016-01-08 ] | |||||||||||||||||||||||||||||||||||||
|
No, it's not normal.
And after that you should have data related to your table in all of mysql.index_stats, mysql.table_stats and mysql.column_stats. Although ironically, it might be that the empty statistical tables by pure luck help you to trigger the good execution plan; but it's of course not a solution, as it's not reliable. | |||||||||||||||||||||||||||||||||||||
| Comment by Moshe L [ 2016-01-08 ] | |||||||||||||||||||||||||||||||||||||
|
Hi ! I am getting "Error 2013: Lost connection to MySQL server during query SQL Statement" when I am trying to use analyze table recived crash:
| |||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2016-01-08 ] | |||||||||||||||||||||||||||||||||||||
|
Are there any errors in the log before the crash? Could you please run | |||||||||||||||||||||||||||||||||||||
| Comment by Moshe L [ 2016-01-08 ] | |||||||||||||||||||||||||||||||||||||
|
mysql.index_stats check status OK fixed (repair table). now trying again. | |||||||||||||||||||||||||||||||||||||
| Comment by Moshe L [ 2016-01-08 ] | |||||||||||||||||||||||||||||||||||||
|
I am trying yo analyze small table and not the large (~5G) one. crashed again analyze table forum_rec; // small table.}} | |||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2016-01-08 ] | |||||||||||||||||||||||||||||||||||||
|
Would you be able to provide the data dump from this small table? | |||||||||||||||||||||||||||||||||||||
| Comment by Moshe L [ 2016-01-08 ] | |||||||||||||||||||||||||||||||||||||
|
mysql.index_stats repair status OK still crashing (upgraded to 10.1.10). | |||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2016-01-08 ] | |||||||||||||||||||||||||||||||||||||
|
So, would you be able to provide the datadump of the table? | |||||||||||||||||||||||||||||||||||||
| Comment by Moshe L [ 2016-01-08 ] | |||||||||||||||||||||||||||||||||||||
|
the crashed table from the example ? Dump20160108.sql | |||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2016-01-08 ] | |||||||||||||||||||||||||||||||||||||
|
Indeed, I am not getting the crash on your data, so maybe something is wrong with the statistical tables themselves – something that CHECK/REPAIR does not recognize. It's not unheard of. | |||||||||||||||||||||||||||||||||||||
| Comment by Moshe L [ 2016-01-09 ] | |||||||||||||||||||||||||||||||||||||
|
uploaded. | |||||||||||||||||||||||||||||||||||||
| Comment by Moshe L [ 2016-01-09 ] | |||||||||||||||||||||||||||||||||||||
|
do you need something more from me? uploaded myi/myd files and also the table. | |||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2016-01-12 ] | |||||||||||||||||||||||||||||||||||||
|
I've only found 5 files – 3 files that belong to table_stats, and 2 files that belong to index_stats (frm and MYI). There is no index_stats.MYD, and no column_stats.* files. Did you upload them? Maybe something went wrong. With the provided table_stats files only, I am still not getting the crash. There is still hope that one of the two other tables causes it... If you still have the other 4 files (those with which your instance crashes), please upload them as well. Did you try to truncate or re-create the tables? Did it help? | |||||||||||||||||||||||||||||||||||||
| Comment by Moshe L [ 2016-01-12 ] | |||||||||||||||||||||||||||||||||||||
|
I suspect that these files is not the problem. I tried on a new server dump > restore and the second server is crashing also. | |||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2016-01-13 ] | |||||||||||||||||||||||||||||||||||||
|
Sorry, I don't quite understand. | |||||||||||||||||||||||||||||||||||||
| Comment by Moshe L [ 2016-01-13 ] | |||||||||||||||||||||||||||||||||||||
|
yes | |||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2016-01-13 ] | |||||||||||||||||||||||||||||||||||||
|
Can you try a really simple new table, like
Something is obviously different about your servers, we need to find out what it can be. | |||||||||||||||||||||||||||||||||||||
| Comment by Moshe L [ 2016-01-13 ] | |||||||||||||||||||||||||||||||||||||
|
crashed | |||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2016-01-13 ] | |||||||||||||||||||||||||||||||||||||
|
Okay, thanks... Lets get back for a moment. First, your environment field says "Linux debian, Windows 2008 R2". Which are we talking about now – Linux, or Windows, or both? And if it's Linux, which exactly Debian is it? And on which platform? Oh, and please paste or attach the error log from this last crash. | |||||||||||||||||||||||||||||||||||||
| Comment by Moshe L [ 2016-01-13 ] | |||||||||||||||||||||||||||||||||||||
|
the two servers in this test is Debian Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.65-1+deb7u2 x86_64 MariaDB 10.1.9 / 10.1.10 from apt-get. the same servers used same settings. Tried on the three one, Windows Server 2008 R2, same problem. | |||||||||||||||||||||||||||||||||||||
| Comment by Moshe L [ 2016-01-13 ] | |||||||||||||||||||||||||||||||||||||
|
2008 - msi from mariadb.org, 10.1.9 | |||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2016-01-22 ] | |||||||||||||||||||||||||||||||||||||
|
Frankly, I am at a loss at the moment. | |||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2016-02-19 ] | |||||||||||||||||||||||||||||||||||||
|
Moshe L, are you still experiencing the issue? If so, could you please consider the request above? | |||||||||||||||||||||||||||||||||||||
| Comment by Moshe L [ 2016-02-19 ] | |||||||||||||||||||||||||||||||||||||
|
Hi ! I can get you an access to duplicate of the server, via TeamViewer or similar. And on production, for now, I am using workaround by adding other key that solves the problem with the specific query so the code works. Thanks | |||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2016-02-19 ] | |||||||||||||||||||||||||||||||||||||
|
If it's a linux server, it might be easier just to grant us a temporary SSH access. If you want to do so, my public ssh key is here: https://launchpad.net/~elenst/+sshkeys | |||||||||||||||||||||||||||||||||||||
| Comment by Ian Gilfillan [ 2019-03-15 ] | |||||||||||||||||||||||||||||||||||||
|
Can this be closed as incomplete/cannot reproduce? | |||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2019-03-15 ] | |||||||||||||||||||||||||||||||||||||
|
Closing for now, as investigation apparently stalled at some point. |