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

Modified Files:
      Tag: SQL_2-24
        rel_bin.mx sql_parser.mx sql_select.mx 
Log Message:
fix bug in handling aggregates over single values


U rel_bin.mx
Index: rel_bin.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/rel_bin.mx,v
retrieving revision 1.42.2.1
retrieving revision 1.42.2.2
diff -u -d -r1.42.2.1 -r1.42.2.2
--- rel_bin.mx  27 May 2008 20:44:03 -0000      1.42.2.1
+++ rel_bin.mx  13 Jun 2008 21:26:55 -0000      1.42.2.2
@@ -241,13 +241,21 @@
                        as = exp_bin(sql, attr->h->data, left, right, NULL, 
sel);
                        if (list_length(attr) == 2)
                                as2 = exp_bin(sql, attr->h->next->data, left, 
right, NULL, sel);
+                       /* insert single value into a column */
+                       if (as && as->nrcols <= 0 && !left)
+                               as = stmt_append(stmt_temp(tail_type(as)), as);
                } else {
                        /* count(*) may need the default group (relation) and
                           and/or an attribute to count */
-                       if (g)
+                       if (g) {
                                as = stmt_dup(grp->grp);
-                       else
+                       } else if (left) {
                                as = bin_first_column(left);
+                       } else {
+                               /* create dummy single value in a column */
+                               as = stmt_atom_int(0);
+                               as = stmt_append(stmt_temp(tail_type(as)), as);
+                       }
                }
                if (!as) 
                        return NULL;    
@@ -1262,11 +1270,12 @@
        group *groupby = NULL;
 
 
-       if (rel->l) /* first construct the sub relation */
+       if (rel->l) { /* first construct the sub relation */
                sub = subrel_bin(sql, rel->l);
-       if (!sub) { 
-               assert(0);
-               return NULL;    
+               if (!sub) { 
+                       assert(0);
+                       return NULL;    
+               }
        }
 
        /* groupby columns */
@@ -1312,7 +1321,7 @@
                aggrstmt = stmt_rename(rel, aggrexp, aggrstmt);
                list_append(l, aggrstmt);
        }
-       stmt_destroy(sub);
+       if (sub) stmt_destroy(sub);
        if (groupby) grp_destroy(groupby);
        return cursub;
 }

U sql_parser.mx
Index: sql_parser.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_parser.mx,v
retrieving revision 1.283
retrieving revision 1.283.2.1
diff -u -d -r1.283 -r1.283.2.1
--- sql_parser.mx       22 May 2008 12:57:41 -0000      1.283
+++ sql_parser.mx       13 Jun 2008 21:26:55 -0000      1.283.2.1
@@ -3536,19 +3536,19 @@
                  append_int(l, TRUE);
                  append_symbol(l, _symbol_create_list(SQL_COLUMN, $4));
                  $$ = _symbol_create_list( SQL_AGGR, l ); }
- |  AGGR '(' DISTINCT scalar_exp ')'
+ |  AGGR '(' DISTINCT case_scalar_exp ')'
                { dlist *l = L();
                  append_string(l, $1);
                  append_int(l, FALSE);
                  append_symbol(l, $4);
                  $$ = _symbol_create_list( SQL_AGGR, l ); }
- |  AGGR '(' ALL scalar_exp ')'
+ |  AGGR '(' ALL case_scalar_exp ')'
                { dlist *l = L();
                  append_string(l, $1);
                  append_int(l, FALSE);
                  append_symbol(l, $4);
                  $$ = _symbol_create_list( SQL_AGGR, l ); }
- |  AGGR '(' scalar_exp ')'
+ |  AGGR '(' case_scalar_exp ')'
                { dlist *l = L();
                  append_string(l, $1);
                  append_int(l, FALSE);

U sql_select.mx
Index: sql_select.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_select.mx,v
retrieving revision 1.231.2.5
retrieving revision 1.231.2.6
diff -u -d -r1.231.2.5 -r1.231.2.6
--- sql_select.mx       3 Jun 2008 09:47:00 -0000       1.231.2.5
+++ sql_select.mx       13 Jun 2008 21:26:55 -0000      1.231.2.6
@@ -1204,8 +1204,11 @@
                /* the values which are aggregated together, no grp should
                 * be given there to optain the values */
                s = sql_value_exp(sql, scp, l->h->next->next->data.sym, /*grp 
*/ NULL, subset, f, ek);
-               if (s && s->nrcols <= 0 && subset) /* single value */
+               if (s && s->nrcols <= 0 && subset) { /* single value */
                        s = stmt_const(first_subset(subset), s);
+               } else if (s && s->nrcols <=0) { /* single value */
+                       s = stmt_append(stmt_temp(tail_type(s)), s);
+               }
        }
 
        if (s && distinct) {


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to