[MDEV-28617] Crash with INSERT...SELECT using a derived table in GROUP BY clause Created: 2022-05-19 Updated: 2022-09-05 Resolved: 2022-08-03 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data Manipulation - Delete, Data Manipulation - Insert |
| Affects Version/s: | 10.3.35, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8 |
| Fix Version/s: | 10.3.36, 10.4.26, 10.5.17, 10.6.9, 10.7.5, 10.8.4, 10.9.2 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Shihao Wen | Assignee: | Igor Babaev |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | fuzzer | ||
| Environment: |
ubuntu 18.04 |
||
| Attachments: |
|
| Description |
|
poc:
output: The full error log is in the attachment. |
| Comments |
| Comment by Daniel Black [ 2022-05-19 ] | ||||||||||||||||||||||||||||||
|
Confirmed on 10.3.35+c9b5a05341d7342db5f369493ea200b5fb9db243 for the first insert statement. Following SQL not needed. | ||||||||||||||||||||||||||||||
| Comment by Alice Sherepa [ 2022-05-20 ] | ||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2022-08-01 ] | ||||||||||||||||||||||||||||||
|
This bug manifests itself for INSERT...SELECT statements whose WHERE condition contained an IN/ANY/ALL predicand with such grouping subquery that:
Execution of this query causes a crash of the server at the prepare phase. The bug causes similar crash when executing a single-table DELETE statement if it uses a WHERE condition with EXISTS subquery whose WHERE condition is such as described above for affected INSERT...SELECT statements. Here's an example of such DELETE statement
| ||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2022-08-02 ] | ||||||||||||||||||||||||||||||
|
When executing the INSERT...SELECT statement from the previous comment we come to the call of JOIN::prepare() for the subquery of the IN predicand. JOIN::prepare notices that the GROUP BY clause of the subquery can be e liminated and it calls remove_redundant_subquery_clauses() that removes the subquery of the GROUP BY clause. The corresponding select together with underlying select of the derived table are excluded from the select tree of the statement. The call of select_insert::prepare() checks whether any of the tables used the SELECT part of the statement is the same as the updated table by invoking unique_table() and then find_dup_table() inside it. find_dup_table() sees that this is the case for table t1 used in the derived table and it forces the materialization of the derived table dt calling TABLE_LIST::set_materialized_derived() in spite of the fact that the | ||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2022-08-02 ] | ||||||||||||||||||||||||||||||
|
OK to push | ||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2022-08-03 ] | ||||||||||||||||||||||||||||||
|
A fix for this bug was pushed into 10.3 |