[AQUMV] Answer Aggregation Query Directly. #705
+822
−78
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 commits enable answer query which has aggregation directly. Use the results of view has aggregations to avoid compute those from origin table.
This may lead to significant efficiency gains if the SQL has a large amount of data.
AQUMV will always return results immediately.
If we have a valid view like:
SQL:
Could be rewritten to:
Plan:
View query with Group By is not supported yet.
HAVING clause process:
If some HAVING quals only exist in origin query and they could be computed from view query's target list, then we could keep them like post_quals.But as the view has aggregations, the additional quals should be moved to WHERE instead of HAVING.
SQL:
Could be rewritten to (The HAVING clause has been rewritten to WHERE clause):
Plan:
There are two additional HAVING quals:
Expression: 2 > 1 (would be eliminated during planner). Expression: abs(count(*) - 21) > 0, it could be computed from view as:
And the new one is put to WHERE clause and acts as a Filter finally.
ORDER BY clause:
There is a trick for ORDER BY for both origin query and view query. As we has no Groupy By curretly, the aggregation results would be either one or zero rows that make the Order By clause pointless.
We could avoid considering the sort columns if it's a junk for view matching.
LIMIT clause:
As we have no group by for view with aggs now, the final result would be either one or zero row.
LIMIT, OFFSET clause of origin query could be applied to view if there are consts.
Query:
Could be rewritten to:
Authored-by: Zhang Mingli [email protected]
fix #ISSUE_Number
Change logs
Describe your change clearly, including what problem is being solved or what feature is being added.
If it has some breaking backward or forward compatibility, please clary.
Why are the changes needed?
Describe why the changes are necessary.
Does this PR introduce any user-facing change?
If yes, please clarify the previous behavior and the change this PR proposes.
How was this patch tested?
Please detail how the changes were tested, including manual tests and any relevant unit or integration tests.
Contributor's Checklist
Here are some reminders and checklists before/when submitting your pull request, please check them:
make installcheck
make -C src/test installcheck-cbdb-parallel
cloudberrydb/dev
team for review and approval when your PR is ready🥳