[MDEV-67] LP:912510 - Crash in do_copy_not_null with semijoin=ON, firstmatch=ON, aggregate function, IN subquery Created: 2012-01-05 Updated: 2012-01-31 Resolved: 2012-01-10 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 5.3.3, 5.3.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major |
| Reporter: | Elena Stepanova | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
bzr version-info |
||
| Description |
|
I'm leaving it 'Major' but not 'Critical' because the query in the test case is not very smart (due to the mix of aggregate and non-aggregate without a group by), although quite simple.
Minimal optimizer_switch: firstmatch=on,semijoin=on (current defaults) EXPLAIN:
Reproducible on 5.3.3 release binaries. Test case:
|
| Comments |
| Comment by Sergei Petrunia [ 2012-01-05 ] |
| Comment by Elena Stepanova [ 2012-01-05 ] |
|
This bug has been also filed in LP as https://bugs.launchpad.net/maria/+bug/912510 |
| Comment by Sergei Petrunia [ 2012-01-06 ] |
|
Analysis: 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where we crash when constructing the lookup key for doing a lookup on t3.c= t1.a. t1.a is defined as NOT NULL, and so has copy->from_null_ptr == NULL. Yet, do_copy_not_null() function is called for it which attempts to do copy from NULL-able field and tries to access from_null_ptr. More details: create_ref_for_key( t3) creates a lookup reference for t3.c=t2.b. Later on, substitute_for_best_equal() changes t3.c (which is NULLable) to t1.a (which is NOT NULL). |
| Comment by Sergei Petrunia [ 2012-01-06 ] |
|
When we fix ref access structures after equality substituion at: #0 Copy_field::set (this=0x9f5d51c, to=0x9f5d570, from=0x9f45a60, save=false) at field_conv.cc:620 We get: (gdb) p from->maybe_null() That is, table t1 is marked as NULLable, as if it was an inner table of an table->maybe_null is set to TRUE by this code in JOIN::prepare(): if (mixed_implicit_grouping) |
| Comment by Sergei Petrunia [ 2012-01-08 ] |
|
The problem happens only with semi-join subqueries. When one runs a while ((tbl= li++)) { ... // comment if (mixed_implicit_grouping) tbl->table->maybe_null= 1; }is run for all three tables, t1, t2, t3. When one runs a semi-join, maybe_null=1 is set only for table t1, because |
| Comment by Sergei Petrunia [ 2012-01-08 ] |
|
This raises a question: should we set maybe_null=TRUE for tables that are The answer is NO: tbl->maybe_null=TRUE is set, because references to "tbl.col" from HAVING or The HAVING clause and select_list may not contain references to tables that
=> there is no need to set tbl->maybe_null=TRUE for tables that are inner |
| Comment by Sergei Petrunia [ 2012-01-08 ] |
|
Committed a fix, waiting for review. |