[MDEV-6797] intcol=NUM is not used to remove intcol from ORDER BY if NUM is quoted Created: 2014-09-26 Updated: 2023-12-05 |
|
| Status: | Stalled |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.0.13 |
| Fix Version/s: | 10.1 |
| Type: | Bug | Priority: | Major |
| Reporter: | Sergei Petrunia | Assignee: | Sergei Petrunia |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | datatype, optimizer, order-by-optimization | ||
| Sprint: | 10.1.6-2 |
| Description |
|
ORDER BY optimizer removes constant items from ORDER BY list. That is, if there is a query
then col1 can be removed from ORDER BY list (except for some charsets). The problem is, this feature doesn't work for some cases where it should.
Now, lets try two queries, one with pk1=const and the other with pk1='const':
|
| Comments |
| Comment by Sergei Petrunia [ 2014-09-26 ] | ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-09-26 ] | ||||||||||||||||||||||||
|
Note that the ref optimizer is able to make use of "pk1='123'". It's only ORDER BY optimizer that can't. | ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-09-26 ] | ||||||||||||||||||||||||
|
Narrowed it down to this code:
ORDER BY optimizer uses it to check whether rows that satisfy "item=const" are all equal from the point of view of "ORDER BY item". Here,
Apparently, the restriction in this function is too strict. | ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-09-28 ] | ||||||||||||||||||||||||
|
Discussed the problem with bar. Came to conclusion that whenever the column's result_type is in { REAL_RESULT, INT_RESULT, DECIMAL_RESULT , TIME_RESULT}then the comparison guarantees uniqueness. | ||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-09-28 ] | ||||||||||||||||||||||||
|
Consider a counter-example: (gdb) p 0xFFFF FFFF FFFF FFFF
Hmm this was supposed to be a counter example, but it's not. If the comparison a='...' has been done by comparing double values, then all values in the table would have been equal to the constant, because of insufficient precision. This didn't happen, because of this code:
and the code here sets args[i]->cmp_context to show which type will be used for comparison. | ||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2014-09-28 ] | ||||||||||||||||||||||||
|
Hi Sergei,
It's cmp_type(), not result_type()!!! | ||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2014-10-10 ] | ||||||||||||||||||||||||
the restriction is formally correct. But it doesn't take into account that hack in Item_bool_func2::fix_length_and_dec(). Perhaps, instead of having that hack and — on top of that — introducing another hack in test_if_equality_guarantees_uniqueness() it'd be cleaner to replace the string literal with a numeric literal (under the same conditions that Item_bool_func2::fix_length_and_dec() checks now). | ||||||||||||||||||||||||
| Comment by Julien Fritsch [ 2023-12-05 ] | ||||||||||||||||||||||||
|
Automated message: |