Refactor query optimization using materialized view
See original GitHub issueRegarding the materialized view rewrite code logic, there are a few aspects can be improved as follows:
- As long as the optimization feature is on,
MaterializedViewCandidateExtractor
would always fetch referenced materialized views from metastore which is unnecessary. => Some validations on the query shape can be done beforehand. Say, if we know we cannot handle the query (e.g. has subqueries, contains unrecognized function calls), there is no need to talk to metastore. MaterializedViewQueryOptimizer
does both validation and rewriting at the same time. => An ideal solution would be separating the two steps.- In the validation step, materialized view information is extracted, then the query info is checked based on the materialized view info. => A better approach is to extract the query info so it can be reused to validate the the materialized views.
- The util class -
MaterializedViewOptimizationRewriteUtils
doesn’t add much value.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Flexviews - part 3 - improving query performance using ...
In my first post in this series, I described materialized views (MVs). ... The SQL features used in the query on which the...
Read more >7 Refreshing Materialized Views - Oracle Help Center
This chapter discusses how to refresh materialized views, which is a key element in maintaining good performance and consistent data when working with...
Read more >Speed up with Materialized Views on PostgreSQL and Rails
Vinoth Kumar shows you how to speed up your expensive SQL queries using materialized views with PostgreSQL and Rails.
Read more >How to use Materialized Views in Django | The PyCharm Blog
Repeatedly running queries that span multiple tables can be burdensome on your database. In this blog post, we're going to talk about ...
Read more >Lightning Fast SQL with Real Time Materialized Views - Medium
Materialized views (MVs) can give amazing performance boost. Once you create one based on your query, Oracle can get the results direct from...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Sullivan-Patrick Here is the paper address https://courses.cs.washington.edu/courses/cse591d/01sp/opt_views.pdf
Structure based rewriting is to extract the features in the query and use a set of rules for matching rewriting. The optimizer represents the query as SPJG standard form (join select project groupby), extracts the five expressions of join, projects, filters, grouping and aggregations in the query, and matches and rewrites the expressions corresponding to the materialized view. This method was systematically proposed by Microsoft in SIGMOD paper “optimizing queries using Materialized Views: a practical, scalable solution” in 2001. This method can rewrite any query method including join, filter and project, and use a series of steps to match and obtain the compensation expression. You can also further rewrite the query containing aggregation, and add an aggregation node to return further summarized results when necessary.Structure based rewriting is easy to expand, such as rewriting outer join and sub query, which can complete almost all rewriting. But the search cost is high, especially when the query is complex and the rewriting attempts are many.
@zhengxingmao Not sure exactly what you mean by structural-based rewrite, can you elaborate or link me to an article which defines this?
The rewrite code can be found inside
MaterializedViewQueryOptimizer
where we literally rewrite the SQL, as well asStatementAnalyzer
. Join definitions are found insideQuerySpecification.from
.I’m quite new to presto myself, but I’ve been working with the materialized view rewrite code for the last 10 weeks. Happy to jump into a voice call to answer anything you’re unclear on.