[MDEV-6830] Server crashes in best_access_path after a sequence of SELECTs invollving a temptable view Created: 2014-10-02 Updated: 2014-12-22 Resolved: 2014-12-18 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 5.3.12, 5.5.40, 10.0.14 |
| Fix Version/s: | 5.5.41, 10.0.16, 5.3.13 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Elena Stepanova | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | optimizer, regression | ||
| Environment: |
cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfo |
||
| Description |
|
IMPORTANT: The crash only happens on a non-debug build (CMAKE_BUILD_TYPE-RelWithDebInfo), both on a handmade build and on release binaries. Reproduced on two mahines out of two that I tried (Debian and Windows). The problem appeared in 10.0 tree after this merge:
which is a 5.5 merge, but I am not getting the crash on 5.5 tree (which doesn't mean the problem doesn't exist there).
Test case is weird, but I couldn't remove anything else from it. All 3 selects seem to be important, as well as all multiple fields in the tables, even though they are not used. This particular test case only causes a crash on 10.0, but I am getting similar crashes on 5.5.40 as well.
|
| Comments |
| Comment by Elena Stepanova [ 2014-11-04 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
More stack traces that I am getting in buildbot presumably due to the same bug (for searching purposes).
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-12-17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I can repeat. It crashes in best_access_path
It seems, we are looking at a key in temporary table. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-12-17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Debugging SELECT non_existing FROM v2 create_tmp_table() = (TABLE *) 0x7fffccd1d020 SELECT * FROM t1, v3, t4 WHERE v3.f1 = t4.f1 AND t4.f2 = 6 AND t1.pk = v3.f5 create_tmp_table() = 0x7fffccd25020 Program received signal SIGSEGV, Segmentation fault. (gdb) p s->table (gdb) p s->table->s->keys (gdb) p s->table->key_info (gdb) p s->table->key_info - keyinfo (gdb) p key Why do we have key=1 (i.e. the second key) when the table has just one key? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-12-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
So there is a call to it calls TABLE::check_tmp_key(key=1, key_parts=1) = true However, KEYUSE array still keeps the element with key=1:
Note that key=1. That's the second key, while the table has only one key:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-12-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Ok the problem is in this pieced of code:
check_tmp_key() and add_tmp_key() use their "&first_keyuse" parameter as a loop variable. That is, these functions have a side effect of modifying this variable. Suppose the call to table->check_tmp_key(...) returned TRUE (which means failure). We then go to this loop
which uses first_keyuse. In our example, check_tmp_table() has set first_keyuse to NULL:
this will cause the loop not to execute. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-12-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Btw one can crash a debug binary also. One needs to run with --debug, so that print_keyuse() is invoked. It will crash when trying to get the name of a non-existent key. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-12-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Pushed into 5.3 and merged into 5.5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Patryk Pomykalski [ 2014-12-18 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I think it might be related to | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-12-19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Checked | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Patryk Pomykalski [ 2014-12-19 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Strange, for me this one fixed 6745 too... |