[MDEV-25994] Crash with union of my_decimal type in ORDER BY clause Created: 2021-06-23 Updated: 2023-12-12 Resolved: 2022-04-22 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 5.5, 10.0, 10.1, 10.2, 10.3, 10.4, 10.5, 10.6 |
| Fix Version/s: | 10.2.44, 10.3.35, 10.4.25, 10.5.16, 10.6.8, 10.7.4, 10.8.3, 10.9.1 |
| Type: | Bug | Priority: | Blocker |
| Reporter: | Vicențiu Ciorbaru | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||||||||||||||||||
| Description |
|
Steps to reproduce:
|
| Comments |
| Comment by Alice Sherepa [ 2021-06-23 ] | |||||||||||||||||||||||||||||||
|
Repeatable on 5.5-10.6
| |||||||||||||||||||||||||||||||
| Comment by Oleg Smirnov [ 2022-04-16 ] | |||||||||||||||||||||||||||||||
|
1. The cause of the crash is NULL value of dec_val pointer retrieved in this function:
dec_val isn't analyzed for NULL so dec_val->to_binary() is called and that leads to the crash. And the cause of NULL value is the failure to execute a single row subselect due to more than one row in the result:
Looking for the ways to process this situation correctly. 2. Does it make any sense to evaluate ORDER BY for an UPDATE that does not have a LIMIT clause? Maybe we can eliminate such ORDER BY at an early stage? | |||||||||||||||||||||||||||||||
| Comment by Oleg Smirnov [ 2022-04-17 ] | |||||||||||||||||||||||||||||||
|
3. I pushed the fix to bb-10.2- | |||||||||||||||||||||||||||||||
| Comment by Oleg Smirnov [ 2022-04-18 ] | |||||||||||||||||||||||||||||||
|
Buildbot tests have succeded (https://buildbot.askmonty.org/buildbot/grid?category=main&branch=bb-10.2-MDEV-25994), so I'm passing this to review. | |||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-04-19 ] | |||||||||||||||||||||||||||||||
|
I see one more problem in Type_handler_decimal_result::make_sort_key:
That is, Item_singlerow_subselect has maybe_null=FALSE, but after val_decimal() it has null_value=TRUE... | |||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-04-20 ] | |||||||||||||||||||||||||||||||
|
Trying to debug a different query:
Internally, the same happens: Then, there is a check for thd->is_error(), after which the query execution is aborted. | |||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-04-20 ] | |||||||||||||||||||||||||||||||
|
A proposed alternative patch:
The idea is to follow the approach in other places and handle the case when item->null_value==true even for items that have maybe_null==false. (I'm not sure if I've fixed all places in make_sort_key code) | |||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-04-20 ] | |||||||||||||||||||||||||||||||
|
Oleg's patch:
if make_sort_key() returns true only on error... well, one can check for error condition by looking at thd->is_error() ... | |||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-04-20 ] | |||||||||||||||||||||||||||||||
|
Take-aways from the call: it seems the best way forward is to make Item_singlerow_subselect NULLable when appropriate | |||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-04-21 ] | |||||||||||||||||||||||||||||||
|
https://github.com/MariaDB/server/commit/baec17bc033cb9be02428e2089046df9f530754a | |||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-04-21 ] | |||||||||||||||||||||||||||||||
|
sanja, please review the second patch variant: https://github.com/MariaDB/server/commit/baec17bc033cb9be02428e2089046df9f530754a | |||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2022-04-22 ] | |||||||||||||||||||||||||||||||
|
OK to push. | |||||||||||||||||||||||||||||||
| Comment by Oleg Smirnov [ 2022-04-25 ] | |||||||||||||||||||||||||||||||
|
And what do you think about my comment #2: |