[MDEV-12867] Full scan despite appropriate index Created: 2017-05-22 Updated: 2021-03-19 |
|
| Status: | Stalled |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.2.5 |
| Fix Version/s: | 10.6 |
| Type: | Bug | Priority: | Major |
| Reporter: | Julien Muchembled | Assignee: | Sergei Petrunia |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | None | ||
| Environment: |
Debian 8, x86_64 |
||
| Issue Links: |
|
||||||||
| Description |
|
Using the following table:
The following request is far too slow:
It used the wrong index (maybe another issue). With correct index, it's not faster:
I want the `partition` column in the result because I'd like to query MAX(tid) for several values of `partition` at the same time (using GROUP BY). Without this column, it works as expected:
|
| Comments |
| Comment by Sergei Petrunia [ 2017-06-27 ] | |||||||||||||||||||||||
|
varun, please investigate. There is an index :
The query
ought to be resolved in opt_sum_query() by making one index lookup, but that is apparently not happening for some reason? | |||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2017-06-27 ] | |||||||||||||||||||||||
|
Does ENGINE=ROCKSDB play a role? I'm not aware of any reason ROCKSDB would be different from InnoDB for this query. | |||||||||||||||||||||||
| Comment by Julien Muchembled [ 2017-06-27 ] | |||||||||||||||||||||||
|
I don't know if it helps but I have the same issue with:
| |||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2017-06-28 ] | |||||||||||||||||||||||
|
[jmuchemb, yes, this shows that the issue is not in the storage engine, but rather at the SQL layer. Thanks! | |||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2017-07-01 ] | |||||||||||||||||||||||
|
Test case for this issue
| |||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2017-07-01 ] | |||||||||||||||||||||||
|
So after doing so investigation I see that the item object for the field a
So stepping into the code I see
So here by setting const_result=0 we say that we were not able to resolve all items as constants in the query. | |||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2017-07-03 ] | |||||||||||||||||||||||
|
varun, ok I tried debugging your example.
If I remove "a" from the select list, the optimization works:
compare with
| |||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2017-07-03 ] | |||||||||||||||||||||||
|
So we have in the select list
The WHERE clause has "a=0" but the Item_field object in the select list is not
A proof that multiple equality is already built:
I think it's feasible to develop a patch that will replace the
with
Here cannot_infer_that_item_is_constant() should use JOIN's multiple equalities.
Let's check the above questions with Igor as he's the most knowledgeable about | |||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2017-07-06 ] | |||||||||||||||||||||||
|
Notes from the yesterday optimizer call: Mixing of aggregates and non-aggregates is not allowed by the SQL standard. MySQL/MariaDB has the infamous extension that allows it. The following is legal:
here, the values of a and column2 can be from any row within "the group". And "the group" here consists of all table rows that match the WHERE clause. An alternative solution to the one mentioned in the previous comment:
At the moment the index lookup to find MIN(b) is done using HA_EXTRA_KEYREAD. If we need a column that's not a part of the index, we can
CC: igor. | |||||||||||||||||||||||
| Comment by Varun Gupta (Inactive) [ 2019-07-08 ] | |||||||||||||||||||||||
|
As discussed with Igor, functional dependency would take care of this case and it would be easier to check if the item in the select list is a constant or not. So this would be fixed in 10.5. | |||||||||||||||||||||||
| Comment by Roman Stingler (Inactive) [ 2021-02-19 ] | |||||||||||||||||||||||
|
is there any plans to fix this and https://jira.mariadb.org/browse/MDEV-11588 in 10.6. It would be critical and very important to close this after nearly 4 years |