[MDEV-32829] Crash when executing PS for query with eliminated subquery using view Created: 2023-11-17 Updated: 2023-11-28 Resolved: 2023-11-22 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Prepared Statements |
| Affects Version/s: | 10.4, 10.5 |
| Fix Version/s: | 10.4.33, 10.5.24, 10.6.17, 10.11.7, 11.0.5, 11.1.4, 11.2.3, 11.3.2 |
| Type: | Bug | Priority: | Major |
| Reporter: | Ramesh Sivaraman | Assignee: | Rex Johnston |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | regression | ||
| Issue Links: |
|
||||||||
| Description |
|
Leads to:
Bug confirmed present in: |
| Comments |
| Comment by Ramesh Sivaraman [ 2023-11-17 ] | ||||||||||||||||
|
The crash occurs after this commit
| ||||||||||||||||
| Comment by Rex Johnston [ 2023-11-20 ] | ||||||||||||||||
|
One of MariaDB's query simplification techniques, obliquely referred to here https://mariadb.com/kb/en/optimizing-group-by/ is removing group by clauses in sub-queries where the outer condition allows this. These conditions include exists, in, > and <, where duplicate rows are irrelevant to the outcome. Removing these clauses allows the query planner more latitude in selecting a good execution plan. This simplification takes place during the prepare phase of join processing. The whole "GROUP BY" clause is removed, both simple column references and expressions. Any containing unit in sub-selects that have been removed have the select_lex structure removed, the pointer set to null (this is important as you'll see later). Any sub-selects, removed by the above simplification, that also contain a view will be affected by this bug. Consider the following example
A view is used in a sub-query clause,
which is part of a group by outer clause.
When preparing the statement,
mysql_test_select() will partially execute the statement and build the join structure(s) required for execution.
is redundant, as it is in a sub-query, there are no aggregate functions and no HAVING clause, so removes it. This leaves the table structures associated with that instance of the view with it's containing unit having no select_lex pointers.
mysql_derived_reinit() is called to reinitialize the unit and select_lex item list names. Note that if a normal table is removed
mysql_derived_reinit() is not called. I should also note that a stored procedure can be used to cause this crash.
During the second execution, mysql_derived_reinit() will be called on the emptied unit that used to represent
and crash. CTEs and derived tables are not affected as only a view has a table structure left over from a previous prepare, they are both "local" to the currently executing query in this respect. Fixed by ensuring restore_item_list_names() is never called from a null pointer. | ||||||||||||||||
| Comment by Igor Babaev [ 2023-11-22 ] | ||||||||||||||||
|
Ok to push into 10.4 |