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

Modified Files:
      Tag: Aug2009
        bin_optimizer.mx rel_bin.mx rel_select.mx sql_parser.mx 
        sql_rel2bin.mx sql_statement.mx 
Log Message:
solved bug in handling not (i)like
allow '*' in selection with other (constant) column expressions 


U sql_rel2bin.mx
Index: sql_rel2bin.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_rel2bin.mx,v
retrieving revision 1.137
retrieving revision 1.137.2.1
diff -u -d -r1.137 -r1.137.2.1
--- sql_rel2bin.mx      2 Aug 2009 13:06:57 -0000       1.137
+++ sql_rel2bin.mx      3 Aug 2009 18:25:23 -0000       1.137.2.1
@@ -917,7 +917,7 @@
                stmt *op2 = stmt_dup( select->op2.stval);
 
                if (cmp == cmp_like || cmp == cmp_notlike ||
-                               cmp == cmp_ilike || cmp == cmp_notilike)
+                   cmp == cmp_ilike || cmp == cmp_notilike)
                {
                        stmt *op3 = stmt_dup(select->op3.stval);
 

U sql_statement.mx
Index: sql_statement.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_statement.mx,v
retrieving revision 1.189
retrieving revision 1.189.2.1
diff -u -d -r1.189 -r1.189.2.1
--- sql_statement.mx    2 Aug 2009 19:56:40 -0000       1.189
+++ sql_statement.mx    3 Aug 2009 18:25:23 -0000       1.189.2.1
@@ -1551,7 +1551,7 @@
        stmt *s = stmt_create(st_uselect);
 
        assert(cmptype != cmp_like && cmptype != cmp_notlike &&
-                       cmptype != cmp_ilike && cmptype != cmp_notilike);
+              cmptype != cmp_ilike && cmptype != cmp_notilike);
        s->op1.stval = op1;
        s->op2.stval = op2;
        s->flag = cmptype;
@@ -2792,7 +2792,7 @@
        case st_select:
        case st_uselect: 
                        if (s->flag == cmp_like || s->flag == cmp_notlike ||
-                                       s->flag == cmp_ilike || s->flag == 
cmp_notilike)
+                           s->flag == cmp_ilike || s->flag == cmp_notilike)
                                dump3(s, "likeselect", nr);
                        else
                                dump2(s, "select", nr);

U bin_optimizer.mx
Index: bin_optimizer.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/bin_optimizer.mx,v
retrieving revision 1.19
retrieving revision 1.19.2.1
diff -u -d -r1.19 -r1.19.2.1
--- bin_optimizer.mx    1 Aug 2009 14:47:37 -0000       1.19
+++ bin_optimizer.mx    3 Aug 2009 18:25:23 -0000       1.19.2.1
@@ -190,7 +190,7 @@
 
        if (select->type == st_select) {
                if (select->flag == cmp_like || select->flag == cmp_notlike ||
-                               select->flag == cmp_ilike || select->flag == 
cmp_notilike)
+                   select->flag == cmp_ilike || select->flag == cmp_notilike)
                        return stmt_likeselect(s, stmt_dup(select->op2.stval),
                                        stmt_dup(select->op3.stval), 
(comp_type)select->flag);
                else

U rel_select.mx
Index: rel_select.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/rel_select.mx,v
retrieving revision 1.152
retrieving revision 1.152.2.1
diff -u -d -r1.152 -r1.152.2.1
--- rel_select.mx       2 Aug 2009 13:06:56 -0000       1.152
+++ rel_select.mx       3 Aug 2009 18:25:23 -0000       1.152.2.1
@@ -246,6 +246,13 @@
        if (!rel)
                return NULL;
 
+       if (!tname) {
+               if (is_project(rel->op))
+                       return rel_projections(sql, rel->l, NULL, 1, 0);
+               else    
+                       return NULL;
+       }
+
        switch(rel->op) {
        case op_join:
        case op_left:
@@ -2286,10 +2293,12 @@
                                return rel_nop_(sql, le, re, ee, NULL, NULL, 
like, 0);
                        return rel_binop_(sql, le, re, NULL, like, 0);
                } else {
-                       char *notlike = insensitive ? "not_ilike" : "not_like";
+                       char *like = insensitive ? "ilike" : "like";
                        if (ee)
-                               return rel_nop_(sql, le, re, ee, NULL, NULL, 
notlike, 0);
-                       return rel_binop_(sql, le, re, NULL, notlike, 0);
+                               le = rel_nop_(sql, le, re, ee, NULL, NULL, 
like, 0);
+                       else
+                               le = rel_binop_(sql, le, re, NULL, like, 0);
+                       return rel_unop_(sql, le, NULL, "not", 0); 
                }
        }
        case SQL_BETWEEN:
@@ -4237,6 +4246,7 @@
 static sql_rel *
 rel_select_exp(mvc *sql, sql_rel *rel, sql_rel *outer, SelectNode *sn, 
exp_kind ek)
 {
+       dnode *n;
        int aggr = 0;
        list *jexps = NULL;
        list *pre_prj = NULL;
@@ -4244,6 +4254,9 @@
        sql_rel *inner = NULL;
        int decorrelated = 0;
 
+       if (!sn->selection)
+               return sql_error(sql, 02, "SELECT: the selection or from part 
is missing");
+
        if (!sn->from)
                return rel_simple_select(sql, rel, sn->where, sn->selection, 
sn->distinct);
 
@@ -4351,90 +4364,70 @@
                aggr = 1;
        }
 
-       if (sn->selection) {
-               dnode *n = sn->selection->h;
-
-               if (!outer || (!decorrelated && ek.card == card_set)) {
-                       if (outer) /* for non decorrelated or card_set sub
-                                                 queries we project all of the 
outer */
-                               rel = rel_project(rel, 
-                                       rel_projections(sql, outer, NULL, 1, 
1));
-                       else
-                               rel = rel_project(rel, new_exp_list());
-               }
-               if (!inner)
-                       inner = rel;
-               for (; n; n = n->next) {
-                       /* Here we could get real column expressions 
-                        * (including single atoms) but also table results. 
-                        * Therefor we try both rel_column_exp 
-                        * and rel_table_exp.
+       n = sn->selection->h;
+       if (!outer || (!decorrelated && ek.card == card_set)) {
+               if (outer) /* for non decorrelated or card_set sub
+                             queries we project all of the outer */
+                       rel = rel_project(rel, 
+                               rel_projections(sql, outer, NULL, 1, 1));
+               else
+                       rel = rel_project(rel, new_exp_list());
+       }
+       if (!inner)
+               inner = rel;
+       for (; n; n = n->next) {
+               /* Here we could get real column expressions 
+                * (including single atoms) but also table results. 
+                * Therefor we try both rel_column_exp 
+                * and rel_table_exp.
 
-                        * TODO 
-                               the rel_table_exp should simply return a new 
-                               relation
-                        */
-                       list *te = NULL; 
-                       sql_rel *o_inner = inner;
-                       sql_exp *ce = rel_column_exp(sql, &inner, n->data.sym, 
sql_sel);
+                * TODO 
+                       the rel_table_exp should simply return a new 
+                       relation
+                */
+               list *te = NULL; 
+               sql_rel *o_inner = inner;
+               sql_exp *ce = rel_column_exp(sql, &inner, n->data.sym, sql_sel);
 
-                       if (inner != o_inner) /* relation got rewritten */
-                               rel = inner;
+               if (inner != o_inner) /* relation got rewritten */
+                       rel = inner;
 
-                       if (ce && exp_subtype(ce)) {
-                               if (rel->card < ce->card) {
-                                       /* This doesn't work without 
de-correlations, ie in that case it should be done later */
-                                       if (outer) {
-                                               sql_subaggr *zero_or_one = 
sql_bind_aggr(sql->session->schema, "zero_or_one", exp_subtype(ce));
+               if (ce && exp_subtype(ce)) {
+                       if (rel->card < ce->card) {
+                               /* This doesn't work without de-correlations, 
ie in that case it should be done later */
+                               if (outer) {
+                                       sql_subaggr *zero_or_one = 
sql_bind_aggr(sql->session->schema, "zero_or_one", exp_subtype(ce));
 
-                                               ce = exp_aggr1(ce, zero_or_one, 
0, 0, rel->card, 0);
-                               
-                                       } else if (ce->name) {
-                                               return sql_error(sql, 02, 
"SELECT: cannot use non GROUP BY column '%s' in query results without an 
aggregate function", ce->name);
-                                       } else {
-                                               return sql_error(sql, 02, 
"SELECT: cannot use non GROUP BY column in query results without an aggregate 
function");
-                                       }
+                                       ce = exp_aggr1(ce, zero_or_one, 0, 0, 
rel->card, 0);
+                               } else if (ce->name) {
+                                       return sql_error(sql, 02, "SELECT: 
cannot use non GROUP BY column '%s' in query results without an aggregate 
function", ce->name);
+                               } else {
+                                       return sql_error(sql, 02, "SELECT: 
cannot use non GROUP BY column in query results without an aggregate function");
                                }
-                               /* 
-                                  because of the selection, the inner
-                                  relation may change.
-                                  We try hard to keep a projection
-                                  around this inner relation.
-                               */
-                               rel_project_add_exp(sql, inner, ce);
-                               rel = inner;
-                               continue;
-                       } else if (!ce) {
-                               te = rel_table_exp(sql, rel, n->data.sym);
-                       } else {
-                               exp_destroy(ce);
-                               ce = NULL;
                        }
-                       if (!ce && !te) 
-                               return sql_error(sql, 02, "SELECT: subquery 
result missing");
-                       /* here we should merge the column expressions we 
-                        * obtained sofar with the table expression, ie 
-                        * t1.* or a subquery.
-                        */
-                       list_merge( rel->exps, te, (fdup)&exp_dup);
-                       list_destroy(te);
-               }
-       } else {
-               /* select * from tables */
-               if (aggr) {
-                       rel_destroy(rel);
-                       return sql_error(sql, 02, "SELECT: cannot combine '*' 
with GROUP BY");
-               }
-
-               if (!outer && !is_project(rel->op)) {
-                       rel = rel_project(rel, rel_projections(sql, rel, NULL, 
1, 0));
-               } else if (!outer && is_project(rel->op)) {
-                       rel_remove_internal_exp(rel);
-               } else {
                        /* 
-                        * subquery can only return one column
-                        */
+                          because of the selection, the inner
+                          relation may change.
+                          We try hard to keep a projection
+                          around this inner relation.
+                       */
+                       rel_project_add_exp(sql, inner, ce);
+                       rel = inner;
+                       continue;
+               } else if (!ce) {
+                       te = rel_table_exp(sql, rel, n->data.sym);
+               } else {
+                       exp_destroy(ce);
+                       ce = NULL;
                }
+               if (!ce && !te) 
+                       return sql_error(sql, 02, "SELECT: subquery result 
missing");
+               /* here we should merge the column expressions we 
+                * obtained sofar with the table expression, ie 
+                * t1.* or a subquery.
+                */
+               list_merge( rel->exps, te, (fdup)&exp_dup);
+               list_destroy(te);
        }
 
        if (sn->having) {

U sql_parser.mx
Index: sql_parser.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_parser.mx,v
retrieving revision 1.312
retrieving revision 1.312.2.1
diff -u -d -r1.312 -r1.312.2.1
--- sql_parser.mx       1 Aug 2009 14:47:45 -0000       1.312
+++ sql_parser.mx       3 Aug 2009 18:25:23 -0000       1.312.2.1
@@ -2930,7 +2930,6 @@
 
 selection:
     column_exp_commalist
- |  '*'                        { $$ = NULL; }
  ;
 
 table_exp:
@@ -3544,7 +3543,12 @@
  ;
 
 column_exp:
-    ident '.' '*'
+    '*'
+               { dlist *l = L();
+                 append_string(l, NULL);
+                 append_string(l, NULL);
+                 $$ = _symbol_create_list( SQL_TABLE, l ); }
+ |  ident '.' '*'
                { dlist *l = L();
                  append_string(l, $1);
                  append_string(l, NULL);

U rel_bin.mx
Index: rel_bin.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/rel_bin.mx,v
retrieving revision 1.87
retrieving revision 1.87.2.1
diff -u -d -r1.87 -r1.87.2.1
--- rel_bin.mx  2 Aug 2009 19:56:40 -0000       1.87
+++ rel_bin.mx  3 Aug 2009 18:25:23 -0000       1.87.2.1
@@ -523,7 +523,7 @@
 
                /* the escape character of like is in the right expression */
                if (e->flag == cmp_notlike || e->flag == cmp_like ||
-                               e->flag == cmp_notilike || e->flag == cmp_ilike)
+                   e->flag == cmp_notilike || e->flag == cmp_ilike)
                {
                        if (!e->f)
                                r2 = stmt_atom_string(_strdup(""));
@@ -539,8 +539,7 @@
                                char *likef = (e->flag == cmp_notilike || 
e->flag == cmp_ilike ?
                                        "ilike" : "like");
                                sql_subtype *s = sql_bind_localtype("str");
-                               sql_subfunc *like = 
sql_bind_func3(sql->session->schema,
-                                               likef, s, s, s);
+                               sql_subfunc *like = 
sql_bind_func3(sql->session->schema, likef, s, s, s);
                                list *ops = create_stmt_list();
 
                                assert(s && like);
@@ -549,7 +548,7 @@
                                list_append(ops, r);
                                list_append(ops, r2);
                                lstmt = stmt_Nop(stmt_list(ops), like);
-                               if (e->flag == cmp_notlike) {
+                               if (e->flag == cmp_notlike || e->flag == 
cmp_notilike) {
                                        sql_subtype *bt = 
sql_bind_localtype("bit");
                                        sql_subfunc *not = 
sql_bind_func(sql->session->schema,
                                                        "not", bt, NULL);


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to