my-ship-it commented on code in PR #1653:
URL: https://github.com/apache/cloudberry/pull/1653#discussion_r3019951573


##########
src/backend/optimizer/util/walkers.c:
##########
@@ -1011,3 +1017,102 @@ check_collation_walker(Node *node, 
check_collation_context *context)
        }
 }
 
+/*
+ * is_ordering_op
+ *
+ * Return true if the operator is registered as an ordering operator
+ * (amoppurpose = AMOP_ORDER) in any opfamily in pg_amop.
+ */
+static bool
+is_ordering_op(Oid opno)
+{
+       CatCList   *catlist = SearchSysCacheList1(AMOPOPID,
+                                                                               
          ObjectIdGetDatum(opno));
+
+       for (int i = 0; i < catlist->n_members; i++)
+       {
+               HeapTuple       tp = &catlist->members[i]->tuple;
+               Form_pg_amop amop = (Form_pg_amop) GETSTRUCT(tp);
+
+               if (amop->amoppurpose == AMOP_ORDER)
+               {
+                       ReleaseSysCacheList(catlist);
+                       return true;
+               }
+       }
+       ReleaseSysCacheList(catlist);
+       return false;
+}
+
+/*
+ * has_plain_var_arg
+ *
+ * Return true if the OpExpr has at least one direct Var argument
+ * (not wrapped in a function or other expression).
+ */
+static bool
+has_plain_var_arg(OpExpr *op)

Review Comment:
   The check requires a direct Var node. A RelabelType wrapping a Var (common 
with type coercions) would not match:
   
   -- If the column is int2 but the operator expects int4,
   -- the Var gets wrapped in RelabelType
   ORDER BY int2_col <-> 42



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