[MDEV-14698] mariadb hangs on a simple query with a dependent sub query innodb Created: 2017-12-18 Updated: 2018-01-10 Resolved: 2018-01-10 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data Manipulation - Subquery, Optimizer |
| Affects Version/s: | 5.5, 10.0, 10.1, 10.2.11, 10.2 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Philip orleans | Assignee: | Alexander Barkov |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | innodb, upstream | ||
| Environment: |
Centos 7 |
||
| Sprint: | 5.5.59 |
| Description |
|
This proves that the tables are properly indexed. The tables are actually smalll, 30K+ records. Yet the query hangs forever and "show processlist" says "Sending data" on the column "state".
I can give access to Elena so she can verify the issue. |
| Comments |
| Comment by Philip orleans [ 2017-12-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
I found something very similar but in this case there are only two small tables. The query itself is trivial. There is definitely a bug that makes innodb hang on the most absolutely simple of queries, one that would take a single second for SQL Server or any other databse. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2017-12-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
The EXPLAIN claims there are at least 230K+ rows in one table and 430K+ in another, not 30K as you said. Can the statistics be that much off, and that's what causes problems? Did you try to run ANALYZE on the tables and see if anything changes? Please also paste the output of ANALYZE FORMAT=JSON, it might help. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Philip orleans [ 2017-12-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Elena is right. I meant the "distintct zip_codes" are 30K, but the row data is much more. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2017-12-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
alice, please contact philip_38 as suggested to get access and investigate the problem. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Philip orleans [ 2017-12-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
I am trying to install Tokudb on Ubuntu xenial. First I add the repositories, and then I install mariadb-sever. It works fine. But when I try to run this command | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2017-12-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
Try mariadb-plugin-tokudb | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Philip orleans [ 2017-12-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
TokuDB is also useless. This simple query never finishes and "show processlist" shows an ever increasiing message explain select distinct zip_code from croutes where type not like 'PO%' and zip_code not in (select distinct zip_code from carrier_routes);
-----
----- | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2017-12-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
Right, sorry for suggesting ANALYZE, it is indeed useless in this case – unlike EXPLAIN, ANALYZE executes the actual query, so if the query hangs, ANALYZE also hangs. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Philip orleans [ 2017-12-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
I need to report that the same exact tables, same indexes, same data, in Ms SQL takes less than 1 second. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Philip orleans [ 2017-12-19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
I need to report that MySQL 5.7 has the same exact bug. So it is not a MariaDB bug. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alice Sherepa [ 2017-12-19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
According to my testing the problem behaviour is a bug, which is triggered when columns have different collations. So I expect that query will be fast if you change collation of column or alter table to the same collation. Following testcase demonstrates the problem:
If you need some further minor improvements, this could also be efficient:
I need some more investigation to verify the bug. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Philip orleans [ 2017-12-20 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
I confirm that once I changed the character set to Latin1, which involves the collation latin1_swedish_ci, the query works. | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alice Sherepa [ 2017-12-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
testcase, that suitable for 5.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2018-01-10 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
The problem is also repeatable with a similar script without using mysql.help_topic, using a smaller amount of records:
Now the query without character set conversion needs around 0.06 seconds:
The query with character set conversion needs 13.22 seconds:
So it does not hung. It just becomes slow when character set conversion takes place. The difference happens because in case of character set conversion the query gets effectively rewritten as:
so it cannot use the index on t3.z any more. These explains prove this:
Notice:
I'd say this behaviour is expected. But the optimizer can be in theory improved to catch such cases. |