[MDEV-13186] main.win failure post MDEV-12336 Created: 2017-06-27 Updated: 2017-07-05 Resolved: 2017-07-05 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer - Window functions |
| Affects Version/s: | 10.2 |
| Fix Version/s: | 10.2.7, 10.3.1 |
| Type: | Bug | Priority: | Major |
| Reporter: | Vicențiu Ciorbaru | Assignee: | Vicențiu Ciorbaru |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Description |
|
This failure only happens with prepared statement protocol.
|
| Comments |
| Comment by Vicențiu Ciorbaru [ 2017-06-27 ] | |||||||||||||||||||||||||||||||||||||||||||
|
I devised a test case that first prepares the statement then executes it, to not have to rely on --ps flag for mtr.
So we execute the query:
We're going through JOIN::prepare and reach the setup_fields call:
Currently all_fields contains just one element:
So we have a case item with an equality comparison that features a window function. Let's look at how the window function specifications look at this point.
So the partition list has an Item_field referencing t.b. This is from the select statement's parsing stage. Now we go past setup_fields call and reach setup_without_group. The all_fields list now contains 3 elements, which are:
So the fields now are:
The ref_ptrs array now has:
Running through setup_without_group, we call setup_windows which calls setup_group to set up partitions, which calls find_order_in_list. find_order_in_list concludes that the order item is not in the field list and proceeds to add it to all_fields. Now ref_ptrs[3] is overwritten (line 22210 in sql/sql_select.cc) with the "fixed" Item_field t.b. And we add this Item_field to all_fields. So ref_ptrs[3] is the window function partition by field t.b
KEY NOTE: As a side effect of this procedure, the order structure in PARTITION BY has the item member point to &ref_pointer_array[3]! Going forward with running the statement:
In Item::split_sum_func2 we end up overriding ref_pointer_array[3] to Item_func_eq, but since the Item_func_eq contains a window function, we don't Now this order->item subsequently has "with_window_func" flag set to true and thus fails our condition that window functions are not allowed in partition by context. SOLUTION: An ideal solution would be to never have to do any setting of ref_ptrs_array post prepare (which seems to be the intent for the array in the first place), but this may need to be targeted for a 10.3 or 10.4 release. | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Vicențiu Ciorbaru [ 2017-06-27 ] | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Vicențiu Ciorbaru [ 2017-06-27 ] | |||||||||||||||||||||||||||||||||||||||||||
|
Patch that fixes the problem: diff --git a/sql/item.cc b/sql/item.cc
| |||||||||||||||||||||||||||||||||||||||||||
| Comment by Vicențiu Ciorbaru [ 2017-06-27 ] | |||||||||||||||||||||||||||||||||||||||||||
|
Another thing to note: This bug was not apparent immediately after This counter is used to allocate an appropriately sized array during setup_ref_array. It is called before calling setup_fields which calls split_sum_func. Before Post | |||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-07-04 ] | |||||||||||||||||||||||||||||||||||||||||||
|
All is OK, but add comments please |