Update of /cvsroot/monetdb/sql/src/server
In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv28654/src/server

Modified Files:
        rel_optimizer.mx 
Log Message:
propagated changes of Friday Nov 20 2009 - Saturday Nov 28 2009
from the Nov2009 branch to the development trunk

  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2009/11/20 - nielsnes: src/server/rel_optimizer.mx,1.71.2.4
  new optimizer to fix (performance) bug. We should always start grouping with
  a sorted column (if its part of a group by list).
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2009/11/26 - nielsnes: src/server/rel_optimizer.mx,1.71.2.5
  fixed order of group by columns
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Index: rel_optimizer.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/rel_optimizer.mx,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -d -r1.75 -r1.76
--- rel_optimizer.mx    12 Nov 2009 08:39:34 -0000      1.75
+++ rel_optimizer.mx    28 Nov 2009 19:57:00 -0000      1.76
@@ -2323,6 +2323,52 @@
        return rel;
 }
 
+/* Compute the efficiency of using this expression early in a group by list */
+static int
+score_gbe( mvc *sql, sql_rel *rel, sql_exp *e)
+{
+       int res = 10;
+       sql_subtype *t = exp_subtype(e);
+       sql_column *c = NULL;
+
+       /* can we find out if the underlying table is sorted */
+       if ( (c = exp_find_column(rel, e)) != NULL) {
+               if (mvc_is_sorted (sql, c)) 
+                       res += 500;
+       }
+
+       /* is the column selective */
+
+       /* prefer the shorter var types over the longer onces */
+       if (!EC_FIXED(t->type->eclass) && t->digits)
+               res -= t->digits;
+       /* smallest type first */
+       if (EC_FIXED(t->type->eclass))
+               res -= t->type->eclass; 
+       return res;
+}
+
+/* reorder group by expressions */
+static sql_rel *
+rel_groupby_order(int *changes, mvc *sql, sql_rel *rel) 
+{
+       list *gbe = rel->r;
+
+       *changes = 0;
+       if (is_groupby(rel->op) && list_length(gbe) > 1 && list_length(gbe)<9) {
+               node *n;
+               int i, *scores = alloca(sizeof(int) * list_length(gbe));
+
+               memset(scores, 0, sizeof(int)*list_length(gbe));
+               for (i = 0, n = gbe->h; n; i++, n = n->next) {
+                       scores[i] = score_gbe(sql, rel, n->data);
+               }
+               rel->r = list_keysort(gbe, scores, (fdup)exp_dup);
+               list_destroy(gbe);
+       }
+       return rel;
+}
+
 /* Pushing projects up the tree. Done very early in the optimizer.
  * Makes later steps easier. 
  */
@@ -3345,8 +3391,10 @@
                rel = rewrite(sql, rel, &rel_push_join_down); 
        }
 
-       if (gp.cnt[op_groupby])
+       if (gp.cnt[op_groupby]) {
                rel = rewrite(sql, rel, &rel_avg2sum_count); 
+               rel = rewrite(sql, rel, &rel_groupby_order); 
+       }
 
        if (gp.cnt[op_join] || gp.cnt[op_left])
                rel = rewrite(sql, rel, &rel_join_order); 


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