Hi,

The existing MaterializedViewRule is not applied when the materialized view
does not have a view predicate but the query contains a predicate. For eg
for the following materialized view

SELECT   eventid,  floor(ts to minute), count(*) as cnt
FROM     events
GROUP BY eventid, floor(ts TO minute)

If we have the following query the view is not chosen in the final plan.

SELECT   floor(ts to minute), count(*)
FROM     events
WHERE    ts >= timestamp'2018-01-01 00:01:00' AND ts < timestamp'2018-01-01
00:05:00'
GROUP BY eventid, floor(ts TO minute)

If I add the predicate "ts > timestamp'2018-01-01 00:01:00' AND ts <
timestamp'2018-01-01 00:05:00'" to the materialized view then the
materialized view is chosen in the final plan. Would it be possible to
modify the MaterializedViewRule to automatically add a view predicate based
on the query when the materialized view being considerent aggregates over a
column that contains a floor()? This predicate would also need to be
applied to the rewritten view. I would like to file a JIRA and work on this
improvement if this makes sense.

Thank you,
Thomas

Reply via email to