Fix get_sort_group_operators() so that it doesn't think arrays can be grouped
authorTom Lane <[email protected]>
Sat, 13 Jun 2009 15:42:09 +0000 (15:42 +0000)
committerTom Lane <[email protected]>
Sat, 13 Jun 2009 15:42:09 +0000 (15:42 +0000)
via hashing.  Eventually we ought to make that possible, but it won't happen
for 8.4.  Per yesterday's report from Robert Haas.

src/backend/parser/parse_oper.c

index 38fe306162283c417aafce3197ddc151e929248b..3d3013ae1a502478d565ebadac1414e9822419ae 100644 (file)
@@ -203,7 +203,7 @@ get_sort_group_operators(Oid argtype,
         * If the datatype is an array, then we can use array_lt and friends ...
         * but only if there are suitable operators for the element type.  (This
         * check is not in the raw typcache.c code ... should it be?)  Testing all
-        * three operator IDs here should be redundant.
+        * three operator IDs here should be redundant, but let's do it anyway.
         */
        if (lt_opr == ARRAY_LT_OP ||
                eq_opr == ARRAY_EQ_OP ||
@@ -215,12 +215,31 @@ get_sort_group_operators(Oid argtype,
                {
                        typentry = lookup_type_cache(elem_type,
                                         TYPECACHE_LT_OPR | TYPECACHE_EQ_OPR | TYPECACHE_GT_OPR);
-                       if (!OidIsValid(typentry->lt_opr))
-                               lt_opr = InvalidOid;    /* element type has no "<" */
+#ifdef NOT_USED
+                       /* We should do this ... */
                        if (!OidIsValid(typentry->eq_opr))
-                               eq_opr = InvalidOid;    /* element type has no "=" */
-                       if (!OidIsValid(typentry->gt_opr))
-                               gt_opr = InvalidOid;    /* element type has no ">" */
+                       {
+                               /* element type is neither sortable nor hashable */
+                               lt_opr = eq_opr = gt_opr = InvalidOid;
+                       }
+                       else if (!OidIsValid(typentry->lt_opr) ||
+                                        !OidIsValid(typentry->gt_opr))
+                       {
+                               /* element type is hashable but not sortable */
+                               lt_opr = gt_opr = InvalidOid;
+                       }
+#else
+                       /*
+                        * ... but for the moment we have to do this.  This is because
+                        * anyarray has sorting but not hashing support.  So, if the
+                        * element type is only hashable, there is nothing we can do
+                        * with the array type.
+                        */
+                       if (!OidIsValid(typentry->lt_opr) ||
+                               !OidIsValid(typentry->eq_opr) ||
+                               !OidIsValid(typentry->gt_opr))
+                               lt_opr = eq_opr = gt_opr = InvalidOid;  /* not sortable */
+#endif
                }
                else
                        lt_opr = eq_opr = gt_opr = InvalidOid;          /* bogus array type? */