avamingli commented on code in PR #705:
URL: https://github.com/apache/cloudberry/pull/705#discussion_r1867383610
##########
src/backend/optimizer/plan/aqumv.c:
##########
@@ -293,69 +325,195 @@ answer_query_using_materialized_views(PlannerInfo *root,
context = aqumv_init_context(viewQuery->targetList,
matviewRel->rd_att);
- /*
- * Process and rewrite target list, return false if failed.
- */
- if(!aqumv_process_targetlist(context, parse->targetList,
&mv_final_tlist))
+ if (!parse->hasAggs && viewQuery->hasAggs)
continue;
- viewQuery->targetList = mv_final_tlist;
+ if (parse->hasAggs && viewQuery->hasAggs)
+ {
+ if (parse->hasDistinctOn ||
+ parse->distinctClause != NIL ||
+ parse->groupClause != NIL ||
+ parse->groupingSets != NIL ||
+ parse->groupDistinct)
+ continue;
+
+ /* No Group by now. */
+ if (viewQuery->hasDistinctOn ||
+ viewQuery->distinctClause != NIL ||
+ viewQuery->groupClause != NIL ||
+ viewQuery->groupingSets != NIL ||
+ viewQuery->groupDistinct ||
+ viewQuery->havingQual != NULL || /* HAVING
clause is not supported on IMMV yet. */
+ limit_needed(viewQuery)) /* LIMIT, OFFSET is
not supported on IMMV yet. */
+ continue;
- /*
- * NB: Update processed_tlist again in case that tlist has been
changed.
- */
- preprocess_targetlist(subroot);
+ /*
+ * There is a trick for ORDER BY for both origin query
and view query.
+ * As we has no Groupy By here, 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.
+ * This in-place update raw_processed_tlist.
+ */
Review Comment:
Make sense, this PR comes earlier than #685 .
Will pick this up after that one is merged, thanks~
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]