Changeset: da283514d9b4 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/da283514d9b4
Modified Files:
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql_statement.c
sql/backends/monet5/sql_statement.h
Branch: ordered-set-aggregates
Log Message:
cleanup code abit
diffs (168 lines):
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -3022,7 +3022,7 @@ rel2bin_groupjoin(backend *be, sql_rel *
stmt *l = bin_find_smallest_column(be, left);
stmt *r = bin_find_smallest_column(be, right);
if (list_empty(jexps)) {
- stmt *limit = stmt_limit(be, r, NULL, NULL,
stmt_atom_lng(be, 0), stmt_atom_lng(be, 1), 0, 0, 0, 0, 0);
+ stmt *limit = stmt_limit(be, r, NULL, NULL,
stmt_atom_lng(be, 0), stmt_atom_lng(be, 1), 0, 0, 0, 0);
r = stmt_project(be, limit, r);
}
join = stmt_join_cand(be, column(be, l), column(be, r),
left->cand, NULL/*right->cand*/, 0, cmp_all, 0, 0, false, rel->op ==
op_left?false:true);
@@ -4461,13 +4461,12 @@ rel2bin_project(backend *be, sql_rel *re
if (topn && rel->r) {
list *oexps = rel->r, *npl = sa_list(sql->sa);
/* distinct, topn returns at least N (unique groups) */
- int distinct = need_distinct(rel);
stmt *limit = NULL, *lpiv = NULL, *lgid = NULL;
- int last = list_length(oexps);
+ int nr_obe = list_length(oexps);
/* check for partition columns */
stmt *grp = NULL, *ext = NULL, *cnt = NULL;
- for (n=oexps->h; n; n = n->next, last--) {
+ for (n=oexps->h; n; n = n->next, nr_obe--) {
sql_exp *gbe = n->data;
bool last = (!n->next ||
!is_partitioning((sql_exp*)n->next->data));
@@ -4504,19 +4503,13 @@ rel2bin_project(backend *be, sql_rel *re
continue;
orderbycolstmt = column(be, orderbycolstmt);
if (!limit) { /* topn based on a single column */
- limit = stmt_limit(be, orderbycolstmt, NULL,
NULL, stmt_atom_lng(be, 0), l, distinct, is_ascending(orderbycole),
nulls_last(orderbycole), last, 1);
+ limit = stmt_limit(be, orderbycolstmt, NULL,
NULL, stmt_atom_lng(be, 0), l, is_ascending(orderbycole),
nulls_last(orderbycole), nr_obe, 1);
} else { /* topn based on 2 columns */
- limit = stmt_limit(be, orderbycolstmt, lpiv,
lgid, stmt_atom_lng(be, 0), l, distinct, is_ascending(orderbycole),
nulls_last(orderbycole), last, 1);
+ limit = stmt_limit(be, orderbycolstmt, lpiv,
lgid, stmt_atom_lng(be, 0), l, is_ascending(orderbycole),
nulls_last(orderbycole), nr_obe, 1);
}
if (!limit)
return NULL;
lpiv = limit;
- if (!last) {
- lpiv = stmt_result(be, limit, 0);
- lgid = stmt_result(be, limit, 1);
- if (lpiv == NULL || lgid == NULL)
- return NULL;
- }
}
limit = lpiv;
@@ -4843,7 +4836,7 @@ rel2bin_topn(backend *be, sql_rel *rel,
sc = column(be, sc);
- limit = stmt_limit(be, sc, NULL, NULL, o, l, 0,0,0,0,0);
+ limit = stmt_limit(be, sc, NULL, NULL, o, l, 0,0,0,0);
for ( ; n; n = n->next) {
stmt *sc = n->data;
diff --git a/sql/backends/monet5/sql_statement.c
b/sql/backends/monet5/sql_statement.c
--- a/sql/backends/monet5/sql_statement.c
+++ b/sql/backends/monet5/sql_statement.c
@@ -1205,12 +1205,11 @@ stmt_result(backend *be, stmt *s, int nr
/* limit maybe atom nil */
stmt *
-stmt_limit(backend *be, stmt *col, stmt *piv, stmt *gid, stmt *offset, stmt
*limit, int distinct, int dir, int nullslast, int last, int order)
+stmt_limit(backend *be, stmt *col, stmt *piv, stmt *gid, stmt *offset, stmt
*limit, int dir, int nullslast, int nr_obe, int order)
{
- int new = 1;
MalBlkPtr mb = be->mb;
InstrPtr q = NULL;
- int l, p, g, c;
+ int l, g, c;
if (col == NULL || offset == NULL || limit == NULL || col->nr < 0 ||
offset->nr < 0 || limit->nr < 0)
goto bailout;
@@ -1218,7 +1217,6 @@ stmt_limit(backend *be, stmt *col, stmt
goto bailout;
c = (col) ? col->nr : 0;
- p = (piv) ? piv->nr : 0;
g = (gid) ? gid->nr : 0;
/* first insert single value into a bat */
@@ -1242,13 +1240,13 @@ stmt_limit(backend *be, stmt *col, stmt
c = k;
}
if (order) {
- if (new && piv) {
+ if (piv) {
q = piv->q;
q = pushArgument(mb, q, c);
q = pushBit(mb, q, dir);
q = pushBit(mb, q, nullslast);
return piv;
- } else if (new) {
+ } else {
int topn = 0;
q = newStmt(mb, calcRef, plusRef);
@@ -1259,7 +1257,7 @@ stmt_limit(backend *be, stmt *col, stmt
topn = getDestVar(q);
pushInstruction(mb, q);
- q = newStmtArgs(mb, algebraRef, "groupedfirstn",
(last*3)+6);
+ q = newStmtArgs(mb, algebraRef, "groupedfirstn",
(nr_obe*3)+6);
if (q == NULL)
goto bailout;
q = pushArgument(mb, q, topn);
@@ -1276,39 +1274,6 @@ stmt_limit(backend *be, stmt *col, stmt
l = getArg(q, 0);
l = getDestVar(q);
pushInstruction(mb, q);
- } else {
- int topn = 0;
-
- q = newStmt(mb, calcRef, plusRef);
- if (q == NULL)
- goto bailout;
- q = pushArgument(mb, q, offset->nr);
- q = pushArgument(mb, q, limit->nr);
- topn = getDestVar(q);
- pushInstruction(mb, q);
-
- q = newStmtArgs(mb, algebraRef, firstnRef, 9);
- if (q == NULL)
- goto bailout;
- if (!last) /* we need the groups for the next firstn */
- q = pushReturn(mb, q, newTmpVariable(mb,
TYPE_any));
- q = pushArgument(mb, q, c);
- if (p)
- q = pushArgument(mb, q, p);
- else
- q = pushNilBat(mb, q);
- if (g)
- q = pushArgument(mb, q, g);
- else
- q = pushNilBat(mb, q);
- q = pushArgument(mb, q, topn);
- q = pushBit(mb, q, dir);
- q = pushBit(mb, q, nullslast);
- q = pushBit(mb, q, distinct != 0);
-
- l = getArg(q, 0);
- l = getDestVar(q);
- pushInstruction(mb, q);
}
} else {
int len;
diff --git a/sql/backends/monet5/sql_statement.h
b/sql/backends/monet5/sql_statement.h
--- a/sql/backends/monet5/sql_statement.h
+++ b/sql/backends/monet5/sql_statement.h
@@ -239,12 +239,11 @@ extern stmt *stmt_mirror(backend *be, st
extern stmt *stmt_result(backend *be, stmt *s, int nr);
/*
- * distinct: compute topn on unique groups
* dir: direction of the ordering, ie 1 Ascending, 0 descending
- * last: intermediate step or last step
+ * nr_obe: total number of order by expression
* order: is order important or not (firstn vs slice)
*/
-extern stmt *stmt_limit(backend *sa, stmt *c, stmt *piv, stmt *gid, stmt
*offset, stmt *limit, int distinct, int dir, int nullslast, int last, int
order);
+extern stmt *stmt_limit(backend *sa, stmt *c, stmt *piv, stmt *gid, stmt
*offset, stmt *limit, int dir, int nullslast, int nr_obe, int order);
extern stmt *stmt_sample(backend *be, stmt *s, stmt *sample, stmt *seed);
extern stmt *stmt_order(backend *be, stmt *s, int direction, int nullslast);
extern stmt *stmt_reorder(backend *be, stmt *s, int direction, int nullslast,
stmt *orderby_ids, stmt *orderby_grp);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]