Update of /cvsroot/monetdb/sql/src/server
In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv1972/src/server

Modified Files:
        bin_optimizer.mx rel_bin.mx rel_schema.mx rel_select.mx 
        rel_updates.mx sql_mvc.mx sql_parser.mx sql_statement.mx 
Log Message:

A sequence of group new and derives is now closed with a group.done (does
the last step ie a group.new or derive).
This makes the code in merge table a bit cleaner (more could be done later)

sql.bind and append/update/delete now have an extra (first) argument,
making them safe to use in the dataflow (ie solved using variable dependencies)
(BREAKS octopus !)

Implemented read only tables. Use 
ALTER TABLE x SET READ ONLY; 
(cannot be reverted currently)

fixed bug in limit/offset handling, now we have 64 bit wrd instead of int.

The new read only required schema changes, ie backup/restore your db.
We therefor claimed some more oid's for internal functions.



Index: bin_optimizer.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/bin_optimizer.mx,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- bin_optimizer.mx    10 Feb 2010 22:32:31 -0000      1.27
+++ bin_optimizer.mx    27 Feb 2010 19:27:48 -0000      1.28
@@ -286,8 +286,8 @@
                        stmt *r = stmt_dup(j->op2.stval);
 
                        l = stmt_limit(l, 
-                             s->op2.stval->op1.aval->data.val.ival,
-                             s->op3.stval->op1.aval->data.val.ival,
+                             s->op2.stval->op1.aval->data.val.wval,
+                             s->op3.stval->op1.aval->data.val.wval,
                              s->flag);
                        s = stmt_join(l, r, cmp_equal); 
                        ns = bin_optimizer(c, s);
@@ -309,8 +309,8 @@
                        stmt *r = stmt_dup(j->op2.stval);
 
                        r = stmt_limit(r, 
-                             s->op2.stval->op1.aval->data.val.ival,
-                             s->op3.stval->op1.aval->data.val.ival,
+                             s->op2.stval->op1.aval->data.val.wval,
+                             s->op3.stval->op1.aval->data.val.wval,
                              s->flag);
                        s = stmt_join(l, r, cmp_equal); 
                        ns = bin_optimizer(c, s);
@@ -323,8 +323,8 @@
                /* try to push the limit through the order */
                if (j->type == st_order) {
                        s = stmt_order(stmt_limit(stmt_dup(j->op1.stval),
-                               s->op2.stval->op1.aval->data.val.ival,
-                               s->op3.stval->op1.aval->data.val.ival,
+                               s->op2.stval->op1.aval->data.val.wval,
+                               s->op3.stval->op1.aval->data.val.wval,
                                LIMIT_DIRECTION(j->flag,1,0)), j->flag);
                        ns = bin_optimizer(c, s);
                        stmt_destroy(s);
@@ -336,8 +336,8 @@
                /* try to push the limit through the reverse */
                if (!s->flag && j->type == st_reverse) {
                        s = stmt_reverse(stmt_limit(stmt_dup(j->op1.stval),
-                               s->op2.stval->op1.aval->data.val.ival,
-                               s->op3.stval->op1.aval->data.val.ival,
+                               s->op2.stval->op1.aval->data.val.wval,
+                               s->op3.stval->op1.aval->data.val.wval,
                                0));
                        ns = bin_optimizer(c, s);
                        stmt_destroy(s);
@@ -347,10 +347,10 @@
                        return ns;
                }
                /* try to push the limit through the mark (only if there is no 
offset) */
-               if (!s->op2.stval->op1.aval->data.val.ival && j->type == 
st_mark) {
+               if (!s->op2.stval->op1.aval->data.val.wval && j->type == 
st_mark) {
                        s = stmt_mark_tail(stmt_limit(stmt_dup(j->op1.stval),
-                               s->op2.stval->op1.aval->data.val.ival,
-                               s->op3.stval->op1.aval->data.val.ival, s->flag),
+                               s->op2.stval->op1.aval->data.val.wval,
+                               s->op3.stval->op1.aval->data.val.wval, s->flag),
                                j->op2.stval->op1.aval->data.val.ival);
                        ns = bin_optimizer(c, s);
                        stmt_destroy(s);

Index: rel_select.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/rel_select.mx,v
retrieving revision 1.169
retrieving revision 1.170
diff -u -d -r1.169 -r1.170
--- rel_select.mx       10 Feb 2010 08:21:49 -0000      1.169
+++ rel_select.mx       27 Feb 2010 19:27:59 -0000      1.170
@@ -4364,6 +4364,8 @@
                                        rel = rel_groupby_gbe(rel, e); 
                                }
                        } else {
+                               node *m;
+
                                list *gbexps = new_exp_list();
 
                                decorrelated = 1;
@@ -4379,14 +4381,13 @@
                                /* now create a groupby on the inner */
                                inner = rel_groupby(rel_dup(rel->r), gbexps);
                                inner = rel_label(sql, inner);
-                               for (n = ce->h; n; n = n->next) {
+                               for (n = ce->h, m = gbexps->h; n && m; n = 
n->next, m = m->next) {
                                        sql_exp *e = n->data;
-                                       sql_exp *re = e->r;
+                                       sql_exp *gbe = m->data;
        
                                        assert(e->type == e_cmp);
-                                       assert(re->type == e_column);
-                                       re = exp_column(rel_name(inner), re->r, 
exp_subtype(re), inner->card, has_nil(re), is_intern(re));
-                                       e = exp_compare( exp_dup(e->l), re, 
e->flag);
+                                       gbe = exp_column(rel_name(inner), 
exp_name(gbe), exp_subtype(gbe), inner->card, has_nil(gbe), is_intern(gbe));
+                                       e = exp_compare( exp_dup(e->l), gbe, 
e->flag);
                                        append(jexps, e);
                                }
                                outer = rel_dup(outer);
@@ -4559,9 +4560,9 @@
        if (sn->limit > 0 || sn->offset > 0) {
                list *exps = new_exp_list();
 
-               append(exps, exp_atom_int(sn->limit));
+               append(exps, exp_atom_lng(sn->limit));
                if (sn->offset > 0)
-                       append(exps, exp_atom_int(sn->offset));
+                       append(exps, exp_atom_lng(sn->offset));
                rel = rel_topn(rel, exps);
        }
        return rel;

Index: sql_statement.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_statement.mx,v
retrieving revision 1.199
retrieving revision 1.200
diff -u -d -r1.199 -r1.200
--- sql_statement.mx    10 Feb 2010 22:32:46 -0000      1.199
+++ sql_statement.mx    27 Feb 2010 19:28:11 -0000      1.200
@@ -149,6 +149,7 @@
 
 /* flag to indicate anti join/select */
 #define ANTI 16
+#define GRP_DONE 32
 
 typedef struct stmt {
        sql_ref ref;
@@ -283,7 +284,7 @@
 
 #define LIMIT_DIRECTION(dir,order,before_project) \
                (dir<<2)+(before_project<<1)+(order)
-extern stmt *stmt_limit(stmt *s, int offset, int limit, int direction);
+extern stmt *stmt_limit(stmt *s, wrd offset, wrd limit, int direction);
 extern stmt *stmt_order(stmt *s, int direction);
 extern stmt *stmt_reorder(stmt *s, stmt *t, int direction);
 
@@ -323,6 +324,7 @@
 extern list* stmt_list_dependencies(stmt *s, int depend_type);
 
 extern group *grp_create(stmt *s, group *og);
+extern void grp_done(group *g);
 extern void grp_destroy(group *g);
 extern group *grp_dup(group *g);
 
@@ -602,6 +604,13 @@
        return g;
 }
 
+void 
+grp_done(group *g)
+{
+       if (g && g->grp)
+               g->grp->flag = GRP_DONE;
+}
+
 void
 cond_stmt_destroy(stmt *s)
 {
@@ -1157,6 +1166,9 @@
 {
        stmt *s = stmt_bat(c, basetable, access );
 
+       if (c->t->readonly)
+               return s;
+
        if (isTable(c->t) &&
           (c->base.flag != TR_NEW || c->t->base.flag != TR_NEW /* alter */) &&
            access == RDONLY && c->t->persistence == SQL_PERSIST && 
!c->t->commit_action) {
@@ -1191,6 +1203,9 @@
 {
        stmt *s = stmt_idxbat(idx, access);
 
+       if (idx->t->readonly)
+               return s;
+
        if (isTable(idx->t) &&
           (idx->base.flag != TR_NEW || idx->t->base.flag != TR_NEW /* alter 
*/) && 
            access == RDONLY && idx->t->persistence == SQL_PERSIST && 
!idx->t->commit_action) {
@@ -1446,13 +1461,13 @@
 }
 
 stmt *
-stmt_limit(stmt *s, int offset, int limit, int direction)
+stmt_limit(stmt *s, wrd offset, wrd limit, int direction)
 {
        stmt *ns = stmt_create(st_limit);
 
        ns->op1.stval = s;
-       ns->op2.stval = stmt_atom_int(offset);
-       ns->op3.stval = stmt_atom_int(limit);
+       ns->op2.stval = stmt_atom_wrd(offset);
+       ns->op3.stval = stmt_atom_wrd(limit);
        ns->nrcols = s->nrcols;
        ns->key = s->key;
        ns->aggr = s->aggr;

Index: sql_mvc.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_mvc.mx,v
retrieving revision 1.234
retrieving revision 1.235
diff -u -d -r1.234 -r1.235
--- sql_mvc.mx  31 Jan 2010 12:44:56 -0000      1.234
+++ sql_mvc.mx  27 Feb 2010 19:28:07 -0000      1.235
@@ -192,6 +192,7 @@
 extern sql_column *mvc_null(mvc *c, sql_column *col, int flag);
 extern sql_column *mvc_default(mvc *c, sql_column *col, char *val);
 extern sql_column *mvc_drop_default(mvc *c, sql_column *col);
+extern sql_table * mvc_readonly(mvc *m, sql_table *t, int readonly);
 extern int mvc_is_sorted(mvc *c, sql_column *col);
 
 extern sql_ukey *mvc_create_ukey(mvc *m, sql_table *t, char *kname, key_type 
kt);
@@ -307,6 +308,7 @@
                mvc_create_column_(m, t, "type", "smallint", 16);
                mvc_create_column_(m, t, "system", "boolean", 1);
                mvc_create_column_(m, t, "commit_action", "smallint", 16);
+               mvc_create_column_(m, t, "readonly", "boolean", 1);
                mvc_create_column_(m, t, "temporary", "smallint", 16);
 
                t = mvc_create_view(m, s, "columns", SQL_PERSIST, "SELECT * 
FROM (SELECT p.* FROM \"sys\".\"_columns\" AS p UNION ALL SELECT t.* FROM 
\"tmp\".\"_columns\" AS t) AS columns;", 1);
@@ -319,6 +321,7 @@
                mvc_create_column_(m, t, "default", "varchar", 2048);
                mvc_create_column_(m, t, "null", "boolean", 1);
                mvc_create_column_(m, t, "number", "int", 32);
+               mvc_create_column_(m, t, "storage_type", "int", 32);
 
                sql_create_env(m, s);
                sql_create_privileges(m, s);
@@ -1398,8 +1401,10 @@
        if (mvc_debug)
                fprintf(stderr, "mvc_null %s %d\n", col->base.name, isnull);
 
-       if (col->t->persistence == SQL_DECLARED_TABLE)
+       if (col->t->persistence == SQL_DECLARED_TABLE) {
                col->null = isnull;
+               return col;
+       }
        return sql_trans_alter_null(m->session->tr, col, isnull);
 }
 
@@ -1431,6 +1436,19 @@
        }
 }
 
+sql_table *
+mvc_readonly(mvc *m, sql_table *t, int readonly)
+{
+       if (mvc_debug)
+               fprintf(stderr, "mvc_readonly %s %d\n", t->base.name, readonly);
+
+       if (t->persistence == SQL_DECLARED_TABLE) {
+               t->readonly = readonly;
+               return t;
+       }
+       return sql_trans_alter_readonly(m->session->tr, t, readonly);
+}
+
 int 
 mvc_is_sorted(mvc *m, sql_column *col)
 {

Index: rel_schema.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/rel_schema.mx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- rel_schema.mx       7 Feb 2010 17:22:09 -0000       1.3
+++ rel_schema.mx       27 Feb 2010 19:27:59 -0000      1.4
@@ -1026,7 +1026,7 @@
                node *n;
                sql_rel *res = NULL;
                sql_table *nt = dup_sql_table(sql->sa, t);
-               if (!nt || table_element(sql, te, s, nt, 1) == SQL_ERR) 
+               if (!nt || (te && table_element(sql, te, s, nt, 1) == SQL_ERR)) 
                        return NULL;
 
                if (t->persistence != SQL_DECLARED_TABLE && s)
@@ -1035,7 +1035,11 @@
                if (t->s && !nt->s)
                        nt->s = t->s;
 
+               if (!te) /* Set Read only */
+                       nt = mvc_readonly(sql, nt, 1);
                res = rel_table( DDL_ALTER_TABLE, sname, nt, 0);
+               if (!te) /* Set Read only */
+                       return res;
 
                /* new columns need update with default values */
                if (nt->columns.nelm) {

Index: rel_updates.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/rel_updates.mx,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- rel_updates.mx      10 Jan 2010 15:33:34 -0000      1.14
+++ rel_updates.mx      27 Feb 2010 19:28:07 -0000      1.15
@@ -158,6 +158,8 @@
                return sql_error(sql, 02, "INSERT INTO: no such table '%s'", 
tname);
        } else if (isView(t)) {
                return sql_error(sql, 02, "INSERT INTO: cannot insert into view 
'%s'", tname);
+       } else if (t->readonly) {
+               return sql_error(sql, 02, "INSERT INTO: cannot insert into read 
only table '%s'", tname);
        }
        if (t && !isTempTable(t) && STORE_READONLY(active_store_type))
                return sql_error(sql, 02, "INSERT INTO: insert into table '%s' 
not allowed in readonly mode", tname);
@@ -330,6 +332,8 @@
                return sql_error(sql, 02, "UPDATE: no such table '%s'", tname);
        } else if (isView(t)) {
                return sql_error(sql, 02, "UPDATE: cannot update view '%s'", 
tname);
+       } else if (t->readonly) {
+               return sql_error(sql, 02, "UPDATE: cannot update read only 
table '%s'", tname);
        } else {
                sql_exp *e = NULL;
                sql_rel *r = NULL;
@@ -454,6 +458,8 @@
                return sql_error(sql, 02, "DELETE FROM: no such table '%s'", 
tname);
        } else if (isView(t)) {
                return sql_error(sql, 02, "DELETE FROM: cannot delete from view 
'%s'", tname);
+       } else if (t->readonly) {
+               return sql_error(sql, 02, "DELETE FROM: cannot delete from read 
only table '%s'", tname);
        }
        if (t && !isTempTable(t) && STORE_READONLY(active_store_type))
                return sql_error(sql, 02, "DELETE FROM: delete from table '%s' 
not allowed in readonly mode", tname);
@@ -561,9 +567,10 @@
                                t = tpe->comp_type;
                }
        }
-       if (!t) {
+       if (!t) 
                return sql_error(sql, 02, "COPY INTO: no such table '%s'", 
tname);
-       }
+       if (t->readonly) 
+               return sql_error(sql, 02, "COPY INTO: cannot copy into read 
only table '%s'", tname);
        if (t && !isTempTable(t) && STORE_READONLY(active_store_type))
                return sql_error(sql, 02, "COPY INTO: copy into table '%s' not 
allowed in readonly mode", tname);
        if (files) {
@@ -622,9 +629,10 @@
                                t = tpe->comp_type;
                }
        }
-       if (!t) {
+       if (!t) 
                return sql_error(sql, 02, "COPY INTO: no such table '%s'", 
tname);
-       }
+       if (t->readonly) 
+               return sql_error(sql, 02, "COPY INTO: cannot copy into read 
only table '%s'", tname);
        if (t && !isTempTable(t) && STORE_READONLY(active_store_type))
                return sql_error(sql, 02, "COPY INTO: copy into table '%s' not 
allowed in readonly mode", tname);
        if (files == NULL)

Index: sql_parser.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_parser.mx,v
retrieving revision 1.331
retrieving revision 1.332
diff -u -d -r1.331 -r1.332
--- sql_parser.mx       30 Jan 2010 12:33:27 -0000      1.331
+++ sql_parser.mx       27 Feb 2010 19:28:07 -0000      1.332
@@ -570,10 +570,8 @@
        opt_from_grantor
        opt_grantor
        opt_index_type
-       opt_limit
        opt_match
        opt_match_type
-       opt_offset
        opt_on_commit
        opt_port
        opt_ref_action
@@ -602,6 +600,9 @@
        opt_start
        lngval
        poslng
+       nonzerolng
+       opt_limit
+       opt_offset
        opt_increment
        opt_min
        opt_max
@@ -1099,7 +1100,6 @@
          append_symbol(l, $6);
          $$ = _symbol_create_list( SQL_ALTER_TABLE, l ); }
  | ALTER TABLE qname ALTER alter_table_element
-
        { dlist *l = L();
          append_list(l, $3);
          append_symbol(l, $5);
@@ -1109,6 +1109,11 @@
          append_list(l, $3);
          append_symbol(l, $5);
          $$ = _symbol_create_list( SQL_ALTER_TABLE, l ); }
+ | ALTER TABLE qname SET READ ONLY
+       { dlist *l = L();
+         append_list(l, $3);
+         append_symbol(l, NULL);
+         $$ = _symbol_create_list( SQL_ALTER_TABLE, l ); }
  | ALTER USER ident passwd_schema
        { dlist *l = L();
          append_string(l, $3);
@@ -1321,7 +1326,7 @@
  */
 opt_increment:
        /* empty */             { $$ = -1; }
-  |    INCREMENT BY nonzero    { $$ = $3; }
+  |    INCREMENT BY nonzerolng { $$ = $3; }
   ;
 
 /*
@@ -1333,8 +1338,8 @@
  */
 opt_min:
        /* empty */                     { $$ = -1; }
-  |    MINVALUE nonzero                { $$ = $2; }
-  |    NOMINVALUE                              { $$ =  0; }
+  |    MINVALUE nonzerolng             { $$ = $2; }
+  |    NOMINVALUE                      { $$ =  0; }
   ;
 
 /*
@@ -1346,8 +1351,8 @@
  */
 opt_max:
        /* empty */                     { $$ = -1; }
-  |    MAXVALUE nonzero                { $$ = $2; }
-  |    NOMAXVALUE                              { $$ =  0; }
+  |    MAXVALUE nonzerolng             { $$ = $2; }
+  |    NOMAXVALUE                      { $$ =  0; }
   ;
 
 /*
@@ -1358,7 +1363,7 @@
  */
 opt_cache:
        /* empty */                     { $$ = -1; }
-  |    CACHE nonzero                   { $$ = $2; }
+  |    CACHE nonzerolng                { $$ = $2; }
   ;
 
 /*
@@ -3129,12 +3134,12 @@
 
 opt_limit:
     /* empty */                        { $$ = -1; }
- |  LIMIT nonzero                      { $$ = $2; }
+ |  LIMIT nonzerolng                   { $$ = $2; }
  ;
 
 opt_offset:
        /* empty */                     { $$ = -1; }
- |  OFFSET posint                      { $$ = $2; }
+ |  OFFSET poslng                      { $$ = $2; }
  ;
 
 sort_specification_list:
@@ -4275,6 +4280,16 @@
                }
        ;
 
+nonzerolng:
+       lngval
+               { $$ = $1;
+                 if ($$ <= 0) {
+                       $$ = -1;
+                       yyerror("Positive value greater than 0 expected");
+                       YYABORT;
+                 }
+               }
+       ;
 
 poslng:
        lngval  { $$ = $1;

Index: rel_bin.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/rel_bin.mx,v
retrieving revision 1.110
retrieving revision 1.111
diff -u -d -r1.110 -r1.111
--- rel_bin.mx  10 Feb 2010 22:32:36 -0000      1.110
+++ rel_bin.mx  27 Feb 2010 19:27:54 -0000      1.111
@@ -59,13 +59,13 @@
 }
 
 static stmt *
-bin_find_column( stmt *sub, char *rname, char *name ) 
+list_find_column( list *l, char *rname, char *name ) 
 {
        stmt *res = NULL;
        node *n;
 
        if (rname) {
-               for (n = sub->op1.lval->h; n; n = n->next) {
+               for (n = l->h; n; n = n->next) {
                        char *rnme = table_name(n->data);
                        char *nme = column_name(n->data);
 
@@ -82,7 +82,7 @@
                                _DELETE(nme);
                }
        } else {
-               for (n = sub->op1.lval->h; n; n = n->next) {
+               for (n = l->h; n; n = n->next) {
                        char *nme = column_name(n->data);
 
                        if (nme && strcmp(nme, name) == 0) {
@@ -99,6 +99,12 @@
        return stmt_dup(res);
 }
 
+static stmt *
+bin_find_column( stmt *sub, char *rname, char *name ) 
+{
+       return list_find_column( sub->op1.lval, rname, name);
+}
+
 static list *
 bin_find_columns( stmt *sub, char *name ) 
 {
@@ -309,6 +315,7 @@
                                }
                        }
                        /* order on the group first */
+                       grp_done(g);
                        if (g) 
                                orderby = stmt_order(stmt_dup(g->grp), 1);
                        for (en = obe->h; en; en = en->next) {
@@ -1087,6 +1094,7 @@
                        grp = grp_create(column(t), grp);
                }
        }
+       grp_done(grp);
 
        for (n = s->op1.lval->h; n; n = n->next) {
                stmt *t = n->data;
@@ -1213,6 +1221,8 @@
                grp_destroy(rgrp);
                return NULL;
        }
+       grp_done(lgrp);
+       grp_done(rgrp);
 
        a = sql_bind_aggr(sql->session->schema, "count", NULL);
        ls = stmt_aggr(stmt_dup(lgrp->grp), grp_dup(lgrp), a, 1); 
@@ -1356,6 +1366,8 @@
                grp_destroy(rgrp);
                return NULL;
        }
+       grp_done(lgrp);
+       grp_done(rgrp);
 
        a = sql_bind_aggr(sql->session->schema, "count", NULL);
        ls = stmt_aggr(stmt_dup(lgrp->grp), grp_dup(lgrp), a, 1); 
@@ -1464,28 +1476,28 @@
        return stmt_list(l);
 }
 
-static int
+static wrd
 topn_limit( sql_rel *rel )
 {
        if (rel->exps) {
                sql_exp *limit = rel->exps->h->data;
                atom *a = limit->l;
 
-               return a->data.val.ival;
+               return a->data.val.lval;
        }
        return -1;
 }
 
-static int
+static wrd
 topn_offset( sql_rel *rel )
 {
-       int o = 0;
+       wrd o = 0;
 
        if (rel->exps && list_length(rel->exps) > 1) {
                sql_exp *offset = rel->exps->h->next->data;
                atom *a = offset->l;
 
-               o = a->data.val.ival;
+               o = a->data.val.lval;
                if (o <= 0)
                        o = 0;
        }
@@ -1510,7 +1522,7 @@
        list *pl; 
        node *en, *n;
        stmt *sub = NULL, *psub = NULL;
-       int l = -1;
+       wrd l = -1;
 
        if (topn) {
                int o = topn_offset(topn);
@@ -1602,12 +1614,21 @@
                                cond_stmt_destroy(orderby);
                                return NULL;
                        }
+                       /* single values don't need sorting */
+                       if (orderbycols->nrcols == 0) {
+                               stmt_destroy(orderbycols);
+                               if (orderby)
+                                       stmt_destroy(orderby);
+                               orderby = NULL;
+                               break;
+                       }
                        if (orderby)
                                orderby = stmt_reorder(orderby, orderbycols, 
is_ascending(orderbycole));
                        else
                                orderby = stmt_order(orderbycols, 
is_ascending(orderbycole));
                }
-               psub = stmt_ordered(orderby, psub);
+               if (orderby)
+                       psub = stmt_ordered(orderby, psub);
        }
        if (sub) 
                stmt_destroy(sub);
@@ -1823,6 +1844,7 @@
                        groupby = grp_create(gbcol, groupby);
                }
        }
+       grp_done(groupby);
        /* now aggregate */
        l = create_stmt_list();
        aggrs = rel->exps;
@@ -1878,7 +1900,7 @@
 rel2bin_topn( mvc *sql, sql_rel *rel, list *refs)
 {
        list *newl;
-       int l = -1, o = 0;
+       wrd l = -1, o = 0;
        stmt *sub = NULL, *order = NULL;
        node *n;
 
@@ -2117,12 +2139,13 @@
                        sql_subaggr *sum;
                        stmt *count_sum = NULL;
                        sql_subfunc *or = 
sql_bind_func_result(sql->session->schema, "or", bt, bt, bt);
-                       stmt *ssum;
+                       stmt *ssum, *ss;
 
                        stmt *ins = stmt_dup(nth(inserts, 
c->c->colnr)->op2.stval);
                        group *g = grp_create(ins, NULL);
-                       stmt *ss = stmt_aggr(stmt_dup(g->grp), g, 
sql_dup_aggr(cnt), 1);
 
+                       grp_done(g);
+                       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, 1);
@@ -2659,6 +2682,7 @@
 
                                g = grp_create(upd, g);
                        }
+                       grp_done(g);
                        ss = stmt_aggr(stmt_dup(g->grp), grp_dup(g), 
sql_dup_aggr(cnt), 1);
                        grp_destroy(g);
                        /* (count(ss) <> sum(ss)) */
@@ -2717,6 +2741,7 @@
                        }
 
                        g = grp_create(upd, NULL);
+                       grp_done(g);
                        ss = stmt_aggr(stmt_dup(g->grp), g, sql_dup_aggr(cnt), 
1);
 
                        /* (count(ss) <> sum(ss)) */


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to