Changeset: b373303ee299 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b373303ee299
Modified Files:
        clients/Tests/MAL-signatures_all.stable.out
        clients/Tests/MAL-signatures_fits_geom.stable.out
        clients/Tests/MAL-signatures_geom.stable.out
        clients/Tests/MAL-signatures_none.stable.out
        clients/Tests/exports.stable.out
        gdk/gdk.h
        gdk/gdk_firstn.c
        monetdb5/modules/kernel/algebra.c
        monetdb5/modules/kernel/algebra.mal
        monetdb5/modules/mal/Tests/pqueue.mal
        monetdb5/modules/mal/Tests/pqueue.stable.out
        monetdb5/modules/mal/Tests/pqueue2.mal
        monetdb5/modules/mal/Tests/pqueue2.stable.out
        monetdb5/modules/mal/Tests/pqueue3.mal
        monetdb5/modules/mal/Tests/pqueue3.stable.out
        monetdb5/tests/gdkTests/Tests/firstn.mal
        sql/backends/monet5/sql_gencode.c
        sql/benchmarks/tpch/Tests/02-explain.stable.out
        sql/benchmarks/tpch/Tests/03-explain.stable.out
        sql/benchmarks/tpch/Tests/10-explain.stable.out
        sql/benchmarks/tpch/Tests/18-explain.stable.out
        sql/benchmarks/tpch/Tests/21-explain.stable.out
        
sql/test/BugTracker-2010/Tests/LIMIT_OFFSET_big-endian.Bug-2622.stable.out
Branch: Oct2014
Log Message:

Fix SELECT DISTINCT with ORDER BY and LIMIT.
This fixes bug 3527, but only for the next feature release.
Niels, there is still an issue in sql_gencode.c.  See the TODO comment.


diffs (truncated from 1550 to 300 lines):

diff --git a/clients/Tests/MAL-signatures_all.stable.out 
b/clients/Tests/MAL-signatures_all.stable.out
--- a/clients/Tests/MAL-signatures_all.stable.out
+++ b/clients/Tests/MAL-signatures_all.stable.out
@@ -2422,27 +2422,27 @@ command algebra.exist(b:bat[:oid,:any_1]
 address ALGexist;
 comment Returns whether 'val' occurs in b.
 
-pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],g:bat[:oid,:oid],n:wrd,asc:bit)
 (X_6:bat[:oid,:oid],X_7:bat[:oid,:oid]) 
+pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],g:bat[:oid,:oid],n:wrd,asc:bit,distinct:bit)
 (X_7:bat[:oid,:oid],X_8:bat[:oid,:oid]) 
 address ALGfirstn;
 comment Calculate first N values of B with candidate list S
 
-pattern algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],n:wrd,asc:bit) 
(X_5:bat[:oid,:oid],X_6:bat[:oid,:oid]) 
+pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],n:wrd,asc:bit,distinct:bit) 
(X_6:bat[:oid,:oid],X_7:bat[:oid,:oid]) 
 address ALGfirstn;
 comment Calculate first N values of B with candidate list S
 
-pattern algebra.firstn(b:bat[:oid,:any],n:wrd,asc:bit) 
(X_4:bat[:oid,:oid],X_5:bat[:oid,:oid]) 
+pattern algebra.firstn(b:bat[:oid,:any],n:wrd,asc:bit,distinct:bit) 
(X_5:bat[:oid,:oid],X_6:bat[:oid,:oid]) 
 address ALGfirstn;
 comment Calculate first N values of B
 
-pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],g:bat[:oid,:oid],n:wrd,asc:bit):bat[:oid,:oid]
 
+pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],g:bat[:oid,:oid],n:wrd,asc:bit,distinct:bit):bat[:oid,:oid]
 
 address ALGfirstn;
 comment Calculate first N values of B with candidate list S
 
-pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],n:wrd,asc:bit):bat[:oid,:oid] 
+pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],n:wrd,asc:bit,distinct:bit):bat[:oid,:oid]
 
 address ALGfirstn;
 comment Calculate first N values of B with candidate list S
 
-pattern algebra.firstn(b:bat[:oid,:any],n:wrd,asc:bit):bat[:oid,:oid] 
+pattern 
algebra.firstn(b:bat[:oid,:any],n:wrd,asc:bit,distinct:bit):bat[:oid,:oid] 
 address ALGfirstn;
 comment Calculate first N values of B
 
diff --git a/clients/Tests/MAL-signatures_fits_geom.stable.out 
b/clients/Tests/MAL-signatures_fits_geom.stable.out
--- a/clients/Tests/MAL-signatures_fits_geom.stable.out
+++ b/clients/Tests/MAL-signatures_fits_geom.stable.out
@@ -2422,27 +2422,27 @@ command algebra.exist(b:bat[:oid,:any_1]
 address ALGexist;
 comment Returns whether 'val' occurs in b.
 
-pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],g:bat[:oid,:oid],n:wrd,asc:bit)
 (X_6:bat[:oid,:oid],X_7:bat[:oid,:oid]) 
+pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],g:bat[:oid,:oid],n:wrd,asc:bit,distinct:bit)
 (X_7:bat[:oid,:oid],X_8:bat[:oid,:oid]) 
 address ALGfirstn;
 comment Calculate first N values of B with candidate list S
 
-pattern algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],n:wrd,asc:bit) 
(X_5:bat[:oid,:oid],X_6:bat[:oid,:oid]) 
+pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],n:wrd,asc:bit,distinct:bit) 
(X_6:bat[:oid,:oid],X_7:bat[:oid,:oid]) 
 address ALGfirstn;
 comment Calculate first N values of B with candidate list S
 
-pattern algebra.firstn(b:bat[:oid,:any],n:wrd,asc:bit) 
(X_4:bat[:oid,:oid],X_5:bat[:oid,:oid]) 
+pattern algebra.firstn(b:bat[:oid,:any],n:wrd,asc:bit,distinct:bit) 
(X_5:bat[:oid,:oid],X_6:bat[:oid,:oid]) 
 address ALGfirstn;
 comment Calculate first N values of B
 
-pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],g:bat[:oid,:oid],n:wrd,asc:bit):bat[:oid,:oid]
 
+pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],g:bat[:oid,:oid],n:wrd,asc:bit,distinct:bit):bat[:oid,:oid]
 
 address ALGfirstn;
 comment Calculate first N values of B with candidate list S
 
-pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],n:wrd,asc:bit):bat[:oid,:oid] 
+pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],n:wrd,asc:bit,distinct:bit):bat[:oid,:oid]
 
 address ALGfirstn;
 comment Calculate first N values of B with candidate list S
 
-pattern algebra.firstn(b:bat[:oid,:any],n:wrd,asc:bit):bat[:oid,:oid] 
+pattern 
algebra.firstn(b:bat[:oid,:any],n:wrd,asc:bit,distinct:bit):bat[:oid,:oid] 
 address ALGfirstn;
 comment Calculate first N values of B
 
diff --git a/clients/Tests/MAL-signatures_geom.stable.out 
b/clients/Tests/MAL-signatures_geom.stable.out
--- a/clients/Tests/MAL-signatures_geom.stable.out
+++ b/clients/Tests/MAL-signatures_geom.stable.out
@@ -2422,27 +2422,27 @@ command algebra.exist(b:bat[:oid,:any_1]
 address ALGexist;
 comment Returns whether 'val' occurs in b.
 
-pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],g:bat[:oid,:oid],n:wrd,asc:bit)
 (X_6:bat[:oid,:oid],X_7:bat[:oid,:oid]) 
+pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],g:bat[:oid,:oid],n:wrd,asc:bit,distinct:bit)
 (X_7:bat[:oid,:oid],X_8:bat[:oid,:oid]) 
 address ALGfirstn;
 comment Calculate first N values of B with candidate list S
 
-pattern algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],n:wrd,asc:bit) 
(X_5:bat[:oid,:oid],X_6:bat[:oid,:oid]) 
+pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],n:wrd,asc:bit,distinct:bit) 
(X_6:bat[:oid,:oid],X_7:bat[:oid,:oid]) 
 address ALGfirstn;
 comment Calculate first N values of B with candidate list S
 
-pattern algebra.firstn(b:bat[:oid,:any],n:wrd,asc:bit) 
(X_4:bat[:oid,:oid],X_5:bat[:oid,:oid]) 
+pattern algebra.firstn(b:bat[:oid,:any],n:wrd,asc:bit,distinct:bit) 
(X_5:bat[:oid,:oid],X_6:bat[:oid,:oid]) 
 address ALGfirstn;
 comment Calculate first N values of B
 
-pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],g:bat[:oid,:oid],n:wrd,asc:bit):bat[:oid,:oid]
 
+pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],g:bat[:oid,:oid],n:wrd,asc:bit,distinct:bit):bat[:oid,:oid]
 
 address ALGfirstn;
 comment Calculate first N values of B with candidate list S
 
-pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],n:wrd,asc:bit):bat[:oid,:oid] 
+pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],n:wrd,asc:bit,distinct:bit):bat[:oid,:oid]
 
 address ALGfirstn;
 comment Calculate first N values of B with candidate list S
 
-pattern algebra.firstn(b:bat[:oid,:any],n:wrd,asc:bit):bat[:oid,:oid] 
+pattern 
algebra.firstn(b:bat[:oid,:any],n:wrd,asc:bit,distinct:bit):bat[:oid,:oid] 
 address ALGfirstn;
 comment Calculate first N values of B
 
diff --git a/clients/Tests/MAL-signatures_none.stable.out 
b/clients/Tests/MAL-signatures_none.stable.out
--- a/clients/Tests/MAL-signatures_none.stable.out
+++ b/clients/Tests/MAL-signatures_none.stable.out
@@ -2421,27 +2421,27 @@ command algebra.exist(b:bat[:oid,:any_1]
 address ALGexist;
 comment Returns whether 'val' occurs in b.
 
-pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],g:bat[:oid,:oid],n:wrd,asc:bit)
 (X_6:bat[:oid,:oid],X_7:bat[:oid,:oid]) 
+pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],g:bat[:oid,:oid],n:wrd,asc:bit,distinct:bit)
 (X_7:bat[:oid,:oid],X_8:bat[:oid,:oid]) 
 address ALGfirstn;
 comment Calculate first N values of B with candidate list S
 
-pattern algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],n:wrd,asc:bit) 
(X_5:bat[:oid,:oid],X_6:bat[:oid,:oid]) 
+pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],n:wrd,asc:bit,distinct:bit) 
(X_6:bat[:oid,:oid],X_7:bat[:oid,:oid]) 
 address ALGfirstn;
 comment Calculate first N values of B with candidate list S
 
-pattern algebra.firstn(b:bat[:oid,:any],n:wrd,asc:bit) 
(X_4:bat[:oid,:oid],X_5:bat[:oid,:oid]) 
+pattern algebra.firstn(b:bat[:oid,:any],n:wrd,asc:bit,distinct:bit) 
(X_5:bat[:oid,:oid],X_6:bat[:oid,:oid]) 
 address ALGfirstn;
 comment Calculate first N values of B
 
-pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],g:bat[:oid,:oid],n:wrd,asc:bit):bat[:oid,:oid]
 
+pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],g:bat[:oid,:oid],n:wrd,asc:bit,distinct:bit):bat[:oid,:oid]
 
 address ALGfirstn;
 comment Calculate first N values of B with candidate list S
 
-pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],n:wrd,asc:bit):bat[:oid,:oid] 
+pattern 
algebra.firstn(b:bat[:oid,:any],s:bat[:oid,:oid],n:wrd,asc:bit,distinct:bit):bat[:oid,:oid]
 
 address ALGfirstn;
 comment Calculate first N values of B with candidate list S
 
-pattern algebra.firstn(b:bat[:oid,:any],n:wrd,asc:bit):bat[:oid,:oid] 
+pattern 
algebra.firstn(b:bat[:oid,:any],n:wrd,asc:bit,distinct:bit):bat[:oid,:oid] 
 address ALGfirstn;
 comment Calculate first N values of B
 
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -116,7 +116,7 @@ void BATderiveHeadProps(BAT *b, int expe
 void BATderiveProps(BAT *b, int expensive);
 BAT *BATextend(BAT *b, BUN newcap);
 BAT *BATfakeCommit(BAT *b);
-gdk_return BATfirstn(BAT **topn, BAT **gids, BAT *b, BAT *cands, BAT *grps, 
BUN n, int asc);
+gdk_return BATfirstn(BAT **topn, BAT **gids, BAT *b, BAT *cands, BAT *grps, 
BUN n, int asc, int distinct);
 int BATgetaccess(BAT *b);
 PROPrec *BATgetprop(BAT *b, int idx);
 gdk_return BATgroup(BAT **groups, BAT **extents, BAT **histo, BAT *b, BAT *g, 
BAT *e, BAT *h);
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -3352,7 +3352,7 @@ gdk_export BAT *BATkdiff(BAT *b, BAT *c)
 gdk_export BAT *BATmergecand(BAT *a, BAT *b);
 gdk_export BAT *BATintersectcand(BAT *a, BAT *b);
 
-gdk_export gdk_return BATfirstn(BAT **topn, BAT **gids, BAT *b, BAT *cands, 
BAT *grps, BUN n, int asc);
+gdk_export gdk_return BATfirstn(BAT **topn, BAT **gids, BAT *b, BAT *cands, 
BAT *grps, BUN n, int asc, int distinct);
 
 #include "gdk_calc.h"
 
diff --git a/gdk/gdk_firstn.c b/gdk/gdk_firstn.c
--- a/gdk/gdk_firstn.c
+++ b/gdk/gdk_firstn.c
@@ -46,9 +46,9 @@
  *
  * Note that BATfirstn can be called in cascading fashion to calculate
  * the first n values of a table of multiple columns:
- *      BATfirstn(&s1, &g1, b1, NULL, NULL, n, asc);
- *      BATfirstn(&s2, &g2, b2, s1, g1, n, asc);
- *      BATfirstn(&s3, NULL, b3, s2, g2, n, asc);
+ *      BATfirstn(&s1, &g1, b1, NULL, NULL, n, asc, distinct);
+ *      BATfirstn(&s2, &g2, b2, s1, g1, n, asc, distinct);
+ *      BATfirstn(&s3, NULL, b3, s2, g2, n, asc, distinct);
  * If the input BATs b1, b2, b3 are large enough, s3 will contain the
  * OIDs of the smallest (largest) n elements in the table consisting
  * of the columns b1, b2, b3 when ordered in ascending order with b1
@@ -435,7 +435,7 @@ BATfirstn_unique_with_groups(BAT *b, BAT
        } while (0)
 
 static gdk_return
-BATfirstn_grouped(BAT **topn, BAT **gids, BAT *b, BAT *s, BUN n, int asc)
+BATfirstn_grouped(BAT **topn, BAT **gids, BAT *b, BAT *s, BUN n, int asc, int 
distinct)
 {
        BAT *bn, *gn;
        BATiter bi = bat_iterator(b);
@@ -446,7 +446,6 @@ BATfirstn_grouped(BAT **topn, BAT **gids
        int c;
        int (*cmp)(const void *, const void *);
        BUN ncnt;
-       int distinct = 0;
        struct group {
                BUN bun;
                BUN cnt;
@@ -695,7 +694,7 @@ BATfirstn_grouped(BAT **topn, BAT **gids
        } while (0)
 
 static gdk_return
-BATfirstn_grouped_with_groups(BAT **topn, BAT **gids, BAT *b, BAT *s, BAT *g, 
BUN n, int asc)
+BATfirstn_grouped_with_groups(BAT **topn, BAT **gids, BAT *b, BAT *s, BAT *g, 
BUN n, int asc, int distinct)
 {
        BAT *bn, *gn;
        BATiter bi = bat_iterator(b);
@@ -706,7 +705,6 @@ BATfirstn_grouped_with_groups(BAT **topn
        int c;
        int (*cmp)(const void *, const void *);
        BUN ncnt;
-       int distinct = 0;
        struct group {
                BUN bun;
                BUN cnt;
@@ -909,7 +907,7 @@ BATfirstn_grouped_with_groups(BAT **topn
 }
 
 gdk_return
-BATfirstn(BAT **topn, BAT **gids, BAT *b, BAT *s, BAT *g, BUN n, int asc)
+BATfirstn(BAT **topn, BAT **gids, BAT *b, BAT *s, BAT *g, BUN n, int asc, int 
distinct)
 {
        assert(topn != NULL);
        if (b == NULL) {
@@ -951,11 +949,11 @@ BATfirstn(BAT **topn, BAT **gids, BAT *b
                        *topn = BATfirstn_unique(b, s, n, asc);
                        return *topn ? GDK_SUCCEED : GDK_FAIL;
                }
-               return BATfirstn_grouped(topn, gids, b, s, n, asc);
+               return BATfirstn_grouped(topn, gids, b, s, n, asc, distinct);
        }
        if (gids == NULL) {
                *topn = BATfirstn_unique_with_groups(b, s, g, n, asc);
                return *topn ? GDK_SUCCEED : GDK_FAIL;
        }
-       return BATfirstn_grouped_with_groups(topn, gids, b, s, g, n, asc);
+       return BATfirstn_grouped_with_groups(topn, gids, b, s, g, n, asc, 
distinct);
 }
diff --git a/monetdb5/modules/kernel/algebra.c 
b/monetdb5/modules/kernel/algebra.c
--- a/monetdb5/modules/kernel/algebra.c
+++ b/monetdb5/modules/kernel/algebra.c
@@ -935,7 +935,8 @@ ALGsubthetajoin(bat *r1, bat *r2, bat *l
  *                [ s:bat[:oid,:oid],
  *                [ g:bat[:oid,:oid], ] ]
  *                n:wrd,
- *                asc:bit)
+ *                asc:bit,
+ *                distinct:bit)
  * returns :bat[:oid,:oid] [ , :bat[:oid,:oid] ]
  */
 str
@@ -946,16 +947,16 @@ ALGfirstn(Client cntxt, MalBlkPtr mb, Ma
        BAT *b, *s = NULL, *g = NULL;
        BAT *bn, *gn;
        wrd n;
-       bit asc;
+       bit asc, distinct;
        gdk_return rc;
 
        (void) cntxt;
        (void) mb;
 
        assert(pci->retc == 1 || pci->retc == 2);
-       assert(pci->argc - pci->retc >= 3 && pci->argc - pci->retc <= 5);
+       assert(pci->argc - pci->retc >= 4 && pci->argc - pci->retc <= 6);
 
-       n = * (wrd *) getArgReference(stk, pci, pci->argc - 2);
+       n = * (wrd *) getArgReference(stk, pci, pci->argc - 3);
        if (n < 0 || (lng) n >= (lng) BUN_MAX)
                throw(MAL, "algebra.firstn", ILLEGAL_ARGUMENT);
        ret1 = getArgReference(stk, pci, 0);
@@ -964,13 +965,13 @@ ALGfirstn(Client cntxt, MalBlkPtr mb, Ma
        bid = * (bat *) getArgReference(stk, pci, pci->retc);
        if ((b = BATdescriptor(bid)) == NULL)
                throw(MAL, "algebra.firstn", RUNTIME_OBJECT_MISSING);
-       if (pci->argc - pci->retc > 3) {
+       if (pci->argc - pci->retc > 4) {
                sid = * (bat *) getArgReference(stk, pci, pci->retc + 1);
                if ((s = BATdescriptor(sid)) == NULL) {
                        BBPreleaseref(bid);
                        throw(MAL, "algebra.firstn", RUNTIME_OBJECT_MISSING);
                }
-               if (pci->argc - pci->retc > 4) {
+               if (pci->argc - pci->retc > 5) {
                        gid = * (bat *) getArgReference(stk, pci, pci->retc + 
2);
                        if ((g = BATdescriptor(gid)) == NULL) {
                                BBPreleaseref(bid);
@@ -979,8 +980,9 @@ ALGfirstn(Client cntxt, MalBlkPtr mb, Ma
                        }
                }
        }
-       asc = * (bit *) getArgReference(stk, pci, pci->argc - 1);
-       rc = BATfirstn(&bn, ret2 ? &gn : NULL, b, s, g, (BUN) n, asc);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to