yjhjstz commented on code in PR #1606:
URL: https://github.com/apache/cloudberry/pull/1606#discussion_r2906944770


##########
src/backend/optimizer/plan/aqumv.c:
##########
@@ -996,3 +996,348 @@ groupby_query_rewrite(PlannerInfo *subroot,
        subroot->append_rel_list = NIL;
        return true;
 }
+
+/*
+ * aqumv_query_is_exact_match
+ *
+ * Compare two Query trees for semantic identity.  Both should be at the
+ * same preprocessing stage (raw parser output).  Returns true only if
+ * they are structurally identical in all query-semantics fields.
+ */
+static bool
+aqumv_query_is_exact_match(Query *raw_parse, Query *viewQuery)
+{
+       /* Both must be CMD_SELECT */
+       if (raw_parse->commandType != CMD_SELECT ||
+               viewQuery->commandType != CMD_SELECT)
+               return false;
+
+       /* Same number of range table entries */
+       if (list_length(raw_parse->rtable) != list_length(viewQuery->rtable))
+               return false;
+
+       /* Compare range tables (table OIDs, join types, aliases structure) */
+       if (!equal(raw_parse->rtable, viewQuery->rtable))
+               return false;
+
+       /* Compare join tree (FROM clause + WHERE quals) */
+       if (!equal(raw_parse->jointree, viewQuery->jointree))
+               return false;
+
+       /* Compare target list entries: expressions and sort/group refs */
+       if (list_length(raw_parse->targetList) != 
list_length(viewQuery->targetList))
+               return false;
+       {
+               ListCell *lc1, *lc2;
+               forboth(lc1, raw_parse->targetList, lc2, viewQuery->targetList)
+               {
+                       TargetEntry *tle1 = lfirst_node(TargetEntry, lc1);
+                       TargetEntry *tle2 = lfirst_node(TargetEntry, lc2);
+                       if (!equal(tle1->expr, tle2->expr))
+                               return false;
+                       if (tle1->resjunk != tle2->resjunk)
+                               return false;
+                       if (tle1->ressortgroupref != tle2->ressortgroupref)
+                               return false;
+               }
+       }
+
+       /* Compare GROUP BY, HAVING, ORDER BY, DISTINCT, LIMIT */
+       if (!equal(raw_parse->groupClause, viewQuery->groupClause))

Review Comment:
   raw_parse->groupDistinct ?



-- 
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]

Reply via email to