[MDEV-27576] Use DESC indexes for MIN/MAX optimization Created: 2022-01-22 Updated: 2023-12-27 Resolved: 2023-12-14 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Fix Version/s: | 11.4.1 |
| Type: | Task | Priority: | Critical |
| Reporter: | Elena Stepanova | Assignee: | Yuchen Pei |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | Preview_11.4, optimizer-easy, optimizer-feature | ||
| Issue Links: |
|
||||||||||||||||||||
| Description |
|
As of c10e10c6, opt_sum.cc is still stubbed for DESC indexes
Given that we are about to close Given the above, the optimization expectedly doesn't work.
With the ASC index, it is
With the DESC index, it is
|
| Comments |
| Comment by Elena Stepanova [ 2022-01-23 ] | ||||||||||||||
|
I don't know what it will take to enable it, but it doesn't appear to be as simple as removing that if – having done so locally, I ran a quick set of tests and it returned quite a few failures. I can't say whether they genuinely relate to DESC indexes or just reveal some old problems, known or not, but they would certainly need to be investigated at least. So, given the release schedule, it may be safer to keep it as is now and, if at all needed, create a separate task for 10.9 about using DESC indexes in the optimizations. Or converting this item into such a task. However, there are at least some effects of the disabled optimization which can come as a surprise. For example, this
returns
I can't raise it to a bug level since it relies on float comparison which is not to be relied upon, but looking at existing MTR tests, for "normal" ascending indexes it is assumed that it will return the bigger value. Thus a surprise. | ||||||||||||||
| Comment by Yuchen Pei [ 2023-06-06 ] | ||||||||||||||
|
Trying to understand where the issue comes from. If I remove the if, I get NULL with descending index. The code path looks similar between the two, but after the call to find_key_for_maxmin(), get_index_max_value() assigns the max (*((Item *) conds)->cmp->a)->val_int(), which is 100 in the usual index and 1 The main actions of finding the max happens in the storage engine, though it is probably independent of storage engines as defined by the contract of index_last(), and the change for this ticket presumably should only touch the optimizer / sql layer. The storage engine code is rather low level, but to find out why things don't work as expected I have to look into it. With InnoDB, I notice that one difference between the two scenarios is page_rec_get_prev_const() counts up to 100 in the usual index and counts down to 1 in the descending index. To be further investigated... | ||||||||||||||
| Comment by Yuchen Pei [ 2023-11-01 ] | ||||||||||||||
|
The difference between counting up and down is simply because
| ||||||||||||||
| Comment by Yuchen Pei [ 2023-11-02 ] | ||||||||||||||
|
Hi psergei, ptal thanks
| ||||||||||||||
| Comment by Sergei Petrunia [ 2023-11-08 ] | ||||||||||||||
|
ycp, replied: | ||||||||||||||
| Comment by Yuchen Pei [ 2023-11-09 ] | ||||||||||||||
|
Thanks for the comments psergei. I addressed them and updated my commit. ptal thanks (I understand the fixversion is 11.5 so no rush):
| ||||||||||||||
| Comment by Sergei Petrunia [ 2023-11-13 ] | ||||||||||||||
|
The patch is ok, I've only requested some formatting changes via email. Then, we need to submit it for testing. | ||||||||||||||
| Comment by Yuchen Pei [ 2023-11-14 ] | ||||||||||||||
|
Thanks for the review psergei. Applied the formatting patch and
BTW, is this still targeted at 11.5? | ||||||||||||||
| Comment by Lena Startseva [ 2023-12-11 ] | ||||||||||||||
|
Testing done. Ok to push. But there are some notes about optimization strategies used by the query optimizer when there is ascending/descending index in the table. These moments were discussed with psergei and at this time they do not require improvement (because there is a task for improvement, or there is no need for improvement), but I think it is necessary keep this information. For the table:
The following query plans are:
Thus second query:
| ||||||||||||||
| Comment by Yuchen Pei [ 2023-12-14 ] | ||||||||||||||
|
pushed the following to 11.4 875377ad824473774c833b1aff4346ba3133f092 |