Update of /cvsroot/monetdb/sql/src/server
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv13637/src/server

Modified Files:
      Tag: SQL_2-16
        rel_bin.mx sql_select.mx sql_statement.mx sql_updates.mx 
Log Message:
We implemented RANK as ROW_NUMBER which isn't correct afcourse
So now added ROW_NUMBER and a new implementation for RANK.


Index: rel_bin.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/rel_bin.mx,v
retrieving revision 1.26
retrieving revision 1.26.2.1
diff -u -d -r1.26 -r1.26.2.1
--- rel_bin.mx  3 Jan 2007 12:39:46 -0000       1.26
+++ rel_bin.mx  31 Mar 2007 20:34:02 -0000      1.26.2.1
@@ -202,7 +202,7 @@
                if (as2) 
                        s = stmt_aggr2(stmt_reverse(as), as2, sql_dup_aggr(a) );
                else
-                       s = stmt_aggr(as, g, sql_dup_aggr(a) );
+                       s = stmt_aggr(as, g, sql_dup_aggr(a), 1 );
        }       break;
        case e_relation: {
                stmt *r = NULL;
@@ -610,9 +610,9 @@
                rgrp = grp_create(column(n->data), rgrp, NULL);
 
        a = sql_bind_aggr(sql->session->schema, "count", NULL);
-       ls = stmt_aggr(stmt_dup(lgrp->grp), grp_dup(lgrp), a); 
+       ls = stmt_aggr(stmt_dup(lgrp->grp), grp_dup(lgrp), a, 1); 
        a = sql_dup_aggr(a);
-       rs = stmt_aggr(stmt_dup(rgrp->grp), grp_dup(rgrp), a); 
+       rs = stmt_aggr(stmt_dup(rgrp->grp), grp_dup(rgrp), a, 1); 
 
        /* now find the matching groups */
        s = stmt_reljoin_init();
@@ -725,9 +725,9 @@
                rgrp = grp_create(column(n->data), rgrp, NULL);
 
        a = sql_bind_aggr(sql->session->schema, "count", NULL);
-       ls = stmt_aggr(stmt_dup(lgrp->grp), grp_dup(lgrp), a); 
+       ls = stmt_aggr(stmt_dup(lgrp->grp), grp_dup(lgrp), a, 1); 
        a = sql_dup_aggr(a);
-       rs = stmt_aggr(stmt_dup(rgrp->grp), grp_dup(rgrp), a); 
+       rs = stmt_aggr(stmt_dup(rgrp->grp), grp_dup(rgrp), a, 1); 
 
        /* now find the matching groups */
        s = stmt_reljoin_init();

Index: sql_statement.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_statement.mx,v
retrieving revision 1.139.2.5
retrieving revision 1.139.2.6
diff -u -d -r1.139.2.5 -r1.139.2.6
--- sql_statement.mx    31 Mar 2007 08:07:48 -0000      1.139.2.5
+++ sql_statement.mx    31 Mar 2007 20:34:03 -0000      1.139.2.6
@@ -271,7 +271,7 @@
 extern stmt *stmt_unop(stmt *op1, sql_subfunc *op);
 extern stmt *stmt_binop(stmt *op1, stmt *op2, sql_subfunc *op);
 extern stmt *stmt_Nop(stmt *ops, sql_subfunc *op);
-extern stmt *stmt_aggr(stmt *op1, group *grp, sql_subaggr *op);
+extern stmt *stmt_aggr(stmt *op1, group *grp, sql_subaggr *op, int reduce);
 extern stmt *stmt_aggr2(stmt *op1, stmt *op2, sql_subaggr *op);
 extern stmt *stmt_unique(stmt *s, group *grp);
 
@@ -1932,7 +1932,7 @@
 }
 
 stmt *
-stmt_aggr(stmt *op1, group *grp, sql_subaggr *op)
+stmt_aggr(stmt *op1, group *grp, sql_subaggr *op, int reduce)
 {
        stmt *s = stmt_create(st_aggr);
 
@@ -1944,11 +1944,12 @@
                s->h = stmt_dup(grp->grp->h);
                grp_destroy(grp);
        } else {
-               s->nrcols = 0;
+               if (!reduce)
+                       s->nrcols = 1;
                s->h = stmt_dup(op1->h);
        }
-       s->key = 1;
-       s->aggr = 1;
+       s->key = reduce;
+       s->aggr = reduce;
        s->op4.aggrval = op;
        s->flag = 0;
        return s;

Index: sql_select.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_select.mx,v
retrieving revision 1.175.2.7
retrieving revision 1.175.2.8
diff -u -d -r1.175.2.7 -r1.175.2.8
--- sql_select.mx       31 Mar 2007 17:25:37 -0000      1.175.2.7
+++ sql_select.mx       31 Mar 2007 20:34:02 -0000      1.175.2.8
@@ -1123,7 +1123,7 @@
                }
                if (grp) {
                        a = sql_bind_aggr(schema, aggrstr, NULL);
-                       return stmt_aggr(stmt_dup(grp->grp), grp_dup(grp), a);
+                       return stmt_aggr(stmt_dup(grp->grp), grp_dup(grp), a, 
1);
                }
                cv = scope_first_column(scp);
                if (cv && subset) {
@@ -1139,7 +1139,7 @@
                                s = stmt_unique(s, NULL);
                        }
                        a = sql_bind_aggr(schema, aggrstr, NULL);
-                       return stmt_aggr(stmt_alias(s,NULL,_strdup("")),NULL,a);
+                       return 
stmt_aggr(stmt_alias(s,NULL,_strdup("")),NULL,a,1);
                } else if (!cv) { /* count(*) without from */
                        /* if we have a where (boolean only) */
                        if (!(s = scope_bind(scp, NULL, "row"))) 
@@ -1182,7 +1182,7 @@
                        stmt *n = stmt_atom(atom_general(t, NULL, 0));
                        s = stmt_select2(s, n, stmt_dup(n), 0);
                }
-               return fix_scale(sql, t, stmt_aggr(s, grp_dup(grp), a), 1, 
(t->type->scale == SCALE_FIX));
+               return fix_scale(sql, t, stmt_aggr(s, grp_dup(grp), a, 1), 1, 
(t->type->scale == SCALE_FIX));
        } else {
                char *type = tail_type(s)->type->sqlname;
 
@@ -1420,9 +1420,17 @@
                else if (!s)
                        return s;
                if (grp) {
-                       sql_subaggr *a = sql_bind_aggr(sql->session->schema, 
"rownumber", NULL);
-                       s = stmt_aggr(stmt_dup(grp->grp), grp_dup(grp), a);
+                       sql_subaggr *a = sql_bind_aggr(sql->session->schema, 
aggrstr, NULL);
+                       if (!a)
+                               return sql_error(sql, 02, "SELECT: function 
'%s' not found", aggrstr );
+                       s = stmt_aggr(stmt_dup(grp->grp), grp_dup(grp), a, 0);
+               } else if (aggrstr) {
+                       sql_subaggr *a = sql_bind_aggr(sql->session->schema, 
aggrstr, NULL);
+                       if (!a)
+                               return sql_error(sql, 02, "SELECT: function 
'%s' not found", aggrstr );
+                       s = stmt_aggr(s, NULL, a, 0);
                } else {
+                       assert(0);
                        s = stmt_mark(stmt_reverse(s), 0);
                }
        } else {
@@ -1560,7 +1568,7 @@
                                        
                                        sql_subaggr *zero_or_one = 
sql_bind_aggr(sql->session->schema, "zero_or_one", tail_type(s));
                                        assert(zero_or_one);
-                                       s = stmt_aggr(s, NULL, zero_or_one);
+                                       s = stmt_aggr(s, NULL, zero_or_one, 1);
                                        /* we aggregated in the subquery not 
                                           in the outer */
                                        s->aggr = 0;
@@ -1988,9 +1996,9 @@
                        rgrp = grp_create(r, rgrp, NULL);
                }
                a = sql_bind_aggr(sql->session->schema, "count", NULL);
-               ls = stmt_aggr(stmt_dup(lgrp->grp), grp_dup(lgrp), a); 
+               ls = stmt_aggr(stmt_dup(lgrp->grp), grp_dup(lgrp), a, 1); 
                a = sql_dup_aggr(a);
-               rs = stmt_aggr(stmt_dup(rgrp->grp), grp_dup(rgrp), a); 
+               rs = stmt_aggr(stmt_dup(rgrp->grp), grp_dup(rgrp), a, 1); 
 
                /* now find the matching groups */
                s = stmt_reljoin_init();
@@ -2098,9 +2106,9 @@
                        rgrp = grp_create(r, rgrp, NULL);
                }
                a = sql_bind_aggr(sql->session->schema, "count", NULL);
-               ls = stmt_aggr(stmt_dup(lgrp->grp), grp_dup(lgrp), a); 
+               ls = stmt_aggr(stmt_dup(lgrp->grp), grp_dup(lgrp), a, 1); 
                a = sql_dup_aggr(a);
-               rs = stmt_aggr(stmt_dup(rgrp->grp), grp_dup(rgrp), a); 
+               rs = stmt_aggr(stmt_dup(rgrp->grp), grp_dup(rgrp), a, 1); 
 
                /* now find the matching groups */
                s = stmt_reljoin_init();
@@ -2608,7 +2616,7 @@
                        if (!sqa->key) {
                                sql_subaggr *zero_or_one = 
sql_bind_aggr(sql->session->schema, "zero_or_one", tail_type(sqa));
                                assert(zero_or_one);
-                               sqa = stmt_aggr(sqa, NULL, zero_or_one);
+                               sqa = stmt_aggr(sqa, NULL, zero_or_one, 1);
                                /* we aggregated in the subquery not in the 
outer */
                                sqa->aggr = 0;
                        }
@@ -2653,7 +2661,7 @@
                                        if (!cmp->key) {
                                                sql_subaggr *zero_or_one = 
sql_bind_aggr(sql->session->schema, "zero_or_one", tail_type(cmp));
                                                assert(zero_or_one);
-                                               cmp = stmt_aggr(cmp, NULL, 
zero_or_one);
+                                               cmp = stmt_aggr(cmp, NULL, 
zero_or_one, 1);
                                                /* we aggregated in the 
subquery not in the outer */
                                                cmp->aggr = 0;
                                        }
@@ -3200,7 +3208,7 @@
                        }
                        cnt = sql_bind_aggr(sql->session->schema, "count", 
NULL);
                        res = stmt_dup(s);
-                       res = stmt_aggr(res, NULL, cnt);
+                       res = stmt_aggr(res, NULL, cnt, 1);
                        if (sc->token == SQL_EXISTS) {
                                sql_subfunc *ne = 
sql_bind_func_result(sql->session->schema, "<>", it, it, bt);
 

Index: sql_updates.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_updates.mx,v
retrieving revision 1.101.2.4
retrieving revision 1.101.2.5
diff -u -d -r1.101.2.4 -r1.101.2.5
--- sql_updates.mx      16 Mar 2007 14:54:36 -0000      1.101.2.4
+++ sql_updates.mx      31 Mar 2007 20:34:03 -0000      1.101.2.5
@@ -126,7 +126,7 @@
                                stmt_reljoin_fill(s, stmt_bat(c->c, 
stmt_dup(ts), RDONLY), stmt_dup(inserts[c->c->colnr]->op2.stval));
                        }
                }
-               s = stmt_binop(stmt_aggr(s, NULL, cnt), stmt_atom_int(0), ne);
+               s = stmt_binop(stmt_aggr(s, NULL, cnt, 1), stmt_atom_int(0), 
ne);
 
                /* 2e stage: find out if inserted are unique */
                if (idx_inserts->nrcols) {      /* insert columns not atoms */
@@ -144,7 +144,7 @@
                        }
 
                        sum = sql_bind_aggr(sql->session->schema, "not_unique", 
tail_type(ss));
-                       count_sum = stmt_aggr(ss, NULL, sum);
+                       count_sum = stmt_aggr(ss, NULL, sum, 1);
                        /* combine results */
                        s = stmt_binop(s, count_sum, or);
                }
@@ -164,11 +164,11 @@
                        if (h->nrcols) {
                                s = stmt_join(s, stmt_reverse(stmt_dup(h)), 
cmp_equal);
                                /* s should be empty */
-                               s = stmt_aggr(s, NULL, cnt);
+                               s = stmt_aggr(s, NULL, cnt, 1);
                        } else {
                                s = stmt_uselect(s, stmt_dup(h), cmp_equal);
                                /* s should be empty */
-                               s = stmt_aggr(s, NULL, cnt);
+                               s = stmt_aggr(s, NULL, cnt, 1);
                        }
                        /* s should be empty */
                        s = stmt_binop(s, stmt_atom_int(0), ne);
@@ -185,12 +185,12 @@
 
                        stmt *ins = stmt_dup(inserts[c->c->colnr]->op2.stval);
                        group *g = grp_create(ins, NULL, NULL);
-                       stmt *ss = stmt_aggr(stmt_dup(g->grp), g, 
sql_dup_aggr(cnt));
+                       stmt *ss = stmt_aggr(stmt_dup(g->grp), g, 
sql_dup_aggr(cnt), 1);
 
                        /* (count(ss) <> sum(ss)) */
                        sum = sql_bind_aggr(sql->session->schema, "sum", 
tail_type(ss));
-                       ssum = stmt_aggr(ss, NULL, sum);
-                       count_sum = stmt_binop(check_types(sql, 
tail_type(ssum), stmt_aggr(stmt_dup(ss), NULL, sql_dup_aggr(cnt)), type_equal), 
ssum, sql_dup_func(ne));
+                       ssum = stmt_aggr(ss, NULL, sum, 1);
+                       count_sum = stmt_binop(check_types(sql, 
tail_type(ssum), stmt_aggr(stmt_dup(ss), NULL, sql_dup_aggr(cnt), 1), 
type_equal), ssum, sql_dup_func(ne));
 
                        /* combine results */
                        s = stmt_binop(s, count_sum, or);
@@ -219,12 +219,12 @@
        (void) sql;             /* unused! */
 
        if (s->key && s->nrcols == 0) {
-               s = stmt_binop(stmt_aggr(stmt_dup(idx_inserts), NULL, cnt), 
stmt_atom_int(1), ne);
+               s = stmt_binop(stmt_aggr(stmt_dup(idx_inserts), NULL, cnt, 1), 
stmt_atom_int(1), ne);
        } else {
                /* reljoin.count <> inserts[col1].count */
                stmt *ins = stmt_dup(inserts[0]->op2.stval);
 
-               s = stmt_binop(stmt_aggr(stmt_dup(idx_inserts), NULL, cnt), 
stmt_aggr(ins, NULL, sql_dup_aggr(cnt)), ne);
+               s = stmt_binop(stmt_aggr(stmt_dup(idx_inserts), NULL, cnt, 1), 
stmt_aggr(ins, NULL, sql_dup_aggr(cnt), 1), ne);
        }
 
        /* s should be empty */
@@ -573,7 +573,7 @@
                        stmt_reljoin_fill(s, l, upd);
 
                }
-               s = stmt_binop(stmt_aggr(s, NULL, cnt), stmt_atom_int(0), ne);
+               s = stmt_binop(stmt_aggr(s, NULL, cnt, 1), stmt_atom_int(0), 
ne);
 
                /* 2e stage: find out if the updated are unique */
                if (idx_updates->nrcols) {      /* update columns not atoms */
@@ -598,11 +598,11 @@
                                }
                                g = grp_create(upd, g, NULL);
                        }
-                       ss = stmt_aggr(stmt_dup(g->grp), grp_dup(g), 
sql_dup_aggr(cnt));
+                       ss = stmt_aggr(stmt_dup(g->grp), grp_dup(g), 
sql_dup_aggr(cnt), 1);
                        grp_destroy(g);
                        /* (count(ss) <> sum(ss)) */
                        sum = sql_bind_aggr(sql->session->schema, "sum", 
tail_type(ss));
-                       count_sum = stmt_binop(stmt_aggr(stmt_dup(ss), NULL, 
sql_dup_aggr(cnt)), check_types(sql, it, stmt_aggr(ss, NULL, sum), type_equal), 
sql_dup_func(ne));
+                       count_sum = stmt_binop(stmt_aggr(stmt_dup(ss), NULL, 
sql_dup_aggr(cnt), 1), check_types(sql, it, stmt_aggr(ss, NULL, sum, 1), 
type_equal), sql_dup_func(ne));
 
                        /* combine results */
                        s = stmt_binop(s, count_sum, or);
@@ -621,7 +621,7 @@
                stmt *s = stmt_join(o, stmt_reverse(h), cmp_equal);
 
                /* s should be empty */
-               s = stmt_binop(stmt_aggr(s, NULL, cnt), stmt_atom_int(0), ne);
+               s = stmt_binop(stmt_aggr(s, NULL, cnt, 1), stmt_atom_int(0), 
ne);
 
                /* 2e stage: find out if updated are unique */
                if (h->nrcols) {        /* update columns not atoms */
@@ -632,12 +632,12 @@
 
                        stmt *upd = stmt_dup(updates[c->c->colnr]->op2.stval);
                        group *g = grp_create(upd, NULL, NULL);
-                       stmt *ss = stmt_aggr(stmt_dup(g->grp), g, 
sql_dup_aggr(cnt));
+                       stmt *ss = stmt_aggr(stmt_dup(g->grp), g, 
sql_dup_aggr(cnt), 1);
 
                        /* (count(ss) <> sum(ss)) */
                        sum = sql_bind_aggr(sql->session->schema, "sum", 
tail_type(ss));
-                       ssum = stmt_aggr(ss, NULL, sum);
-                       count_sum = stmt_binop(check_types(sql, 
tail_type(ssum), stmt_aggr(stmt_dup(ss), NULL, sql_dup_aggr(cnt)), type_equal), 
ssum, sql_dup_func(ne));
+                       ssum = stmt_aggr(ss, NULL, sum, 1);
+                       count_sum = stmt_binop(check_types(sql, 
tail_type(ssum), stmt_aggr(stmt_dup(ss), NULL, sql_dup_aggr(cnt), 1), 
type_equal), ssum, sql_dup_func(ne));
 
                        /* combine results */
                        s = stmt_binop(s, count_sum, or);
@@ -669,7 +669,7 @@
        (void) sql;             /* unused! */
        /* reljoin.count <> updates[updcol].count */
        cur = stmt_dup(updates[updcol]->op2.stval);
-       s = stmt_binop(stmt_aggr(stmt_dup(idx_updates), NULL, cnt), 
stmt_aggr(cur, NULL, sql_dup_aggr(cnt)), ne);
+       s = stmt_binop(stmt_aggr(stmt_dup(idx_updates), NULL, cnt, 1), 
stmt_aggr(cur, NULL, sql_dup_aggr(cnt), 1), ne);
 
        /* s should be empty */
        snprintf(buf, BUFSIZ, "UPDATE: FOREIGN KEY constraint '%s.%s' 
violated", k->t->base.name, k->base.name);
@@ -729,7 +729,7 @@
        stmt_destroy(fts);
 
        /* reljoin.count <> updates[updcol].count */
-       s = stmt_binop(stmt_aggr(stmt_dup(s), NULL, cnt), stmt_aggr(rows, NULL, 
sql_dup_aggr(cnt)), ne);
+       s = stmt_binop(stmt_aggr(stmt_dup(s), NULL, cnt, 1), stmt_aggr(rows, 
NULL, sql_dup_aggr(cnt), 1), ne);
 
        /* s should be empty */
        snprintf(buf, BUFSIZ, "UPDATE: FOREIGN KEY constraint '%s.%s' 
violated", k->t->base.name, k->base.name);
@@ -1020,7 +1020,7 @@
                        if (!(s->key && s->nrcols == 0)) {
                                s = stmt_atom(atom_general(&c->type, NULL, 0));
                                s = 
stmt_uselect(stmt_dup(inserts[c->colnr]->op2.stval), s, cmp_equal);
-                               s = stmt_aggr(s, NULL, sql_dup_aggr(cnt));
+                               s = stmt_aggr(s, NULL, sql_dup_aggr(cnt), 1);
                        } else {
                                sql_subfunc *isnil = 
sql_bind_func(sql->session->schema, "isnull", &c->type, NULL);
 
@@ -1046,7 +1046,7 @@
                if (inserts[0]->op2.stval->nrcols == 0) {
                        s = stmt_atom_int(1);
                } else {
-                       s = stmt_aggr(stmt_dup(inserts[0]->op2.stval), NULL, 
sql_bind_aggr(sql->session->schema, "count", NULL));
+                       s = stmt_aggr(stmt_dup(inserts[0]->op2.stval), NULL, 
sql_bind_aggr(sql->session->schema, "count", NULL), 1);
                }
                list_append(l, stmt_affected_rows(s));
        }
@@ -1384,7 +1384,7 @@
                        if (!(s->key && s->nrcols == 0)) {
                                s = stmt_atom(atom_general(&c->type, NULL, 0));
                                s = 
stmt_uselect(stmt_dup(updates[c->colnr]->op2.stval), s, cmp_equal);
-                               s = stmt_aggr(s, NULL, sql_dup_aggr(cnt));
+                               s = stmt_aggr(s, NULL, sql_dup_aggr(cnt), 1);
                        } else {
                                sql_subfunc *isnil = 
sql_bind_func(sql->session->schema, "isnull", &c->type, NULL);
 
@@ -1532,7 +1532,7 @@
                                updates[c->colnr] = stmt_insert(stmt_bat(c, 
stmt_dup(tv->s), UPD), stmt_dup(v));
                        list_append(l, stmt_dup(updates[c->colnr]));
                }
-               list_append(l, stmt_affected_rows(stmt_aggr(first_subset(s), 
NULL, sql_bind_aggr(sql->session->schema, "count", NULL))));
+               list_append(l, stmt_affected_rows(stmt_aggr(first_subset(s), 
NULL, sql_bind_aggr(sql->session->schema, "count", NULL), 1)));
                stmt_destroy(s);
 
                if ((s = sql_update(sql, t, updates, l)) == NULL) {
@@ -1669,7 +1669,7 @@
                        s = stmt_semijoin(stmt_reverse(s), stmt_dup(deletes));
                        /* The overlap between deleted primaries and foreign
                           should be empty */
-                       s = stmt_binop(stmt_aggr(s, NULL, cnt), 
stmt_atom_int(0), ne);
+                       s = stmt_binop(stmt_aggr(s, NULL, cnt, 1), 
stmt_atom_int(0), ne);
                        snprintf(buf, BUFSIZ, "DELETE: FOREIGN KEY constraint 
'%s.%s' violated", k->t->base.name, k->base.name);
                        s = stmt_exception(s, _strdup(buf), 00001);
                        list_prepend(l, s);
@@ -1731,7 +1731,7 @@
        if (output) {
                if (!all) 
                        s = stmt_aggr(stmt_dup(subset), NULL,
-                           sql_bind_aggr(sql->session->schema, "count", NULL));
+                           sql_bind_aggr(sql->session->schema, "count", NULL), 
1);
                list_append(l, stmt_affected_rows(s));
        }
        return stmt_list(l);


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to