[MDEV-13622] Merging non-mergeable views into referring selects Created: 2017-08-22  Updated: 2023-04-11

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

Type: Task Priority: Major
Reporter: Igor Babaev Assignee: Igor Babaev
Resolution: Unresolved Votes: 2
Labels: None


 Description   

Consider the following view:

create view v1 as select a, sum(b) as s from t1 where a > 0 group by a;

This is a non-mergeable view, because it contains GROUP BY. In the current code this view is never merged. However it's obvious that if this view is used in the select

select * from v1 where a < 10 and s > 100

the view could be merged into the referring select to produce

select a, sum(b) from t1 where a > 0 and a < 10 group by a having sum(b) > 100

The select to which a non-mergeable view is merged must refer only to this view in its FROM list. GROUP BY and HAVING clauses, DISTINCT, aggregate functions, window functions cannot be used in this select at the top level.
Merge for the following non-mergeable views will be supported:

  • selects with GROUP BY
  • selects with DISTINCT
  • selects without GROUP BY with window functions (in this case the select to where to merge must refer only to partition fields in its WHERE condition)
  • unions of selects with only WHERE clauses or above mentioned selects.

Generated at Thu Feb 08 08:07:02 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.