Skip to content

Commit

Permalink
Fix inefficient range tree construction from IN list
Browse files Browse the repository at this point in the history
Summary:
Fixes https://bugs.mysql.com/108963

When constructing the range tree, we end up re-merging the current tree for every element of the IN list, and this causes optimization to be very slow. Fix this by switching the order of arguments, so that we always merge the new item into the existing tree instead.

I've also considered fixing `key_or` to automatically swap the order of arguments, but there is already existing swapping logic that considers which tree needs copied vs can be edited in place, and it seems unclear how to integrate with that effectively (since the two goals could be conflicting).

Test Plan:
tested manually using the query affecting user


before:
```
+----+-------------+------------------------------+------------+------+---------------+------+---------+------+------+----------+-------------+
| id | select_type | table                        | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
+----+-------------+------------------------------+------------+------+---------------+------+---------+------+------+----------+-------------+
|  1 | SIMPLE      | nee_violation_obj_chg_events | NULL       | ALL  | unique_event  | NULL | NULL    | NULL |    1 |   100.00 | Using where |
+----+-------------+------------------------------+------------+------+---------------+------+---------+------+------+----------+-------------+
1 row in set, 40970 warnings (6 min 24.58 sec)
```

after
```
+----+-------------+------------------------------+------------+------+---------------+------+---------+------+------+----------+-------------+
| id | select_type | table                        | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
+----+-------------+------------------------------+------------+------+---------------+------+---------+------+------+----------+-------------+
|  1 | SIMPLE      | nee_violation_obj_chg_events | NULL       | ALL  | unique_event  | NULL | NULL    | NULL |    1 |   100.00 | Using where |
+----+-------------+------------------------------+------------+------+---------------+------+---------+------+------+----------+-------------+
1 row in set, 40970 warnings (0.34 sec)
```

Reviewers: herman, yoshinori, #mysql_eng

Reviewed By: herman

Subscribers: pgl

Differential Revision: https://phabricator.intern.facebook.com/D40948362

Tasks: T135027152
  • Loading branch information
Manuel Ung authored and lth committed Nov 2, 2022
1 parent f51a654 commit 04ddd79
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion sql/range_optimizer/range_analysis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ static SEL_TREE *get_func_mm_tree_from_in_predicate(
*/
if (and_tree == nullptr) return nullptr;
}
or_tree = tree_or(param, remove_jump_scans, and_tree, or_tree);
or_tree = tree_or(param, remove_jump_scans, or_tree, and_tree);
}
return or_tree;
}
Expand Down

0 comments on commit 04ddd79

Please sign in to comment.