Update of /cvsroot/monetdb/sql/src/server
In directory sc8-pr-cvs16:/tmp/cvs-serv24540/src/server

Modified Files:
        sql_optimize.mx sql_schema.mx sql_select.mx 
Log Message:
added use of any type (only internal)
the any type is needed to have a single function definition for
al functions which all types need.



Index: sql_optimize.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_optimize.mx,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -d -r1.77 -r1.78
--- sql_optimize.mx     20 Feb 2007 11:50:47 -0000      1.77
+++ sql_optimize.mx     26 Apr 2007 14:35:08 -0000      1.78
@@ -387,6 +387,10 @@
                printf("= TODO: common/optimize.c: push down head %s\n", 
st_type2string(join->type));
 #endif
        }
+       if (join == select) {
+               stmt_destroy(select);
+               return join;
+       }
        return stmt_semijoin(join, select);
 }
 

Index: sql_select.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_select.mx,v
retrieving revision 1.182
retrieving revision 1.183
diff -u -d -r1.182 -r1.183
--- sql_select.mx       18 Apr 2007 13:34:05 -0000      1.182
+++ sql_select.mx       26 Apr 2007 14:35:09 -0000      1.183
@@ -56,6 +56,7 @@
 
 extern stmt *sql_subquery(mvc *sql, scope *scp, symbol *sq, exp_kind ek);
 extern stmt *scope_subquery(mvc *sql, scope *scp, symbol *sq, exp_kind ek );
+extern stmt *scope_subtable(mvc *sql, scope *scp, symbol *sq, exp_kind ek );
 extern stmt *flat_subquery(mvc *sql, symbol *sq);
 extern stmt *sql_reorder(stmt *order, stmt *s);
 
@@ -254,6 +255,34 @@
 }
 
 stmt *
+scope_subtable(mvc *sql, scope *scp, symbol *sq, exp_kind ek)
+{
+       stmt *s;
+
+       scp = scope_open(scp);
+       s = sql_subquery(sql, scp, sq, ek);
+       /* create a table from a single value subquery result */
+       if (s->key && s->nrcols == 0) {
+               list *l = create_stmt_list();
+               node *n;
+
+               for (n = s->op1.lval->h; n; n = n->next) {
+                       stmt *ns = stmt_dup(n->data);
+                       char *cname = column_name(ns);
+                       stmt *temp = stmt_temp(tail_type(ns));
+
+                       ns = stmt_append(temp, ns);
+                       ns = stmt_alias(ns, table_name(ns), cname);
+                       list_append(l, ns);
+               }
+               stmt_destroy(s);
+               s = stmt_list(l);
+       }
+       scp = scope_close(scp);
+       return s;
+}
+
+stmt *
 scope_subquery(mvc *sql, scope *scp, symbol *sq, exp_kind ek)
 {
        stmt *s;
@@ -909,19 +938,33 @@
                return stmt_binop(ls, rs, f);
        } else {
                int digits = t1->digits + t2->digits;
+               stmt *ols = stmt_dup(ls);
+               stmt *ors = stmt_dup(rs);
 
-               if ((f = sql_bind_member(s, fname, t1, 2)) != NULL ||
-                  ((f = sql_find_func(s, fname, 2)) != NULL && f->func->sql)) {
-                       /* try finding function based on first argument */
+               /* try finding function based on first argument */
+               if ((f = sql_bind_member(s, fname, t1, 2)) != NULL) {
                        node *m = f->func->ops->h;
                        sql_arg *a = m->data;
 
                        ls = check_types(sql, &a->type, ls, type_equal);
                        a = m->next->data;
                        rs = check_types(sql, &a->type, rs, type_equal);
-                       if (ls && rs) 
+                       if (ls && rs) {
+                               stmt_destroy(ols);
+                               stmt_destroy(ors);
                                return stmt_binop(ls, rs, f);
-               } else if (convert_types(sql, &ls, &rs, 1, type_equal) >= 0) {
+                       }
+               }
+               if (ls)
+                       stmt_destroy(ls);
+               if (rs)
+                       stmt_destroy(rs);
+               ls = ols;
+               rs = ors;
+               ols = stmt_dup(ls);
+               ors = stmt_dup(rs);
+               /* try finding function based on both arguments */
+               if (convert_types(sql, &ls, &rs, 1, type_equal) >= 0) {
                        /* try operators */
                        t1 = tail_type(ls);
                        t2 = tail_type(rs);
@@ -937,9 +980,28 @@
                                } else if (f->func->res.scale == DIGITS_ADD) {
                                        f->res.digits = digits;
                                }
+                               stmt_destroy(ols);
+                               stmt_destroy(ors);
                                return stmt_binop(ls, rs, f);
                        }
                }
+               if (ls)
+                       stmt_destroy(ls);
+               if (rs)
+                       stmt_destroy(rs);
+               ls = ols;
+               rs = ors;
+               /* everything failed, fall back to bind on function name only */
+               if ((f = sql_find_func(s, fname, 2)) != NULL) {
+                       node *m = f->func->ops->h;
+                       sql_arg *a = m->data;
+
+                       ls = check_types(sql, &a->type, ls, type_equal);
+                       a = m->next->data;
+                       rs = check_types(sql, &a->type, rs, type_equal);
+                       if (ls && rs) 
+                               return stmt_binop(ls, rs, f);
+               }
        }
        if (rs && ls)
                res = sql_error(sql, 02, "SELECT: no such binary operator 
'%s(%s,%s)'", fname, tail_type(ls)->type->sqlname, 
tail_type(rs)->type->sqlname);

Index: sql_schema.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_schema.mx,v
retrieving revision 1.123
retrieving revision 1.124
diff -u -d -r1.123 -r1.124
--- sql_schema.mx       18 Apr 2007 09:16:26 -0000      1.123
+++ sql_schema.mx       26 Apr 2007 14:35:08 -0000      1.124
@@ -754,7 +754,7 @@
                sql->depth++;
                if (sql->depth > SQL_MAXDEPTH)
                        return sql_error(sql, 02, "CREATE VIEW: too many nested 
VIEWS");
-               sq = scope_subquery(sql, NULL, query, ek );
+               sq = scope_subtable(sql, NULL, query, ek );
                sql->depth--;
                if (!sq)
                        return NULL;
@@ -1533,7 +1533,6 @@
                commit_action = CA_DELETE;
        
        if (temp != SQL_PERSIST) {
-               /* if (s != NULL) warn("discarding schema %s", s->base.name; */
                s = mvc_bind_schema(sql, "tmp");
        } else if (s == NULL) {
                s = ss;
@@ -1574,7 +1573,7 @@
                int with_data = as_sq->h->next->next->data.ival;
                sql_table *t = NULL; 
 
-               sq = scope_subquery(sql, NULL, subquery, ek);
+               sq = scope_subtable(sql, NULL, subquery, ek);
                /* make sure we get a list of ordered columns */
                if (sq && sq->type == st_ordered) {
                        stmt *order = stmt_dup(sq->op1.stval);
@@ -1776,6 +1775,7 @@
 {
        stmt *ret = NULL;
 
+       /* TODO everything should be done via the backend language */ 
        if (!QUERY_MODE(sql->mode))
                return sql_error(sql, 05, "Schema statements are directly 
executed and therefor cannot be debugged, explained, profiled, traced or used 
in a prepare statement");
 


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to