[MDEV-13225] Lateral-like optimization for derived tables with GROUP BY Created: 2017-06-30 Updated: 2023-11-03 Resolved: 2023-11-03 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | N/A |
| Fix Version/s: | N/A |
| Type: | Task | Priority: | Major |
| Reporter: | Sergei Petrunia | Assignee: | Unassigned |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||
| Description |
|
(this is just a draft based on the preliminary discussions with igor). Consider a query
At the moment, the only way to execute this is to
This works poorly when the set of t1.col is such that it only covers a few of groups in t2. Possible solutions to this:
This MDEV is about the latter. The idea is as follows: ApplicabilityWhen we see a derived table that cannot be merged and has GROUP BY as its top-level operation (as opposed to, say, ORDER BY-LIMIT), we mark it as update_ref_and_keys()update_ref_and_keys also records equalities in form
We will call these Lateral-Parameter-Equalities. Note that "condition pushdown into derived table" can happen independently of this. Whatever can be pushed down, should be, we are not interested in those conditions here. Optimization of the subquerySimilar to "subquery materialization vs IN->EXISTS rewrite" choice, we will need to do query optimization for two variants: 1. Optimize for just computing the derived table (to do it once, that is). Let's call this "Lateral computation". Optimization of the upper query.Whenever best_access_path tries to add a Lateral-candidate table into the query plan, it should consider two options:
ExecutionIgor has mentioned that Recursive CTEs have a framework that allows derived tables to be re-filled on each execution (or at least, not once-per-query). |
| Comments |
| Comment by Sergei Petrunia [ 2023-11-03 ] |
|
Closing as Duplicate of |