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

Modified Files:
      Tag: SQL_2-22
        sql_psm.mx sql_select.mx sql_updates.mx 
Log Message:
backport of bug fix for range_select bugs (0<id>10)


Index: sql_psm.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_psm.mx,v
retrieving revision 1.50.2.1
retrieving revision 1.50.2.2
diff -u -d -r1.50.2.1 -r1.50.2.2
--- sql_psm.mx  6 Mar 2008 21:35:00 -0000       1.50.2.1
+++ sql_psm.mx  14 Mar 2008 17:08:18 -0000      1.50.2.2
@@ -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: sql_select.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_select.mx,v
retrieving revision 1.219.2.7
retrieving revision 1.219.2.8
diff -u -d -r1.219.2.7 -r1.219.2.8
--- sql_select.mx       14 Mar 2008 16:12:37 -0000      1.219.2.7
+++ sql_select.mx       14 Mar 2008 17:08:18 -0000      1.219.2.8
@@ -60,7 +60,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);
@@ -592,7 +592,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);
                }
@@ -642,7 +642,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);
                }
@@ -896,7 +896,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);
        }
@@ -1485,7 +1485,7 @@
 
                        /* fall back to column references, ie those not in
                           the selection result */
-                       if (!sc && !grp) {
+                       if (!sc && (!sel || !grp)) {
                                /* reset error */
                                sql->session->status = 0;
                                sql->errstr[0] = '\0';
@@ -1530,12 +1530,12 @@
        
        if (window_function->token == SQL_RANK) {
                aggrstr = window_function->data.sval;
-       } else { /* real aggr */
+       } else { /* window aggr function */
                aggrstr  = window_function->data.lval->h->data.sval;
        }
 
        if (grp && window_specification->h->data.sym) 
-               return sql_error(sql, 02, "OVER: not allowed in combination 
with GROUP BY");
+               return sql_error(sql, 02, "OVER: not supported in combination 
with GROUP BY");
 
        if (f == sql_where) 
                return sql_error(sql, 02, "%s: not allowed in WHERE clause", 
toUpper(alloca(strlen(aggrstr) + 1), aggrstr));
@@ -1783,7 +1783,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;
 }
@@ -1943,7 +1943,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;
 
@@ -2714,6 +2715,7 @@
 
        if (!s)
                return NULL;
+
        /* flatten subqueries */
        if (s->type == st_list && 
            list_length(s->op1.lval) == 2 && f == sql_sel) {
@@ -2812,7 +2814,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);
@@ -2945,7 +2947,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);
@@ -3172,9 +3174,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;
@@ -3187,8 +3189,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);
        }
@@ -3197,8 +3199,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);
        }
@@ -3209,7 +3211,8 @@
                symbol *ro = sc->data.lval->h->next->next->data.sym;
                char *compare_op = sc->data.lval->h->next->data.sval;
 
-               ek.reduce = TRUE;
+               /* currently we don't handle the (universial and existential) 
+                  quantifiers (all and any/some) */
                return sql_compare_exp(sql, scp, grp, subset, lo, ro, 
compare_op, f, ek);
        }
                break;
@@ -3221,9 +3224,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)
@@ -3246,7 +3249,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);
@@ -3258,7 +3260,7 @@
                        return sql_and(sql, scp, j1, j2, f);
                }
                res = stmt_uselect2(ls, rs1, rs2, 3
-                                   /* aka rs1 <= ls <= rs2 */ );
+                           /* aka ls >= rs1 && ls <= rs2 */ );
                if (sc->token == SQL_NOT_BETWEEN)
                        res = stmt_diff(stmt_dup(ls), res);
                return res;
@@ -3269,7 +3271,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;
@@ -3284,8 +3286,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);
@@ -3352,11 +3354,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);
@@ -3364,7 +3366,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);
@@ -3407,9 +3409,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;
                        }
@@ -3472,7 +3473,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;
@@ -3532,7 +3533,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) {
@@ -3564,7 +3565,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;
@@ -3616,9 +3617,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 */
@@ -3641,7 +3642,7 @@
                }
                if (!(s = check_types(sql, bt, s, type_equal)))
                        return NULL;
-               s = stmt_select(t, s, cmp_equal);
+               s = stmt_uselect(t, s, cmp_equal);
                if (!found)
                        scope_add_alias(scp, stmt_dup(t), "row");
 
@@ -3649,7 +3650,7 @@
                stmt *t = first_subset(subset);
 
                t = stmt_const(t, stmt_bool(1));
-               return stmt_select(t, s, cmp_equal);
+               return stmt_uselect(t, s, cmp_equal);
        }
        return s;
 }
@@ -3718,12 +3719,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;
@@ -3861,6 +3863,7 @@
 {
        list *rl = NULL;
        stmt *s = NULL;
+       exp_kind iek = {type_value, card_relation, TRUE};
 
        stmt *order = NULL, *subset = NULL;
        group *grp = NULL;
@@ -3869,7 +3872,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");
@@ -3951,7 +3954,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.132
retrieving revision 1.132.2.1
diff -u -d -r1.132 -r1.132.2.1
--- sql_updates.mx      30 Jan 2008 10:41:36 -0000      1.132
+++ sql_updates.mx      14 Mar 2008 17:08:20 -0000      1.132.2.1
@@ -1562,6 +1562,7 @@
                dnode *n;
                list *l;
                stmt **updates, *rows_affected;
+               exp_kind ek = {type_value, card_column, TRUE};
 
                scp = scope_open(scp);
                if (temp_table) 
@@ -1570,7 +1571,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);
                        }
@@ -1903,6 +1904,7 @@
        } else {
                tvar *tv = NULL;
                stmt *s = NULL;
+               exp_kind ek = {type_value, card_column, TRUE};
 
                scp = scope_open(scp);
                if (temp_table) 
@@ -1911,7 +1913,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);


-------------------------------------------------------------------------
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