[MDEV-7950] Item_func::type() takes 0.26% in OLTP RO Created: 2015-04-09 Updated: 2015-10-04 Resolved: 2015-06-18 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Affects Version/s: | 10.1 |
| Fix Version/s: | 10.1.6 |
| Type: | Bug | Priority: | Major |
| Reporter: | Sergey Vojtovich | Assignee: | Alexander Barkov |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Epic Link: | Performance: micro optimizations | ||||||||
| Description |
|
Data comes from Sandy Bridge system running sysbench OLTP RO in 1 thread against 1 table. Call graphs:
This is virtual method which can't be inlined. Most time spent for function call convention. Check if we can revoke it's virtual status. |
| Comments |
| Comment by Alexander Barkov [ 2015-04-15 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
In this SQL script:
Item_func::type() is called 16 times from JOIN::optimizer() and its callees during the above SELECT query:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2015-04-21 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Plan: 1. Fix " 2a. Introduce a new class Item_ident_or_func_or_sum, common parent for Item_func_or_sum and Item_ident (which covert Item_field and Item_ref), as they behave in very similar ways in the function build_equal_items_for_cond. 2b. Change the function build_equal_items_for_cond() into virtual method in Item and split the function into at least:
2c. Update: After discussion with Igor, it appeared that Item_field and Item_ref cannot appear in this context in the function build_equal_item_for_cond:
because conditions of type:
are already replaced to:
by the time of a build_eqial_items() call. See normilize_cond(). The part of the condition checking for Item_field::FIELD_ITEM was a dead code. Therefore the implementation of Item_ident_or_func_or_sum::build_equal_items() can be moved to Item_func, and Item_ident_or_func_or_sum itself is not really needed. 3. Split the function check_equality() into a method in Item. Implement This will replace two virtual calls inside the former function check_equality():
into a single virtual call in Item_cond_and::build_equal_items :
Additionally, implement Item_func_eq::build_equal_items() in addition to Item_func::build_equal_items() and move the call for check_equality() from Item_func::build_equal_items() to Item_func_eq::build_equal_items(). 4. Change this piece of code in the function build_equal_items():
to get rid of virtual calls by adding a new out parameter to Item::build_equal_items() of type COND_EQUAL**:
so Item::build_equal_items() can create cond_equal internally. This will replace two virtual calls, type() followed by functype(), to a single virtual call for build_equal_cond(). 5. Split the functions remove_eq_conds() and internal_remove_eq_conds() into a virtual method Item::remove_eq_conds(). This will replace about 6 calls for item->type() into a single call for item->remove_eq_conds(). 6. Split the function add_key_fields() into a method in Item. This will remove about 3 virtual calls item->type(), as well as some virtual calls item_func->functype(), and will add one virtual call item->add_key_fields() instead. 7. Split the function get_mm_parts() into a virtual method in Item. This will replaces one virtual call item->type() to another virtual call, item->get_mm_tree(), but also will remove a virtual call for functype(), which used to distinguish between COND_AND_FUNC and COND_OR_FUNC:
8. Split the code in Item::get_mm_tree() responsible for functions into methods in Item_func and its descendants:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2015-05-13 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Item_func_type() calls that remain after step4 (14 calls)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2015-05-14 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Item_func_type() calls that remain after step#5 (8 calls)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2015-05-19 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Item_func_type() calls that remain after step#6 (5 calls)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2015-06-18 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The goal of this task has been reached. We just need to do some clean-up after the Separate clean-up tasks have been created: |