[MDEV-22417] "pushdown" of MIN/MAX inside UNION with WHERE and GROUP BY Created: 2020-04-05  Updated: 2023-12-12

Status: Open
Project: MariaDB Server
Component/s: Optimizer
Fix Version/s: 11.5

Type: New Feature Priority: Major
Reporter: Oleksandr Byelkin Assignee: Sergei Petrunia
Resolution: Unresolved Votes: 1
Labels: optimizer

Issue Links:
Relates
relates to MDEV-22416 "pushdown" of MIN/MAX inside UNION Open

 Description   

Even if we will not have MIN/MAX optimisation (as in MENT-693) we can get gail from early filtering by MIN/MAX pushdown.

Transformation:

SELECT MAX(field) FROM
   (SELECT field1 as field, field3 as group_field FROM table1
    UNION
    SELECT field2, firld4  FROM table2)
  WHERE cond(field,group_field) and other_cond()
  GROUP by group_field

to

SELECT MAX(field) FROM
   (SELECT MAX(field1) as field, field3 as group_field FROM table1 WHERE cond(field1,filed3) GROUP BY group_field
    UNION
    SELECT MAX(field2), firld4  FROM table2 WHERE  cond(field2,filed4) GROUP BY field4)
  WHERE cond(field) and othercond()
  GROUP by group_field

The idea of this task is to lift WHERE/GROUP BY limitations of MENT-693.

We can clone WHERE condition portion which depend on field under MAX/MIN and GROUP BY (if possible to clone and to separate this portion from other condition (could be side effect, random, outer references mixed with the fields)), clone GROUP BY list (also if possible), in both (WHERE & GROUP BY) change fields of UNION result by references (direct reference?) on SELECT LIST of each underlying SELECT. Cloned WHERE will be add (AND) to the WHERE of each underlying SELECT and GROUP BY just add to each such SELECT (the select should not have own GROUP BY).



 Comments   
Comment by Julien Fritsch [ 2020-04-06 ]

sanja since the fixversion is missing, I've added N/A to ensure this get listed into the dev or maintenance list, but please adjust it later.

Generated at Thu Feb 08 09:14:35 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.