[MDEV-6876] Limit in subquery changes behavior, even when arbitrarily high limit is used Created: 2014-10-16 Updated: 2015-09-10 Resolved: 2015-09-10 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 5.5.40 |
| Fix Version/s: | 10.1.8 |
| Type: | Bug | Priority: | Major |
| Reporter: | adipose | Assignee: | Oleksandr Byelkin |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | upstream | ||
| Environment: |
Windows Server 2008 R2 64 bit. |
||
| Attachments: |
|
| Sprint: | 10.1.8-1 |
| Description |
|
Issue described here: http://stackoverflow.com/questions/26393529/why-does-mariadb-behave-differentyly-when-an-arbitrarily-high-limit-is-placed-on A limit of 2^64-1 on a subquery changes the optimization for the better, even though it theoretically has no effect on the subquery.
Changing the subquery to the following results in a different result
The query time changes from 9.1 seconds to .078. |
| Comments |
| Comment by Elena Stepanova [ 2014-10-16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi, Could you please send SHOW CREATE TABLE and SHOW INDEX IN output for quotes, sostatus and sos? I tried to create the tables based on queries, but I'm getting different plans (also changing upon adding LIMIT, but still different from yours). Thanks. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by adipose [ 2014-10-16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I updated the queries above to have a more watered down query, and to include a cast statement. Without the cast statement, the explain still changes, but the performance doesn't change as I originally reported. So this should more accurately describe the situation.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2014-10-16 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thank you. Assigning to psergey to evaluate how much of a bug it is and what it takes to fix it. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2015-09-10 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
As far as I can see limit just prevent merging and in this case materialization is more efficient. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2015-09-10 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I attached dump of database where I was experimenting. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2015-09-10 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
In discussion with Sergey Petrunia we figured our that in case of merge expression CAST(`dnum` as UNSIGNED) prevent using hash join. In case of materialization we already has 2 fields and hash join works. At the moment optimizer this situation is beyond cases it can detect. So only manual optimization can help. Sorry. |