[MDEV-321] CHEAP SQ: A query with inner joins and EXISTS subquery takes several times longer on MDEV-193 tree than on 5.5 main tree Created: 2012-06-06 Updated: 2012-06-08 Resolved: 2012-06-08 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 5.5.27 |
| Type: | Bug | Priority: | Major |
| Reporter: | Elena Stepanova | Assignee: | Timour Katchaounov (Inactive) |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
The following query
takes several times longer on Reproducible with the default optimizer_switch as well as all OFF values except for in_to_exists required to execute the query. EXPLAIN on
EXPLAIN on maria/5.5 (with the default optimizer_switch):
Test case:
|
| Comments |
| Comment by Timour Katchaounov (Inactive) [ 2012-06-07 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
This is a generic join optimizer problem that is completely unrelated to mdev-193. In the example above, if the predicate is considered non-expensive, then it is evaluated If one runs the simplified query directly: SELECT MAX(al1.a) FROM t1 AS al1, t1 AS al2, t1 AS al3, t1 AS al4 WHERE al4.a = al3.a; It executes equally slowly. This can also be verified with mysql-trunk (both with the simplified The reason for the slow execution is the join order chosen by the optimizer: -----
-----
----- This order coincides with the order of the tables in the FROM clause. The reason why this plan is slow, is because If we reorder the tables in the FROM clause (or use STRAIGHT_JOIN) as follows: MariaDB [md321]> explain SELECT MAX(al1.a) FROM t1 AS al4, t1 AS al3, t1 AS al2, t1 AS al1 WHERE al4.a = al3.a;
-----
----- This plan takes ~4 sec instead of ~50 sec of the previous plan. If we run the original test case with the correct table order, the plan is also very fast ~9 sec. Finally, if the test case query is run with 5.5 main, or with mdev-193 and set expensive_subquery_limit=0, In summary, mdev-193 allows the optimizer to correctly simplify the WHERE clause, but it exposes a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2012-06-08 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Timour, If it exposes a weakness of the join optimizer then report a new bug. From your analysis it's not clear why the cost of the first plan is less than the cost of the second plan. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2012-06-08 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Here's what I had in the latest MariaDB 5.5: MariaDB [test]> explain SELECT MAX(al1.a) FROM t1 AS al4, t1 AS al3, t1 AS al2, t1 AS al1 WHERE al4.a = al3.a;
-----
----- MariaDB [test]> SHOW SESSION STATUS LIKE 'Last_query_cost';
----------------
---------------- MariaDB [test]> EXPLAIN SELECT MAX(al1.a) FROM t1 AS al1, t1 AS al2, t1 AS al3, t1 AS al4 WHERE al4.a = al3.a;
-----
----- MariaDB [test]> SHOW SESSION STATUS LIKE 'Last_query_cost';
----------------
---------------- MariaDB [test]> set optimizer_prune_level=1; MariaDB [test]> EXPLAIN SELECT MAX(al1.a) FROM t1 AS al1, t1 AS al2, t1 AS al3, t1 AS al4 WHERE al4.a = al3.a;
-----
----- MariaDB [test]> SHOW SESSION STATUS LIKE 'Last_query_cost';
----------------
---------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2012-06-08 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The problem is repeatable in MariaDB 5.2. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Timour Katchaounov (Inactive) [ 2012-06-08 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
As said above, this problem is unrelated to mdev-193. |