[MDEV-9197] Pushdown conditions into non-mergeable views/derived tables Created: 2015-11-27 Updated: 2021-12-22 Resolved: 2016-09-26 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Optimizer |
| Fix Version/s: | 10.2.2 |
| Type: | Task | Priority: | Major |
| Reporter: | Sergei Petrunia | Assignee: | Igor Babaev |
| Resolution: | Fixed | Votes: | 8 |
| Labels: | Compatibility, contribution, foundation, gsoc16, optimizer | ||
| Attachments: |
|
||||||||||||||||||||||||||||
| Issue Links: |
|
||||||||||||||||||||||||||||
| Epic Link: | Oracle Compatibility | ||||||||||||||||||||||||||||
| Sprint: | 10.2.2-2, 10.2.2-4 | ||||||||||||||||||||||||||||
| Description |
| Comments |
| Comment by Galina Shalygina (Inactive) [ 2016-06-17 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Detailed description of the task. The following optimization of the queries that use nonmergeable views and/or derived tables will be implemented. A condition that depends only on the columns of the view/derived table is extracted from the Generally such condition can be pushed into the HAVING clause of the subquery. Let's consider a view defined through a grouping query: create view v as select a, avg(b) from t1 group by a; Let's use this view in a query: select * from v, t where v.a in (const1, const2) and t.a=v.a; Apparently this query could be very fast, especially if there were an index on t1.a. If before materialization we could push the condition v.a in (const1, const2) into the view and materialized the result of the query: select a, avg(b) from t1 group by a having a in (const1, const2); materialization would become much faster. At some conditions it makes sense to push a in (const1, const2) even further into the WHERE clause: select a, avg(b) from t1 where a in (const1, const2) group by a; (E.g. when there is an index on t1.a) 1. Separable conditions These are conjunctive conditions that depend only on view columns: select * from v,t where P1(v) AND P2(v,t); Here P1(v) is a predicate depending only on the columns of v, while P2(v,t) is a predicate depending on the columns of v and t. Apparently P1(v) can be separated from the WHERE clause of the main query and moved to the HAVING clause of the view. (In some cases it can be moved to the WHERE clause of the view). The case with separable conditions is pretty easy to implement. 2. Nonseparable conditions In a more general case there are no conjunctive conditions depending only on the columns of v, but still some restrictive condition depending only on v can be extracted from the WHERE clause. select * from v,t Here the condition (P1(v) OR P3(v)) is implied by the WHERE condition and can be pushed into the view. Yet it's not a conjunctive condition so it cannot be separated from the WHERE condition and moved into the HAVING condition of the view. In this case we have to build clones of the items for P1(v) and P3(v). 3. Building item clones In a general case building a clone for an item is quite a big task (E.g. when the item contains a subquery). 4. Using equalities We could write the first query in the following equivalent form: select * from v, t where t.a in (const1, const2) and t.a=v.a; The condition t.a in (const1, const2) can be pushed into the view if we take into account the conjunctive equality t.a=v.a. When searching for pushable condition we should take into account existing equality predicates. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Galina Shalygina (Inactive) [ 2016-06-24 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The state of the development by June 24 2016: ( see the development tree here https://github.com/shagalla/server/tree/10.2-mdev9197 ) 1. The build_clone method was implemented for simple exressions (items) Table t1:
Table t2:
View v1:
Queries: 1.
2.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Galina Shalygina (Inactive) [ 2016-09-09 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
What's I've done for final evaluation: -building item clones; -pushing conditions into HAVING; -pushing conditions into WHERE; -pushing conditions into embedded derived tables; The code is ready to be merged into MariaDB 10.2. Here is the list of commits on github: https://github.com/MariaDB/server/compare/10.2...shagalla:10.2-mdev9197 And here is the commit with the consolidated patch: https://github.com/MariaDB/server/compare/10.2...shagalla:10.2-mdev9197-cons | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Galina Shalygina (Inactive) [ 2016-09-09 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The consolidated patch was submitted as a contribution for MariaDB server on 08-23-2016. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2016-09-09 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The code for this task has been pushed into 10.2.2. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Igor Babaev [ 2016-09-26 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The feature was pushed into the 10.2 tree and will appear in the 10.2.2 release. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Krishnadas [ 2016-10-04 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
DBS test results MDEV-9197.zip |