Uh oh!
There was an error while loading. Please reload this page.
[AQUMV] Directly compute queries from materialized views with GROUP BY. - #1143
Merged
Conversation
yjhjstz
reviewed
Jun 10, 2025
Uh oh!
There was an error while loading. Please reload this page.
yjhjstz
reviewed
Jun 10, 2025
Uh oh!
There was an error while loading. Please reload this page.
avamingliforce-pushed
the
dev0
branch
4 times, most recently
from
June 18, 2025 07:55
75d3b26 to
7e9b277Compareyjhjstz
reviewed
Jun 18, 2025
Uh oh!
There was an error while loading. Please reload this page.
yjhjstz
reviewed
Jun 18, 2025
Uh oh!
There was an error while loading. Please reload this page.
This commit enhances the AQUMV system by enabling it to compute queries directly from materialized views that already contain a GROUP BY clause. This improvement allows us to bypass additional GROUP BY operations during query execution, resulting in faster and more efficient performance. For example, with a materialized view defined as follows: ```sql CREATE MATERIALIZED VIEW mv_group_1 AS SELECT c, b, COUNT(b) AS count_b FROM t0 WHERE a > 3 GROUP BY c, b; ``` An original query like: ```sql SELECT COUNT(b), b, c FROM t0 WHERE a > 3 GROUP BY b, c; ``` is rewritten to: ```sql SELECT count_b, b, c FROM mv_group_1; ``` The plan looks like: ```sql explain(costs off, verbose) select count(b), b, c from t0 where a > 3 group by b, c; QUERY PLAN --------------------------------------------------------------- Gather Motion 3:1 (slice1; segments: 3) Output: count, b, c -> Seq Scan on aqumv.mv_group_1 Output: count, b, c Settings: enable_answer_query_using_materialized_views = 'on', optimizer = 'off' Optimizer: Postgres query optimizer (6 rows) ``` The two SQL queries yield equivalent results, even though the selected columns are in a different order. Since mv_group_1 already contains the aggregated results and all rows have a column a value greater than 3, there is no need for additional filtering or GROUP BY operations. This enhancement eliminates redundant computations, leading to significant time savings. Fetching results directly from these views reduces overall execution time, improving responsiveness for complex queries. This is particularly beneficial for large datasets, allowing efficient data analysis without performance degradation. The feature also applies to Dynamic Tables and Incremental Materialized Views. Authored-by: Zhang Mingli avamingli@gmail.com
yjhjstz
approved these changes
Jun 19, 2025
my-ship-it
approved these changes
Jun 19, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit enhances the AQUMV system by enabling it to compute queries directly from materialized views that already contain a GROUP BY clause. This improvement allows us to bypass additional GROUP BY operations during query execution, resulting in faster and more efficient performance.
For example, with a materialized view defined as follows:
An original query like:
is rewritten to:
The plan looks like:
The two SQL queries yield equivalent results, even though the selected columns are in a different order. Since mv_group_1 already contains the aggregated results and all rows have a column a value greater than 3, there is no need for additional filtering or GROUP BY operations.
This enhancement eliminates redundant computations, leading to significant time savings. Fetching results directly from these views reduces overall execution time, improving responsiveness for complex queries. This is particularly beneficial for large datasets, allowing efficient data analysis without performance degradation.
The feature also applies to Dynamic Tables and Incremental Materialized Views.
Authored-by: Zhang Mingli avamingli@gmail.com
Fixes #ISSUE_Number
What does this PR do?
Type of Change
Breaking Changes
Test Plan
make installcheckmake -C src/test installcheck-cbdb-parallelImpact
Performance:
User-facing changes:
Dependencies:
Checklist
Additional Context
CI Skip Instructions