Update of /cvsroot/monetdb/pathfinder/compiler/algebra/opt
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv3968/compiler/algebra/opt

Modified Files:
      Tag: M5XQ
        opt_const.c 
Log Message:
propagated changes of Friday Jun 12 2009 - Monday Jun 15 2009
from the development trunk to the M5XQ branch

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2009/06/12 - tsheyar: compiler/algebra/opt/opt_const.c,1.48
-- Replaced aggregate operators count, min, max, avg, sum, prod, seqty1,
   and all in the algebra by a single aggregate operator ``aggr''
   that can handle multiple aggregates. The aggregate entries
   are of kind count, min, max, avg, sum, prod, seqty1, all, and dist.

-- Added new aggregate kind ``dist'' that allows to represent group by
   columns that functionally depend on the partitioning criterion
   in the result of the grouping aggregate.

-- Added rewrite that merges aggregates.

-- Added rewrite that removes superfluous aggregates.

-- Added rewrite that pushes a rank operator through an aggregate.

-- Extended the XML import to cope with the old
   as well as the new representation of aggregates.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


U opt_const.c
Index: opt_const.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/opt/opt_const.c,v
retrieving revision 1.45.2.2
retrieving revision 1.45.2.3
diff -u -d -r1.45.2.2 -r1.45.2.3
--- opt_const.c 20 May 2009 16:28:29 -0000      1.45.2.2
+++ opt_const.c 15 Jun 2009 12:44:50 -0000      1.45.2.3
@@ -196,19 +196,7 @@
             }
             break;
 
-        case la_sum:
-        case la_prod:
-            /* introduce attach if necessary */
-            if (PFprop_const_left (p->prop, p->sem.aggr.col)) {
-                L(p) = add_attach (L(p), p->sem.aggr.col,
-                                   PFprop_const_val_left (p->prop,
-                                                          p->sem.aggr.col));
-            }
-            /* fall through */
-        case la_avg:
-        case la_max:
-        case la_min:
-        case la_count:
+        case la_aggr:
             /* introduce attach if necessary */
             if (p->sem.aggr.part &&
                 PFprop_const_left (p->prop, p->sem.aggr.part)) {
@@ -216,6 +204,15 @@
                                    PFprop_const_val_left (p->prop,
                                                           p->sem.aggr.part));
             }
+            /* introduce attach if necessary */
+            for (unsigned int i = 0; i < p->sem.aggr.count; i++)
+                if (p->sem.aggr.aggr[i].col &&
+                    PFprop_const_left (p->prop, p->sem.aggr.aggr[i].col))
+                    L(p) = add_attach (L(p),
+                                       p->sem.aggr.aggr[i].col,
+                                       PFprop_const_val_left (
+                                           p->prop,
+                                           p->sem.aggr.aggr[i].col));
             break;
 
         case la_type:
@@ -229,33 +226,6 @@
             }
             break;
 
-        case la_all:
-            if (p->sem.aggr.part &&
-                PFprop_const_left (p->prop, p->sem.aggr.col)) {
-                PFla_op_t *op, *ret;
-                
-                op = distinct (
-                         project (L(p),
-                                  proj (p->sem.aggr.part,
-                                        p->sem.aggr.part)));
-
-                ret = add_attach (op, p->sem.aggr.col,
-                                  PFprop_const_val_left (
-                                      p->prop,
-                                      p->sem.aggr.col));
-                *p = *ret;
-                SEEN(p) = true;
-            }
-            /* fall through */
-        case la_seqty1:
-            /* introduce attach if necessary */
-            if (PFprop_const_left (p->prop, p->sem.aggr.col)) {
-                L(p) = add_attach (L(p), p->sem.aggr.col,
-                                   PFprop_const_val_left (p->prop,
-                                                          p->sem.aggr.col));
-            }
-            break;
-
         default:
             break;
     }
@@ -543,9 +513,12 @@
                and replace it by an unpartitioned count */
             if (p->schema.count == 1 &&
                 L(p)->kind == la_project &&
-                LL(p)->kind == la_count &&
+                LL(p)->kind == la_aggr &&
+                LL(p)->sem.aggr.count == 1 &&
+                LL(p)->sem.aggr.aggr[0].kind == alg_aggr_count &&
+                LL(p)->sem.aggr.part &&
                 PFprop_const (LL(p)->prop, LL(p)->sem.aggr.part) &&
-                L(p)->sem.proj.items[0].old == LL(p)->sem.aggr.res &&
+                L(p)->sem.proj.items[0].old == LL(p)->sem.aggr.aggr[0].res &&
                 R(p)->kind == la_project &&
                 RL(p)->kind == la_attach &&
                 R(p)->sem.proj.items[0].old == RL(p)->sem.attach.res &&
@@ -557,6 +530,9 @@
                 RLLR(p)->sem.proj.items[0].old ==
                 LL(p)->sem.aggr.part &&
                 L(RLLR(p)) == LL(p)) {
+                PFalg_aggr_t aggr = PFalg_aggr (alg_aggr_count,
+                                                R(p)->sem.proj.items[0].old,
+                                                col_NULL);
 
                 /* check that the values in the loop are constant
                    and provide the same value */
@@ -578,9 +554,10 @@
                    of 0) we have to make sure that we take the cardinality
                    of the loop relation into account. */
                 *p = *project (cross (RLLL(p), /* loop */
-                                      PFla_count (LLL(p),
-                                                  R(p)->sem.proj.items[0].old,
-                                                  col_NULL)),
+                                      PFla_aggr (LLL(p),
+                                                 col_NULL,
+                                                 1,
+                                                 &aggr)),
                                proj (R(p)->sem.proj.items[0].new,
                                      R(p)->sem.proj.items[0].old));
                 break;
@@ -764,100 +741,21 @@
             }
             break;
 
-        case la_avg:
-        case la_max:
-        case la_min:
-            /* some optimization opportunities for
-               aggregate operators arise if 'col' is constant */
-            if (PFprop_const_left (p->prop, p->sem.aggr.col)) {
-
-#if 0 /* We are not allowed to create an unpartitioned aggregate
-         as an empty loop relation might result in a single line
-         result otherwise. */
-         
-                /* if partitioning column is constant as well
-                   replace aggregate by a new literal table
-                   with one row containing 'col' and 'part' */
-                if (p->sem.aggr.part &&
-                    PFprop_const_left (p->prop, p->sem.aggr.part))
-                    *p = *PFla_lit_tbl (
-                              collist (p->sem.aggr.res,
-                                       p->sem.aggr.part),
-                              PFalg_tuple (PFprop_const_val_left (
-                                               p->prop,
-                                               p->sem.aggr.col),
-                                           PFprop_const_val_left (
-                                               p->prop,
-                                               p->sem.aggr.part)));
-                /* if the partitioning column is present but not
-                   constant we can replace the aggregate by a
-                   distinct operator (value in 'col' stays the same). */
-                else if (p->sem.aggr.part)
-#endif
-                    *p = *PFla_distinct (
-                              PFla_project (
-                                  L(p),
-                                  PFalg_proj (p->sem.aggr.res,
-                                              p->sem.aggr.col),
-                                  PFalg_proj (p->sem.aggr.part,
-                                              p->sem.aggr.part)));
-#if 0
-                /* replace aggregate by a new literal table
-                   containining a single record with the result of
-                   aggregate operator. */
-                else
-                    *p = *PFla_lit_tbl (collist (p->sem.aggr.res),
-                                        PFalg_tuple (
-                                            PFprop_const_val_left (
-                                                p->prop,
-                                                p->sem.aggr.col)));
-#endif
-            }
-            break;
-
-#if 0 /* We are not allowed to create an unpartitioned aggregate
-         as an empty loop relation might result in a single line
-         result otherwise. */
-         
-        case la_sum:
-        case la_prod:
-            /* if partitiong column is constant remove it
-               and attach it after the operator */
-            if (p->sem.aggr.part &&
-                PFprop_const_left (p->prop, p->sem.aggr.part)) {
-                PFla_op_t *sum = PFla_aggr (p->kind,
-                                           L(p),
-                                           p->sem.aggr.res,
-                                           p->sem.aggr.col,
-                                           p->sem.aggr.part);
-                PFla_op_t *ret = add_attach (sum, p->sem.aggr.part,
-                                             PFprop_const_val_left (
-                                                 p->prop,
-                                                 p->sem.aggr.part));
-                sum->sem.aggr.part = col_NULL;
-                *p = *ret;
-                SEEN(p) = true;
-            }
-            break;
+        case la_aggr:
+            for (unsigned int i = 0; i < p->sem.aggr.count; i++)
+                if (PFprop_const_left (p->prop, p->sem.aggr.aggr[i].col))
+                    switch (p->sem.aggr.aggr[i].kind) {
+                        case alg_aggr_avg:
+                        case alg_aggr_max:
+                        case alg_aggr_min:
+                        case alg_aggr_all:
+                            p->sem.aggr.aggr[i].kind = alg_aggr_dist;
+                            break;
 
-        case la_count:
-            /* if partitiong column is constant remove it
-               and attach it after the operator */
-            if (p->sem.aggr.part &&
-                PFprop_const_left (p->prop, p->sem.aggr.part)) {
-                PFla_op_t *count = PFla_count (L(p),
-                                               p->sem.aggr.res,
-                                               p->sem.aggr.part);
-                PFla_op_t *ret = add_attach (count, p->sem.aggr.part,
-                                             PFprop_const_val_left (
-                                                 p->prop,
-                                                 p->sem.aggr.part));
-                count->sem.aggr.part = col_NULL;
-                *p = *ret;
-                SEEN(p) = true;
-            }
+                        default:
+                            break;
+                    }
             break;
-#endif
 
         case la_rownum:
         {
@@ -916,77 +814,6 @@
                 *p = *PFla_attach (L(p), p->sem.sort.res, PFalg_lit_int (1));
         }   break;
 
-#if 0 /* We are not allowed to create an unpartitioned aggregate
-         as an empty loop relation might result in a single line
-         result otherwise. */
-
-        case la_all:
-            if (p->sem.aggr.part &&
-                PFprop_const_left (p->prop, p->sem.aggr.col)) {
-                PFla_op_t *op, *ret;
-                
-                if (PFprop_const_left (p->prop, p->sem.aggr.part)) {
-                    op = lit_tbl (collist (p->sem.aggr.part),
-                                  tuple (PFprop_const_val_left (
-                                             p->prop,
-                                             p->sem.aggr.part)));
-                } else {
-                    op = distinct (
-                             project (L(p),
-                                      proj (p->sem.aggr.part,
-                                            p->sem.aggr.part)));
-                }
-
-                ret = add_attach (op, p->sem.aggr.col,
-                                  PFprop_const_val_left (
-                                      p->prop,
-                                      p->sem.aggr.col));
-                *p = *ret;
-                SEEN(p) = true;
-            }
-
-            else if (PFprop_const_left (p->prop, p->sem.aggr.col)) {
-                PFla_op_t *ret = lit_tbl (collist (p->sem.aggr.col),
-                                          tuple (PFprop_const_val_left (
-                                                     p->prop,
-                                                     p->sem.aggr.col)));
-                *p = *ret;
-                SEEN(p) = true;
-            }
-            /* fall through */
-        case la_seqty1:
-            /* introduce attach if necessary */
-            if (PFprop_const_left (p->prop, p->sem.aggr.col)) {
-                L(p) = add_attach (L(p), p->sem.aggr.col,
-                                   PFprop_const_val_left (p->prop,
-                                                          p->sem.aggr.col));
-            }
-
-            /* if partitiong column is constant remove it
-               and attach it after the operator */
-            if (p->sem.aggr.part &&
-                PFprop_const_left (p->prop, p->sem.aggr.part)) {
-                PFla_op_t *op = p->kind == la_all
-                                ? PFla_all (L(p),
-                                            p->sem.aggr.res,
-                                            p->sem.aggr.col,
-                                            p->sem.aggr.part)
-                                : PFla_seqty1 (L(p),
-                                               p->sem.aggr.res,
-                                               p->sem.aggr.col,
-                                               p->sem.aggr.part);
-
-                PFla_op_t *ret = add_attach (op, p->sem.aggr.part,
-                                             PFprop_const_val_left (
-                                                 p->prop,
-                                                 p->sem.aggr.part));
-                op->sem.aggr.part = col_NULL;
-                *p = *ret;
-                SEEN(p) = true;
-            }
-            break;
-#endif
-
         default:
             break;
     }


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Monetdb-pf-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-pf-checkins

Reply via email to