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

Modified Files:
        rel_optimizer.mx 
Log Message:
propagated changes of Thursday Jan 29 2009 - Friday Jan 30 2009
from the Feb2009 branch to the development trunk

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2009/01/29 - nielsnes: src/server/rel_optimizer.mx,1.37.2.1
fixes for roberto's bugs
(distinct/join and row_number pushed incorrectly up)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Index: rel_optimizer.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/rel_optimizer.mx,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- rel_optimizer.mx    13 Jan 2009 14:47:54 -0000      1.37
+++ rel_optimizer.mx    29 Jan 2009 23:52:32 -0000      1.38
@@ -996,11 +996,31 @@
        return NULL;
 }
 
+/* some projections results are order dependend (row_number etc) */
+static int 
+project_unsafe(sql_rel *rel)
+{
+       node *n;
+
+       if (need_distinct(rel))
+               return 1;
+       if (!rel->exps)
+               return 0;
+       for(n = rel->exps->h; n; n = n->next) {
+               sql_exp *e = n->data;
+
+               /* aggr func in project ! */
+               if (e->type == e_func && e->card == 1)
+                       return 1;
+       }
+       return 0;
+}
+
 /*
  * Push select down, pushes the selects through (simple) projections. Also
  * it cleans up the projections which become useless.
  */
-sql_rel *
+static sql_rel *
 rel_push_select_down(int *changes, mvc *sql, sql_rel *rel) 
 {
        list *exps = NULL;
@@ -1154,6 +1174,11 @@
                return rel;
        /* push select through project */
        } else if (rel->op == op_select && r && r->op == op_project && 
!(rel_is_ref(r))) {
+               /* we cannot push through rank (row_number etc) functions or
+                  projects with distinct */
+               if (project_unsafe(r))
+                       return rel;
+
                /* here we need to fix aliases */
                rel->exps = new_exp_list(); 
                /* for each exp check if we can rename it */
@@ -1335,9 +1360,11 @@
                                        list *exps = e->l;
                                        sql_exp *ae = exps->h->data;
 
-                                       /* FOR NOW ESCAPE ON AVG ON DECIMALS,
+                                       /* 
+                                          FOR NOW ESCAPE ON AVG ON DECIMALS,
                                           we need a rewrite or DEC's in 
-                                          the optimizer to solve this problem*/
+                                          the optimizer to solve this problem
+                                       */
                                        if (exp_subtype(ae)->type->eclass == 
EC_DEC)
                                                return rel;
                                        append(avgs, e);
@@ -1452,9 +1479,9 @@
                   (is_join(rel->op) && (!r || rel_is_ref(r))) ||
                   (is_select(rel->op) && l->op != op_project) ||
                   (is_join(rel->op) && l->op != op_project && r->op != 
op_project) ||
-                 ((l->op == op_project && (!l->l || l->r)) ||
+                 ((l->op == op_project && (!l->l || l->r || 
project_unsafe(l))) ||
                   (is_join(rel->op) && 
-                   r->op == op_project && (!r->l || r->r)))) 
+                   r->op == op_project && (!r->l || r->r || 
project_unsafe(r))))) 
                        return rel;
 
                if (l->op == op_project && l->l) {


------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to