[MDEV-28958] Crash when checking whether condition can be pushed into view Created: 2022-06-27 Updated: 2023-03-16 Resolved: 2023-03-16 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.7, 10.8, 10.9, 10.10, 10.11 |
| Fix Version/s: | 11.1.0, 10.11.3, 10.8.8, 10.9.6, 10.10.4 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Roel Van de Paar | Assignee: | Igor Babaev |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | not-10.3, not-10.4, not-10.5, not-10.6, pushdown_from_having, regression-10.7 | ||
| Attachments: |
|
| Description |
|
Leads to:
Bug confirmed present in: Bug (or feature/syntax) confirmed not present in: |
| Comments |
| Comment by Roel Van de Paar [ 2022-07-13 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Secondary testcase
Leads to:
Bug confirmed present in: Bug (or feature/syntax) confirmed not present in: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-11-10 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
According to Johnston, still reproducible on current 10.7. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-11-10 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Johnston, please try with valgrind (or a *san) build. Maybe it will immediately show we're trying to access free'd memory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Rex Johnston [ 2022-11-10 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I can confirm that it's not in 10.5 too. Will try valgrind first. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Rex Johnston [ 2022-11-14 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Valgrind build fails...
etc. Investigating. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Roel Van de Paar [ 2022-11-14 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Johnston Try ASAN + UBSAN build (they can be merged) and/or MSAN build. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Rex Johnston [ 2022-11-15 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Have got valgrind build working. At the crash point...
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-11-28 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Valgrind error I'm observing:
Indeed, the Item_true is a global object which somehow was put into a read-only memory. And Rex's fix is to make Item_func_eq::build_equal_items allocate a new object which is private to this query and is writable. This is correct. My concern is, are there any other scenarios where Item tree has a pointer to this global Item_true object? If there are, we can get other similar bugs...
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-11-28 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Discussed this with Monty. We should try to avoid setting/clearing flags like extraction flag in constant items. One needs to take a look at why pushdown_cond_for_derived() does it. It looks like it should be sufficient to set/clear such flags only for direct children of Item_cond_and/Item_cond_or objects. Items that are constant should not be direct children of Item_cond_and/item_cond_or (as they can be removed in that case). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michael Widenius [ 2022-11-28 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The issue is that we are calling clear_extraction_flag on all items, including const items and other items that we are not going to mark or have to mark. It is a not a good idea to mark all items, including sub items, as the marking and cleanup can become very expensive in the long run. Better to avoid marking all items (just marking AND and OR items can be ok) One can easily avoid the issue with Item_true/Item_false as these are ALWAYS top level items. Checking for basic_const_item() at function start/function call avoids this issue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Michael Widenius [ 2022-11-28 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Here is a suggested patch that fixes the issue: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2022-11-29 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
As far as I understood from the optimizer call this week, Igor will clarify something about which way this should be fixed... (Please re-assign accordingly if it is not correct) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2022-11-30 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The following test case is more meaningful and causes the same problem:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2022-11-30 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
If we are not allowed to use the field 'marker' for basis_const_items let's not to use this field for such items:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2023-02-06 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
OK to push. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2023-03-16 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
A fix for this bug was pushed into 10.8 |