Changeset: 007632271b61 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=007632271b61
Modified Files:
        gdk/gdk_firstn.c
Branch: Oct2014
Log Message:

Fixed SELECT DISTINCT with ORDER BY and LIMIT again.
After changeset 4592f95b53ff, BATfirstn was called with distinct set,
but only a single return BAT.  We now cater for this situation as well.


diffs (106 lines):

diff --git a/gdk/gdk_firstn.c b/gdk/gdk_firstn.c
--- a/gdk/gdk_firstn.c
+++ b/gdk/gdk_firstn.c
@@ -452,7 +452,6 @@ BATfirstn_grouped(BAT **topn, BAT **gids
        } *groups;
 
        assert(topn);
-       assert(gids);
 
        CANDINIT(b, s, start, end, cnt, cand, candend);
 
@@ -616,15 +615,18 @@ BATfirstn_grouped(BAT **topn, BAT **gids
                bn->T->nil = 0;
                bn->T->nonil = 1;
        }
-       BATsetcount(gn, ncnt);
-       BATseqbase(gn, 0);
-       gn->tkey = ncnt == top;
-       gn->tsorted = ncnt <= 1;
-       gn->trevsorted = ncnt <= 1;
-       gn->T->nil = 0;
-       gn->T->nonil = 1;
+       if (gids) {
+               BATsetcount(gn, ncnt);
+               BATseqbase(gn, 0);
+               gn->tkey = ncnt == top;
+               gn->tsorted = ncnt <= 1;
+               gn->trevsorted = ncnt <= 1;
+               gn->T->nil = 0;
+               gn->T->nonil = 1;
+               *gids = gn;
+       } else
+               BBPreclaim(gn);
        *topn = bn;
-       *gids = gn;
        return GDK_SUCCEED;
 }
 
@@ -712,20 +714,20 @@ BATfirstn_grouped_with_groups(BAT **topn
        } *groups;
 
        assert(topn);
-       assert(gids);
 
        if (BATtdense(g)) {
                /* trivial: g determines ordering, return initial
                 * slice of s */
                bn = BATslice(s, 0, n);
-               gn = BATslice(g, 0, n);
-               if (bn == NULL || gn == NULL) {
+               gn = gids ? BATslice(g, 0, n) : NULL;
+               if (bn == NULL || (gids != NULL && gn == NULL)) {
                        BBPreclaim(bn);
                        BBPreclaim(gn);
                        return GDK_FAIL;
                }
                *topn = bn;
-               *gids = gn;
+               if (gids)
+                       *gids = gn;
                return GDK_SUCCEED;
        }
 
@@ -894,15 +896,18 @@ BATfirstn_grouped_with_groups(BAT **topn
                bn->T->nil = 0;
                bn->T->nonil = 1;
        }
-       BATsetcount(gn, ncnt);
-       BATseqbase(gn, 0);
-       gn->tkey = ncnt == top;
-       gn->tsorted = ncnt <= 1;
-       gn->trevsorted = ncnt <= 1;
-       gn->T->nil = 0;
-       gn->T->nonil = 1;
+       if (gids) {
+               BATsetcount(gn, ncnt);
+               BATseqbase(gn, 0);
+               gn->tkey = ncnt == top;
+               gn->tsorted = ncnt <= 1;
+               gn->trevsorted = ncnt <= 1;
+               gn->T->nil = 0;
+               gn->T->nonil = 1;
+               *gids = gn;
+       } else
+               BBPreclaim(gn);
        *topn = bn;
-       *gids = gn;
        return GDK_SUCCEED;
 }
 
@@ -945,13 +950,13 @@ BATfirstn(BAT **topn, BAT **gids, BAT *b
        }
 
        if (g == NULL) {
-               if (gids == NULL) {
+               if (gids == NULL && !distinct) {
                        *topn = BATfirstn_unique(b, s, n, asc);
                        return *topn ? GDK_SUCCEED : GDK_FAIL;
                }
                return BATfirstn_grouped(topn, gids, b, s, n, asc, distinct);
        }
-       if (gids == NULL) {
+       if (gids == NULL && !distinct) {
                *topn = BATfirstn_unique_with_groups(b, s, g, n, asc);
                return *topn ? GDK_SUCCEED : GDK_FAIL;
        }
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to