Changeset: 6cfed0167e2e for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6cfed0167e2e
Modified Files:
        gdk/gdk_batop.c
Branch: Feb2013
Log Message:

Added another shortcut in BATsubsort.
If the input is already sorted and we need to return group
information, we can take a shortcut if the input is also key or
constant.
This should fix bug 3368.


diffs (46 lines):

diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -1297,8 +1297,12 @@ BATsubsort(BAT **sorted, BAT **order, BA
                /* no place to put result, so we're done quickly */
                return GDK_SUCCEED;
        }
-       if (BATcount(b) <= 1 || (BATtordered(b) && o == NULL && g == NULL && 
groups == NULL)) {
-               /* trivially (sub)sorted */
+       if (BATcount(b) <= 1 ||
+           (BATtordered(b) && o == NULL && g == NULL &&
+            (groups == NULL || BATtkey(b) || BATtrevordered(b)))) {
+               /* trivially (sub)sorted, and either we don't need to
+                * return group information, or we can trivially
+                * deduce the groups */
                if (sorted) {
                        BBPfix(b->batCacheid);
                        bn = b;
@@ -1314,12 +1318,22 @@ BATsubsort(BAT **sorted, BAT **order, BA
                        *order = on;
                }
                if (groups) {
-                       gn = BATnew(TYPE_void, TYPE_void, BATcount(b));
-                       if (gn == NULL)
-                               goto error;
-                       BATsetcount(gn, BATcount(b));
+                       if (BATtkey(b)) {
+                               /* singleton groups */
+                               gn = BATnew(TYPE_void, TYPE_void, BATcount(b));
+                               if (gn == NULL)
+                                       goto error;
+                               BATsetcount(gn, BATcount(b));
+                               BATseqbase(BATmirror(gn), 0);
+                       } else {
+                               /* single group */
+                               const oid *o = 0;
+                               assert(BATcount(b) == 1 || BATtrevordered(b));
+                               gn = BATconstant(TYPE_oid, &o, BATcount(b));
+                               if (gn == NULL)
+                                       goto error;
+                       }
                        BATseqbase(gn, 0);
-                       BATseqbase(BATmirror(gn), 0);
                        *groups = gn;
                }
                return GDK_SUCCEED;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to