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

Modified Files:
        rel_exp.mx rel_optimizer.mx rel_select.mx sql_atom.mx 
        sql_optimize.mx sql_psm.mx sql_qc.mx sql_select.mx 
        sql_updates.mx 
Log Message:
fixes for the bugs 
1909638          sql prepare problem....
this needed a fix in query argument matching
1907006          range select....
0<id>10 is  now handled as select(0<id, TRUE)


Index: sql_select.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_select.mx,v
retrieving revision 1.225
retrieving revision 1.226
diff -u -d -r1.225 -r1.226
--- sql_select.mx       7 Mar 2008 09:45:35 -0000       1.225
+++ sql_select.mx       14 Mar 2008 12:55:22 -0000      1.226
@@ -39,7 +39,7 @@
 extern stmt *sql_reorder(stmt *order, stmt *s);
 
 extern stmt *sql_value_exp(mvc *sql, scope *scp, symbol *se, group *grp, stmt 
*subset, int f, exp_kind knd);
-extern stmt *sql_logical_exp(mvc *sql, scope *scp, symbol *sc, group *grp, 
stmt *subset, int f);
+extern stmt *sql_logical_exp(mvc *sql, scope *scp, symbol *sc, group *grp, 
stmt *subset, int f, exp_kind knd);
 extern stmt *stmt2pivot(scope *scp, stmt *s);
 
 extern stmt *sql_compare(mvc *sql, scope *scp, stmt *ls, stmt *rs, char 
*compare_op, int f, exp_kind ek);
@@ -571,7 +571,7 @@
                        if (opt_cond) {
                                cond = sql_compare_exp(sql, scp, grp, subset, 
opt_cond, when->h->data.sym, "=", sql_sel, ek);
                        } else {
-                               cond = sql_logical_exp(sql, scp, 
when->h->data.sym, grp, subset, sql_sel);
+                               cond = sql_logical_exp(sql, scp, 
when->h->data.sym, grp, subset, sql_sel, ek);
                        }
                        result = sql_value_exp(sql, scp, 
when->h->next->data.sym, grp, subset, f, ek);
                }
@@ -621,7 +621,7 @@
                        if (opt_cond) {
                                cond = sql_compare_exp(sql, scp, grp, subset, 
opt_cond, when->h->data.sym, "=", sql_sel, ek);
                        } else {
-                               cond = sql_logical_exp(sql, scp, 
when->h->data.sym, grp, subset, sql_sel);
+                               cond = sql_logical_exp(sql, scp, 
when->h->data.sym, grp, subset, sql_sel, ek);
                        }
                        result = sql_value_exp(sql, scp, 
when->h->next->data.sym, grp, subset, sql_sel, ek);
                }
@@ -875,7 +875,7 @@
        if (!s)
                s = sql->session->schema;
        /* input from different tables requires an extra cross-product! */
-       if (ls->nrcols > 0 && rs->nrcols > 0 && ls->h != rs->h) {
+       if (scp && ls->nrcols > 0 && rs->nrcols > 0 && ls->h != rs->h) {
                ls = stmt_join(scope_find_pivot(scp, ls->h), ls, cmp_equal);
                rs = stmt_join(scope_find_pivot(scp, rs->h), rs, cmp_equal);
        }
@@ -1754,7 +1754,7 @@
        case SQL_XMLTEXT:
                return sql_xml(sql, scp, se, grp, subset, f, ek);
        default:
-               return sql_logical_exp(sql, scp, se, grp, subset, f);
+               return sql_logical_exp(sql, scp, se, grp, subset, f, ek);
        }
        return NULL;
 }
@@ -1914,7 +1914,8 @@
                return sql_error(sql, 02, "SELECT: must have NATURAL JOIN or a 
JOIN with a join specification (ON or USING);");
 
        if (js && js->token != SQL_USING) {     /* On sql_logical_exp */
-               s = sql_logical_exp(sql, scp, js, NULL, NULL, sql_where);
+               exp_kind ek = {type_value, card_relation, TRUE };
+               s = sql_logical_exp(sql, scp, js, NULL, NULL, sql_where, ek);
        } else if (js) {        /* using */
                dnode *n = js->data.lval->h;
 
@@ -2784,7 +2785,7 @@
                if (ls->h && rs->h && ls->h == rs->h && ls->nrcols != 2) {
                        return stmt_uselect(ls, rs, type);
                }
-               if (ls->nrcols == 2 || rs->nrcols == 2) {
+               if (scp && (ls->nrcols == 2 || rs->nrcols == 2)) {
                        /* we have some implicit joins, ie lets filter */ 
                        if (ls->nrcols < rs->nrcols) {
                                ls = stmt_join(scope_find_pivot(scp, ls->h), 
ls, cmp_equal);
@@ -2917,7 +2918,7 @@
                                        stmt *p = find_pivot(subset, ls->h);
 
                                        ls = stmt_join(p, ls, cmp_equal);
-                               } else if (ls->nrcols) {
+                               } else if (scp && ls->nrcols) {
                                        stmt *p = scope_find_pivot(scp, ls->h);
 
                                        ls = stmt_join(p, ls, cmp_equal);
@@ -3144,9 +3145,9 @@
 }
 
 stmt *
-sql_logical_exp_(mvc *sql, scope *scp, symbol *sc, group *grp, stmt *subset, 
int f)
+sql_logical_exp_(mvc *sql, scope *scp, symbol *sc, group *grp, stmt *subset, 
int f, exp_kind ek)
 {
-       exp_kind ek = {type_value, card_column, FALSE};
+       exp_kind iek = {type_value, card_column, FALSE};
 
        if (!sc)
                return NULL;
@@ -3159,8 +3160,8 @@
        {
                symbol *lo = sc->data.lval->h->data.sym;
                symbol *ro = sc->data.lval->h->next->data.sym;
-               stmt *ls = sql_logical_exp(sql, scp, lo, grp, subset, f);
-               stmt *rs = sql_logical_exp(sql, scp, ro, grp, subset, f);
+               stmt *ls = sql_logical_exp(sql, scp, lo, grp, subset, f, ek);
+               stmt *rs = sql_logical_exp(sql, scp, ro, grp, subset, f, ek);
 
                return sql_or(sql, scp, ls, rs, f);
        }
@@ -3169,8 +3170,8 @@
        {
                symbol *lo = sc->data.lval->h->data.sym;
                symbol *ro = sc->data.lval->h->next->data.sym;
-               stmt *ls = sql_logical_exp(sql, scp, lo, grp, subset, f);
-               stmt *rs = sql_logical_exp(sql, scp, ro, grp, subset, f);
+               stmt *ls = sql_logical_exp(sql, scp, lo, grp, subset, f, ek);
+               stmt *rs = sql_logical_exp(sql, scp, ro, grp, subset, f, ek);
 
                return sql_and(sql, scp, ls, rs, f);
        }
@@ -3183,7 +3184,6 @@
 
                /* currently we don't handle the (universial and existential) 
                   quantifiers (all and any/some) */
-               ek.reduce = TRUE;
                return sql_compare_exp(sql, scp, grp, subset, lo, ro, 
compare_op, f, ek);
        }
                break;
@@ -3195,9 +3195,9 @@
                int symmetric = sc->data.lval->h->next->data.ival;
                symbol *ro1 = sc->data.lval->h->next->next->data.sym;
                symbol *ro2 = sc->data.lval->h->next->next->next->data.sym;
-               stmt *ls = sql_value_exp(sql, scp, lo, grp, subset, f, ek);
-               stmt *rs1 = sql_value_exp(sql, scp, ro1, grp, subset, f, ek);
-               stmt *rs2 = sql_value_exp(sql, scp, ro2, grp, subset, f, ek);
+               stmt *ls = sql_value_exp(sql, scp, lo, grp, subset, f, iek);
+               stmt *rs1 = sql_value_exp(sql, scp, ro1, grp, subset, f, iek);
+               stmt *rs2 = sql_value_exp(sql, scp, ro2, grp, subset, f, iek);
                sql_subtype *ct = NULL;
 
                if (!ls || !rs1 || !rs2)
@@ -3220,7 +3220,6 @@
                if (rs1->nrcols > 0 || rs2->nrcols > 0 || f == sql_sel) {
                        stmt *j1, *j2;
 
-                       ek.reduce = TRUE;
                        if (sc->token == SQL_NOT_BETWEEN) {
                                j1 = sql_compare(sql, scp, stmt_dup(ls), rs1, 
"<", f, ek);
                                j2 = sql_compare(sql, scp, stmt_dup(ls), rs2, 
">", f, ek);
@@ -3243,7 +3242,7 @@
                stmt *res = NULL;
                symbol *lo = sc->data.lval->h->data.sym;
                symbol *ro = sc->data.lval->h->next->data.sym;
-               stmt *ls = sql_value_exp(sql, scp, lo, grp, subset, f, ek);
+               stmt *ls = sql_value_exp(sql, scp, lo, grp, subset, f, iek);
                stmt *a = NULL, *e = NULL;
                sql_subtype *st = sql_bind_localtype("str");
                char *es = NULL;
@@ -3258,8 +3257,8 @@
 
                lo = ro->data.lval->h->data.sym;
                /* like uses a single string pattern */
-               ek.card = card_value;
-               a = sql_value_exp(sql, scp, lo, grp, subset, f, ek);
+               iek.card = card_value;
+               a = sql_value_exp(sql, scp, lo, grp, subset, f, iek);
 
                if (!a) {
                        stmt_destroy(ls);
@@ -3326,11 +3325,11 @@
        {
                dlist *l = sc->data.lval;
                symbol *lo = l->h->data.sym;
-               stmt *ls = sql_value_exp(sql, scp, lo, grp, subset, f, ek);
+               stmt *ls = sql_value_exp(sql, scp, lo, grp, subset, f, iek);
 
                if (!ls)
                        return NULL;
-               ek.card = card_set;
+               iek.card = card_set;
                if (l->h->next->type == type_list) {
                        dnode *n = l->h->next->data.lval->h;
                        sql_subtype *ct = tail_type(ls);
@@ -3338,7 +3337,7 @@
 
                        for (; n; n = n->next) {
                                symbol *sval = n->data.sym;
-                               stmt *v = sql_value_exp(sql, scp, sval, NULL, 
NULL, f, ek);
+                               stmt *v = sql_value_exp(sql, scp, sval, NULL, 
NULL, f, iek);
 
                                if (!v) {
                                        stmt_destroy(ls);
@@ -3381,9 +3380,8 @@
 
                                if (subset)
                                        cmp = stmt_join(find_pivot(subset, 
cmp->h), cmp, cmp_equal);
-                               else
+                               else if (scp)
                                        cmp = stmt_join(scope_find_pivot(scp, 
cmp->h), cmp, cmp_equal);
-                               ek.reduce = TRUE;
                                cmp = sql_compare(sql, scp, ls, cmp, comp, f, 
ek);
                                return cmp;
                        }
@@ -3446,7 +3444,7 @@
        case SQL_NOT_EXISTS:
        {
                symbol *lo = sc->data.sym;
-               stmt *ls = scope_subquery(sql, scp, lo, ek);
+               stmt *ls = scope_subquery(sql, scp, lo, iek);
 
                if (!ls)
                        return NULL;
@@ -3506,7 +3504,7 @@
        /* is (NOT) NULL */
        {
                symbol *cr = sc->data.sym;
-               stmt *res = sql_value_exp(sql, scp, cr, grp, subset, f, ek);
+               stmt *res = sql_value_exp(sql, scp, cr, grp, subset, f, iek);
 
                /* TODO predicate! */
                if (res && f == sql_sel) {
@@ -3538,7 +3536,7 @@
                break;
        case SQL_NOT: {
                symbol *lo = sc->data.sym;
-               stmt *ls = sql_logical_exp(sql, scp, lo, grp, subset, f);
+               stmt *ls = sql_logical_exp(sql, scp, lo, grp, subset, f, ek);
 
                if (!ls)
                        return NULL;
@@ -3590,9 +3588,9 @@
 }
 
 stmt *
-sql_logical_exp(mvc *sql, scope *scp, symbol *sc, group *grp, stmt *subset, 
int f)
+sql_logical_exp(mvc *sql, scope *scp, symbol *sc, group *grp, stmt *subset, 
int f, exp_kind ek)
 {
-       stmt *s = sql_logical_exp_(sql, scp, sc, grp, subset, f);
+       stmt *s = sql_logical_exp_(sql, scp, sc, grp, subset, f, ek);
 
        if (s && s->nrcols == 0 && f == sql_where) {
                /* predicate */
@@ -3692,12 +3690,13 @@
        dnode *n = NULL;
        node *m;
        int aggr = 0;
+       exp_kind ek = {type_value, card_relation, TRUE};
 
        if (!sn->selection) 
                return sql_error(sql, 02, "SELECT: '*' not allowed without 
FROM");
                
        if (sn->where) {
-               s = sql_logical_exp(sql, scp, sn->where, NULL, NULL, sql_where);
+               s = sql_logical_exp(sql, scp, sn->where, NULL, NULL, sql_where, 
ek);
                if (!s)
                        return NULL;
                subset = s;
@@ -3835,6 +3834,7 @@
 {
        list *rl = NULL;
        stmt *s = NULL;
+       exp_kind iek = {type_value, card_relation, TRUE};
 
        stmt *order = NULL, *subset = NULL;
        group *grp = NULL;
@@ -3843,7 +3843,7 @@
                return sql_simple_select(sql, scp, sn);
 
        if (sn->where) {
-               s = sql_logical_exp(sql, scp, sn->where, NULL, NULL, sql_where);
+               s = sql_logical_exp(sql, scp, sn->where, NULL, NULL, sql_where, 
iek);
                if (!s) {
                        sql_select_cleanup(sql, s, subset, grp);
                        return sql_error(sql, 02, "SELECT: subquery result 
missing");
@@ -3925,7 +3925,7 @@
                if (!grp)
                        ss = ptable_parent(subset);
 
-               t = sql_logical_exp(sql, scp, sn->having, grp, ss, sql_having);
+               t = sql_logical_exp(sql, scp, sn->having, grp, ss, sql_having, 
iek);
                if (!t) {
                        sql_select_cleanup(sql, s, subset, grp);
                        return sql_error(sql, 02, "SELECT: subquery result 
missing");

Index: sql_updates.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_updates.mx,v
retrieving revision 1.133
retrieving revision 1.134
diff -u -d -r1.133 -r1.134
--- sql_updates.mx      18 Feb 2008 10:52:08 -0000      1.133
+++ sql_updates.mx      14 Mar 2008 12:55:24 -0000      1.134
@@ -1565,6 +1565,7 @@
                dnode *n;
                list *l;
                stmt **updates, *rows_affected;
+               exp_kind ek = {type_value, card_column, TRUE};
 
                scp = scope_open(scp);
                if (temp_table) 
@@ -1573,7 +1574,7 @@
                        tv = scope_add_table_columns(sql, scp, t, t->base.name, 
RDONLY);
 
                if (opt_where) {
-                       s = sql_logical_exp(sql, scp, opt_where, NULL, NULL, 
sql_where);
+                       s = sql_logical_exp(sql, scp, opt_where, NULL, NULL, 
sql_where, ek);
                        if (s && s->type != st_set && s->type != st_sets) {
                                s = stmt_set(s);
                        }
@@ -1906,6 +1907,7 @@
        } else {
                tvar *tv = NULL;
                stmt *s = NULL;
+               exp_kind ek = {type_value, card_column, TRUE};
 
                scp = scope_open(scp);
                if (temp_table) 
@@ -1914,7 +1916,7 @@
                        tv = scope_add_table_columns(sql, scp, t, t->base.name, 
RDONLY);
                if (opt_where) {
                        stmt *subset = NULL;
-                       s = sql_logical_exp(sql, scp, opt_where, NULL, NULL, 
sql_where);
+                       s = sql_logical_exp(sql, scp, opt_where, NULL, NULL, 
sql_where, ek);
                        if (s && s->type == st_filter) { /* filter on table ? */
                                ptable_statements(scp->ptable) = stmt_set(s);
                                s = stmt_dup(scope_first_column(scp)->s);

Index: rel_select.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/rel_select.mx,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -d -r1.68 -r1.69
--- rel_select.mx       8 Mar 2008 07:27:02 -0000       1.68
+++ rel_select.mx       14 Mar 2008 12:55:17 -0000      1.69
@@ -351,8 +351,10 @@
 rel_bind_path(sql_rel *rel, sql_exp *e )
 {
        list *path = new_rel_list(); 
+
+       if (e->type == e_convert) 
+               e = e->l;
        if (e->type == e_column) {
-       
                if (rel) {
                        if (!rel_bind_path_(rel, e, path)) {
                                /* something is wrong */
@@ -1718,7 +1720,7 @@
                }
                e = exp_compare( ls, rs, type );
        } else {
-               e = exp_like( ls, rs, esc, type );
+               e = exp_compare2( ls, rs, esc, type );
        }
 
        /* atom or row => select */

Index: sql_atom.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_atom.mx,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- sql_atom.mx 11 Jan 2008 10:52:11 -0000      1.57
+++ sql_atom.mx 14 Mar 2008 12:55:18 -0000      1.58
@@ -44,6 +44,7 @@
 extern atom *atom_dec( sql_subtype *tpe, lng val, double dval);
 
 extern int atom_neg( atom *a );
+extern unsigned int atom_num_digits( atom *a );
 
 /* duplicate atom */
 extern atom *atom_dup( atom *a);
@@ -409,7 +410,7 @@
        return na;
 }
 
-static unsigned int
+unsigned int
 atom_num_digits( atom *a ) 
 {
        lng v = 0;

Index: sql_optimize.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_optimize.mx,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -d -r1.90 -r1.91
--- sql_optimize.mx     27 Jan 2008 15:40:08 -0000      1.90
+++ sql_optimize.mx     14 Mar 2008 12:55:18 -0000      1.91
@@ -249,6 +249,8 @@
                        return -20;
                else if (s->flag == cmp_equal)
                        return select_count(s->op1.stval) + 20; /* point */
+               else if (s->flag == cmp_notequal)
+                       return select_count(s->op1.stval) + 10; /* point */
                else if (s->flag == cmp_like || s->flag == cmp_notlike)
                        return select_count(s->op1.stval) + 2;  /* like==scan */
                /* ranges */

Index: rel_exp.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/rel_exp.mx,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- rel_exp.mx  8 Mar 2008 07:27:01 -0000       1.8
+++ rel_exp.mx  14 Mar 2008 12:55:15 -0000      1.9
@@ -32,7 +32,7 @@
 extern void exp_destroy(sql_exp* e);
 
 extern sql_exp *exp_compare( sql_exp *l, sql_exp *r, int cmptype);
-extern sql_exp *exp_like( sql_exp *l, sql_exp *r, sql_exp *esc, int like);
+extern sql_exp *exp_compare2( sql_exp *l, sql_exp *r, sql_exp *h, int cmptype);
 
 #define exp_fromtype(e)        ((list*)e->r)->h->data
 #define exp_totype(e)  ((list*)e->r)->h->next->data
@@ -166,15 +166,15 @@
 }
 
 sql_exp * 
-exp_like( sql_exp *l, sql_exp *r, sql_exp *esc, int like) 
+exp_compare2( sql_exp *l, sql_exp *r, sql_exp *h, int cmptype) 
 {
        sql_exp *e = exp_create(e_cmp);
        e->card = l->card;
        e->l = l;
        e->r = r;
-       if (esc)
-               e->f = esc;
-       e->flag = like;
+       if (h)
+               e->f = h;
+       e->flag = cmptype;
        return e;
 }
 

Index: sql_qc.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_qc.mx,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- sql_qc.mx   11 Jan 2008 10:52:11 -0000      1.43
+++ sql_qc.mx   14 Mar 2008 12:55:22 -0000      1.44
@@ -87,6 +87,7 @@
 
 #include "sql_qc.h"
 #include "sql_scope.h"
+#include "sql_atom.h"
 
 qc *
 qc_create(int clientid)
@@ -175,34 +176,34 @@
        if (!typelist || !atoms)
                return -1;
        for (i=0; i < plen; i++) {
-               sql_subtype *t1 = typelist + i;
-               atom *a2 = atoms[i];
+               sql_subtype *tp = typelist + i;
+               atom *a = atoms[i];
 
                /* NULL values match any type */
-               if (!atom_null(a2) && param_cmp(t1, atom_type(a2)) != 0) {
-                       sql_subtype *at = atom_type(a2);
+               if (!atom_null(a) && param_cmp(tp, atom_type(a)) != 0) {
+                       sql_subtype *at = atom_type(a);
 
                        /* FLT == DEC/NUM and DEC/NUM are equal */
-                       if ((!(t1->type->eclass == EC_FLT && 
-                           (at->type->eclass == EC_DEC ||
-                            at->type->eclass == EC_NUM))) &&
-                          (!(EC_VARCHAR(t1->type->eclass) &&
-                             EC_VARCHAR(atom_type(a2)->type->eclass) &&
-                             (!t1->digits ||
-                              t1->digits >= atom_type(a2)->digits))) &&
-                          (!(t1->type->eclass == EC_DEC &&
+                       if ((!((at->type->eclass == EC_DEC ||
+                               at->type->eclass == EC_NUM) &&
+                              tp->type->eclass == EC_FLT)) &&
+                          (!(EC_VARCHAR(tp->type->eclass) &&
+                             EC_VARCHAR(at->type->eclass) &&
+                             (!tp->digits ||
+                              tp->digits >= at->digits))) &&
+                          (!(tp->type->eclass == EC_DEC &&
                              at->type->eclass == EC_NUM &&
-                             t1->type->localtype >= at->type->localtype)) &&
+                             tp->type->localtype >= at->type->localtype &&
+                            (at->digits <= tp->digits || atom_num_digits(a) <= 
tp->digits) && at->scale <= tp->scale)) &&
                        /*
-                          (!(t1->type->eclass == EC_DEC &&
+                          (!(tp->type->eclass == EC_DEC &&
                              at->type->eclass == EC_DEC &&
-                             t1->type->localtype >= at->type->localtype &&
-                             at->digits <= t1->digits &&
-                             at->scale <= t1->scale)) &&
+                             tp->type->localtype >= at->type->localtype &&
+                             at->digits <= tp->digits &&
+                             at->scale <= tp->scale)) &&
                        */
-                          (!(t1->type->eclass == EC_NUM &&
-                             atom_type(a2)->type->eclass == EC_NUM &&
-                              t1->type->localtype >= 
atom_type(a2)->type->localtype)))
+                          (!(at->type->eclass == EC_NUM && tp->type->eclass == 
EC_NUM && 
+                             at->type->localtype <= tp->type->localtype)))
                                return -1;
                }
        }

Index: sql_psm.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_psm.mx,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- sql_psm.mx  7 Mar 2008 09:45:34 -0000       1.51
+++ sql_psm.mx  14 Mar 2008 12:55:20 -0000      1.52
@@ -195,8 +195,9 @@
        if (w->type == type_symbol) { 
                stmt *cond, *whilestmts;
                dnode *n = w;
+               exp_kind ek = {type_value, card_value, FALSE};
 
-               cond = sql_logical_exp(sql, scp, n->data.sym, NULL, NULL, 
sql_sel); 
+               cond = sql_logical_exp(sql, scp, n->data.sym, NULL, NULL, 
sql_sel, ek); 
                n = n->next;
                whilestmts = sequential_block(sql, scp, res, n->data.lval, 
n->next->data.sval, is_func);
 
@@ -224,8 +225,9 @@
        if (elseif->next && elseif->type == type_symbol) { /* if or elseif */
                stmt *cond, *ifstmts, *elsestmts;
                dnode *n = elseif;
+               exp_kind ek = {type_value, card_value, FALSE };
 
-               cond = sql_logical_exp(sql, scp, n->data.sym, NULL, NULL, 
sql_sel); 
+               cond = sql_logical_exp(sql, scp, n->data.sym, NULL, NULL, 
sql_sel, ek); 
                n = n->next;
                ifstmts = sequential_block(sql, scp, res, n->data.lval, NULL, 
is_func);
                n = n->next;
@@ -328,7 +330,7 @@
                n = whenlist->h;
                while(n) {
                        dnode *m = n->data.sym->data.lval->h;
-                       stmt *cond = sql_logical_exp(sql, scp, m->data.sym, 
NULL, NULL, sql_sel);
+                       stmt *cond = sql_logical_exp(sql, scp, m->data.sym, 
NULL, NULL, sql_sel, ek);
                        stmt *if_stmts = NULL;
                        stmt *case_stmt = NULL;
 
@@ -450,24 +452,30 @@
 }
 
 static sql_subtype *
-result_type(mvc *sql, char *fname, symbol *res ) 
+result_type(mvc *sql, char *fname, symbol *res, int instantiate ) 
 {
        if (res->token == SQL_TYPE) {
                return &res->data.lval->h->data.typeval;
        } else if (res->token == SQL_TABLE) {
-
                /* here we create a new table-type */
                sql_subtype *t = NEW(sql_subtype);
                sql_table *tbl;
-               dnode *n = res->data.lval->h;
                char *tnme = NEW_ARRAY(char, strlen(fname) + 2);
 
                tnme[0] = '#';
                strcpy(tnme+1, fname);
-               tbl = mvc_create_generated(sql, sql->session->schema, tnme, 
NULL, 1 /* system ?*/);
-               for(;n; n = n->next->next) {
-                       sql_subtype *ct = &n->next->data.typeval;
-                       mvc_create_column(sql, tbl, n->data.sval, ct);
+               if (instantiate) {
+                       tbl = mvc_bind_table(sql, sql->session->schema, tnme);
+                       if (!tbl)
+                               return NULL;
+               } else {
+                       dnode *n = res->data.lval->h;
+
+                       tbl = mvc_create_generated(sql, sql->session->schema, 
tnme, NULL, 1 /* system ?*/);
+                       for(;n; n = n->next->next) {
+                               sql_subtype *ct = &n->next->data.typeval;
+                               mvc_create_column(sql, tbl, n->data.sval, ct);
+                       }
                }
                _DELETE(tnme);
 
@@ -537,7 +545,7 @@
                s = cur_schema(sql);
 
        if (res)
-               restype = result_type(sql, fname, res);
+               restype = result_type(sql, fname, res, instantiate);
 
        if (params)
                type_list = create_type_list(params, 1);

Index: rel_optimizer.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/rel_optimizer.mx,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- rel_optimizer.mx    8 Mar 2008 07:27:01 -0000       1.12
+++ rel_optimizer.mx    14 Mar 2008 12:55:16 -0000      1.13
@@ -297,23 +297,28 @@
        case e_cmp:
                switch (e->flag) {
                case cmp_equal:
+                       *cnt += 20;
+                       return 20;
+               case cmp_notequal:
                        *cnt += 10;
                        return 10;
                case cmp_gt:
                case cmp_gte:
                case cmp_lt:
                case cmp_lte:
+                       *cnt += 4;
+                       return 4;
                case cmp_like:
                case cmp_notlike:
-                       *cnt += 1;
-                       return 1;
+                       *cnt += 2;
+                       return 2;
                default:
                        return 0;
                }
        default:
-               return 0;
+               return -5;
        }
-       return 0;
+       return -5;
 }
 
 static int
@@ -834,7 +839,7 @@
                return e;
        case e_cmp: 
                if (e->f) 
-                       return exp_like( exp_push_down(sql, e->l, f, t), 
exp_push_down(sql, e->r, f, t), exp_push_down(sql, e->f, f, t), e->flag);
+                       return exp_compare2( exp_push_down(sql, e->l, f, t), 
exp_push_down(sql, e->r, f, t), exp_push_down(sql, e->f, f, t), e->flag);
                else
                        return exp_compare( exp_push_down(sql, e->l, f, t), 
exp_push_down(sql, e->r, f, t), e->flag);
        case e_convert:


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to