Consider the following view:
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
the view could be merged into the referring select to produce
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.