[MDEV-20129] Equality propagation for ORDER BY items do not work with expressions Created: 2019-07-23 Updated: 2023-11-28 |
|
| Status: | Stalled |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.2, 10.3, 10.4, 10.5, 10.6, 10.9, 10.10, 10.11, 11.0, 11.1, 11.2 |
| Fix Version/s: | 10.6, 10.11, 11.0, 11.1, 11.2 |
| Type: | Bug | Priority: | Major |
| Reporter: | Varun Gupta (Inactive) | Assignee: | Sergei Petrunia |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
Test data
So for expressions we don't propagate equal fields and so we are not able to use the optimization where we can sort by the first table |
| Comments |
| Comment by Varun Gupta (Inactive) [ 2019-07-29 ] | |||||||||||||||
|
Patch | |||||||||||||||
| Comment by Sergei Petrunia [ 2020-06-06 ] | |||||||||||||||
|
Review notes: The idea behind the new function equality_propagation_for_order_items doesn't look good to me. The effect of the function is similar (but exactly the same) as propagate_equal_fields call followed by substitute_for_best_equal_field call. Here is an alternative variant of the fix that uses those two calls: https://gist.github.com/spetrunia/f48251cc87f07cc8e4a8fa9910bbe6c7 | |||||||||||||||
| Comment by Sergei Petrunia [ 2020-06-06 ] | |||||||||||||||
|
Another interesting observation: Before the patch, the optimizer only handles "ORDER BY table.col". The code in remove_const() checks if it can be substituted with other_table.col, and whether that will allow to get rid of "Using temporary". No substitution is performed here. The substitution is done in Filesort::make_sortorder():
(item->get_item_equal() returns non-NULL only for Item_field and Item_direct_view_ref. ) The patch for this MDEv adds "early substitution": if the Item_field that we need to replace is not at the top level of the ORDER BY clause, it will be replaced in remove_const(). Can we switch the code to do the substitution in only one place and do it "early"? I've tried to do that and got an assertion failure in create_tmp_table, not sure why. |