Update of /cvsroot/monetdb/sql/src/server
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv28111/src/server

Modified Files:
        rel_select.mx 
Log Message:
propagated changes of Thursday Feb 05 2009 - Friday Feb 06 2009
from the Feb2009 branch to the development trunk

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2009/02/05 - nielsnes: src/server/rel_select.mx,1.113.2.3
fix the in operator in the selection phase
fix naming of group by expressions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2009/02/05 - nielsnes: src/server/rel_select.mx,1.113.2.4
fixed bug in in handling in selection
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2009/02/06 - nielsnes: src/server/rel_select.mx,1.113.2.5
Improved performance, ie handle single value case special
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Index: rel_select.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/rel_select.mx,v
retrieving revision 1.115
retrieving revision 1.116
diff -u -d -r1.115 -r1.116
--- rel_select.mx       3 Feb 2009 09:33:49 -0000       1.115
+++ rel_select.mx       6 Feb 2009 13:01:19 -0000       1.116
@@ -549,7 +549,7 @@
        rel->r = NULL;
        rel->op = op_project;
        rel->exps = e;
-       rel->card = CARD_MULTI; 
+       rel->card = l?CARD_MULTI:CARD_ATOM; 
        if (l) {
                rel->card = l->card;
                rel->nrcols = l->nrcols;
@@ -637,7 +637,7 @@
 
 static sql_exp *rel_groupby_add_aggr(mvc *sql, sql_rel *rel, sql_exp *e)
 {
-       sql_exp *m = NULL;
+       sql_exp *m = NULL, *ne;
        char name[16], *nme = NULL;
        char *tname = NULL;
 
@@ -651,7 +651,9 @@
        }
        if (e->type == e_column)
                tname = e->l;
-       return exp_column(tname, m->name, exp_subtype(m), rel->card, 
has_nil(m), is_intern(m));
+       ne = exp_column(tname, m->name, exp_subtype(m), rel->card, has_nil(m), 
is_intern(m));
+       exp_setname(ne, NULL, e->name);
+       return ne;
 }
 
 void 
@@ -1981,15 +1983,22 @@
                dlist *dl = sc->data.lval;
                symbol *lo = dl->h->data.sym;
                dnode *n = dl->h->next;
-               sql_exp *l = rel_value_exp(sql, rel, lo, f, ek);
+               sql_exp *l = rel_value_exp(sql, rel, lo, f, ek), *r = NULL;
                sql_rel *left = NULL, *right = NULL, *p = NULL;
+               int needproj = 0;
 
                if (!l)
                        return NULL;
 
                ek.card = card_set;
 
-               /* we assume the selection case */
+               /* only selection phase ! */
+               if (f < sql_sel)
+                       assert(0);
+
+               if (!left) 
+                       left = *rel;
+/*
                if (f >= sql_sel) { 
                        if (left && is_project(left->op)) {
                                p = left;
@@ -2000,16 +2009,13 @@
                                left = left->l;
                        }
                } 
-               if (!left) 
+*/
+               if (!left || !left->l) {
+                       needproj = (left != NULL);
                        left = rel_project_exp(l);
-               else 
+               } else 
                        left = rel_dup(left);
-               if (!p)
-                       p = *rel;
-               l = exp_alias_or_copy(sql, NULL, NULL, left, l, 0);
-               /* list of values or subqueries */
 
-               /* single element could be a 'select' */
                if (n->type == type_list) {
                        sql_subtype *st = exp_subtype(l);
 
@@ -2017,10 +2023,9 @@
                        for (; n; n = n->next) {
                                symbol *sval = n->data.sym;
                                /* without correlation first */
-                               sql_rel *z = NULL;
-                               sql_exp *r = rel_value_exp(sql, &z, sval, f, 
ek);
-                               sql_rel *rl;
+                               sql_rel *z = NULL, *rl;
 
+                               r = rel_value_exp(sql, &z, sval, f, ek);
                                if (!r || !(r=rel_check_type(sql, st, r, 
type_equal))) {
                                        if (r)
                                                exp_destroy(r);
@@ -2048,22 +2053,38 @@
                        return sql_error(sql, 02, "IN: missing inner query");
                }
                if (right) {
-                       sql_exp *r = NULL, *e;
+                       sql_exp *e;
 
+                       if (right->card == CARD_ATOM) {
+                               if (sc->token == SQL_NOT_IN) 
+                                       e = rel_binop_(sql, l, r, NULL, "!=");
+                               else
+                                       e = rel_binop_(sql, l, r, NULL, "=");
+                               return e;
+                       }
                        r = rel_lastexp(sql, right);
                        rel_setsubquery(right);
-                       if (p)
-                               rel_destroy(p->l);
                        if (rel_convert_types(sql, &l, &r, 1, type_equal) < 0) {
                                exp_destroy(l);
                                exp_destroy(r);
                                return NULL;
                        }
-                       left = p->l = rel_crossproduct(left, right, op_join);
+                       left = rel_crossproduct(left, right, op_join);
+                       if (p) {
+                               rel_destroy(p->l);
+                               p->l = left;
+                       }
                        left->op = op_left;
                        e = exp_compare( l, r, cmp_equal );
                        rel_join_add_exp(left, e);
-                       l = rel_unop_(sql, l, NULL, "isnull");
+                       if (!p) {
+                               if (*rel && needproj) 
+                                       left = *rel = rel_project(left, NULL);
+                               else 
+                                       *rel = left;
+                       }
+                       e = rel_binop_(sql, l, r, NULL, "=");
+                       l = rel_unop_(sql, e, NULL, "isnull");
                        if (sc->token == SQL_NOT_IN) 
                                r = exp_atom_bool(1);
                        else


------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to