[MDEV-5368] Server crashes in Item_in_subselect::optimize on 2nd execution of PS with IN subqueries, materialization+semijoin Created: 2013-12-01 Updated: 2014-01-29 Resolved: 2014-01-23 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 5.3.12, 5.5.34, 10.0.6 |
| Fix Version/s: | 5.5.35, 10.0.8, 5.3.13 |
| Type: | Bug | Priority: | Major |
| Reporter: | Elena Stepanova | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||
| Description |
|
|
| Comments |
| Comment by Sergei Petrunia [ 2014-01-22 ] |
|
a VIEW is not necessary, the crash could be repeated when using a derived table, too: prepare s from ' |
| Comment by Sergei Petrunia [ 2014-01-22 ] |
|
The crash happens in - Item_in_subselect::optimize(). The cause is this->unit->first_select()->join==NULL that is, a JOIN object has not yet been constructed for the Item_in_subselect. The subselect is not a part of WHERE clause - it has been converted into a non-merged semijoin (see setup_jtbm_semi_joins in the stack trace) during the first EXECUTE call. |
| Comment by Sergei Petrunia [ 2014-01-22 ] |
|
When a subquery is still an Item in a WHERE clause, it gets its JOIN here: JOIN::JOIN |
| Comment by Sergei Petrunia [ 2014-01-22 ] |
|
In general, non-merged semi-joins work with PS. If I run PREPARE, EXECUTE, EXECUTE for this query: select * from t1a where a in (select max(a) from t1) on second EXECUTE the join is created here: JOIN::JOIN setup_tables() has this piece: if (table_list->jtbm_subselect) |
| Comment by Sergei Petrunia [ 2014-01-22 ] |
|
.. and it seems that piece of code is not hit. I'm debugging the original query (the variant without the VIEW), second if (select_lex->first_cond_optimization) { ... }else { List_iterator_fast <TABLE_LIST> ti(select_lex->leaf_tables_exec); select_lex->leaf_tables.empty(); while ((table_list= ti++)) ... } for (table_list= tables; The while() loop enumerates all three tables: t1, t2, <subquery4> <subquery4> is never processed. |
| Comment by Sergei Petrunia [ 2014-01-22 ] |
|
convert_subq_to_jtbm() has these lines: /* Nests do not participate in those 'chains', so: */ ... /* A theory: no need to re-connect the next_global chain */ Perhaps, they are the cause of this bug. |
| Comment by Sergei Petrunia [ 2014-01-23 ] |
|
The code actually makes an attempt to connect the next_leaf chain. The problem is that something is connected in the wrong place.
that way, second re-execution doesn't see the non-merged semi-join in TABLE_LIST::next_local chain |
| Comment by Sergei Petrunia [ 2014-01-23 ] |
|
Had a discussion with Sanja. convert_subq_to_sj() has this code tl->next_local= subq_lex->leaf_tables.head(); it attaches first of child's leaf_tables into the parent's TABLE_LIST:::next_local list. This is incorrect, we should attach child's next_local chain (and not the first table in child's leaf_tables list). |
| Comment by Daniel Bartholomew [ 2014-01-29 ] |
|
http://bazaar.launchpad.net/~maria-captains/maria/5.5/revision/2502.567.185 |
| Comment by Daniel Bartholomew [ 2014-01-29 ] |
|
http://bazaar.launchpad.net/~maria-captains/maria/5.5/revision/4026 |