Update of /cvsroot/monetdb/pathfinder/compiler/algebra/opt
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv12037/algebra/opt
Modified Files:
opt_complex.c opt_general.brg
Log Message:
-- Move rewrite that doesn't look at properties into opt_general.brg
(rank operator with a single sort criterion).
-- Changed old (and inactive) rownum-project-rownum pattern rewrite into a
rank-project-rank pattern (that merges multiple adjacent rank operators
into a single one).
Index: opt_general.brg
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/opt/opt_general.brg,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- opt_general.brg 13 Jul 2007 12:48:30 -0000 1.29
+++ opt_general.brg 18 Jul 2007 11:45:08 -0000 1.30
@@ -806,42 +806,37 @@
relabel (p, kids);
break;
- /* Rel: rownum (Rel) */
- case 49:
-#if 0
-/* this is only allowed if the numbers do not matter */
+ /* Rel: rank (Rel) */
+ case 50:
+ /* Replace a rank operator with a single ascending order
+ criterion by a projection that links the output column
+ to the order criterion. */
+ if (PFord_count (p->sem.rank.sortby) == 1 &&
+ PFord_order_dir_at (p->sem.rank.sortby, 0) == DIR_ASC) {
+ PFalg_proj_t *proj_list;
+ unsigned int count = 0;
- /* replace rownum by projection if it only contains one
- sort (and no partioning) criterion that is of type nat */
- if (!p->sem.rownum.part &&
- p->sem.rownum.sortby.count == 1)
- for (unsigned int i = 0; i < p->schema.count; i++) {
- PFalg_att_t cur_col = p->schema.items[i].name;
-
- if (cur_col == p->sem.rownum.sortby.atts[0] &&
- p->schema.items[i].type == aat_nat) {
- PFalg_proj_t *proj = PFmalloc (
- p->schema.count
- * sizeof (PFalg_proj_t));
- /* copy property list */
- for (i = 0; i < p->schema.count; i++)
- if (p->sem.rownum.res ==
- p->schema.items[i].name)
- /* as rownum column we use the single
- sort criterion */
- proj[i] = PFalg_proj (p->sem.number.res,
- cur_col);
- else
- proj[i] = PFalg_proj (p->schema.items[i].name,
- p->schema.items[i].name);
-
- *p = *PFla_project_ (L(p), p->schema.count, proj);
- SEEN(p) = false;
- relabel (p, kids);
- break;
- }
- }
-#endif
+ /* create projection list */
+ proj_list = PFmalloc (p->schema.count *
+ sizeof (*(proj_list)));
+
+ /* adjust column name of the rank operator */
+ proj_list[count++] = PFalg_proj (
+ p->sem.rank.res,
+ PFord_order_col_at (
+ p->sem.rank.sortby,
+ 0));
+
+ for (unsigned int i = 0; i < p->schema.count; i++)
+ if (p->schema.items[i].name != p->sem.rank.res)
+ proj_list[count++] = PFalg_proj (
+ p->schema.items[i].name,
+ p->schema.items[i].name);
+
+ *p = *PFla_project_ (L(p), count, proj_list);
+ SEEN(p) = false;
+ relabel (p, kids);
+ }
break;
/* Rel: number (number (Rel)) */
Index: opt_complex.c
===================================================================
RCS file: /cvsroot/monetdb/pathfinder/compiler/algebra/opt/opt_complex.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- opt_complex.c 13 Jul 2007 11:05:25 -0000 1.25
+++ opt_complex.c 18 Jul 2007 11:45:07 -0000 1.26
@@ -644,15 +644,14 @@
}
break;
-#if 0
- case la_rownum:
- /* match the pattern rownum - (project -) rownum and
+ case la_rank:
+ /* match the pattern rank - (project -) rank and
try to merge both row number operators if the nested
- one only prepares some columns for the outer rownum.
+ one only prepares some columns for the outer rank.
As most operators are separated by a projection
we also support projections that do not rename. */
{
- PFla_op_t *rownum;
+ PFla_op_t *rank;
bool proj = false, renamed = false;
unsigned int i;
@@ -662,109 +661,82 @@
for (i = 0; i < L(p)->sem.proj.count; i++)
renamed = renamed || (L(p)->sem.proj.items[i].new !=
L(p)->sem.proj.items[i].old);
- rownum = LL(p);
+ rank = LL(p);
}
else
- rownum = L(p);
+ rank = L(p);
/* don't handle patterns with renaming projections */
if (renamed) break;
- /* check the remaining part of the pattern (nested rownum)
+ /* check the remaining part of the pattern (nested rank)
and ensure that the column generated by the nested
- row number operator is not used above the outer rownum. */
- if (rownum->kind == la_rownum &&
- !PFprop_icol (p->prop, rownum->sem.rownum.res)) {
+ row number operator is not used above the outer rank. */
+ if (rank->kind == la_rank &&
+ !PFprop_icol (p->prop, rank->sem.rank.res)) {
PFord_ordering_t sortby;
PFalg_proj_t *proj_list;
- PFalg_att_t inner_att = rownum->sem.rownum.res;
- PFalg_att_t inner_part = rownum->sem.rownum.part;
- unsigned int pos_part = 0, pos_att = 0, count = 0;
+ PFalg_att_t inner_att = rank->sem.rank.res;
+ unsigned int pos_att = 0, count = 0;
- /* if the inner rownum has a partitioning column
- this column has to occur in the outer rownum as
- partitioning attribute or as a sort criterion
- preceding the new column generated by the nested
- rownum. */
- if (inner_part) {
- /* get the position of the inner partition attribute
- in the sort criteria of the outer rownum */
- for (i = 0; i < PFord_count (p->sem.rownum.sortby); i++)
- if (PFord_order_col_at (p->sem.rownum.sortby, i)
- == inner_part) {
- pos_part = i;
- break;
- }
- /* don't handle patterns where the inner partition
- column does not occur in the outer rownum */
- if (i == PFord_count (p->sem.rownum.sortby))
- if (!p->sem.rownum.part ||
- p->sem.rownum.part != inner_part)
- break;
- }
-
- /* lookup position of the inner rownum column in
- the list of sort criteria of the outer rownum */
- for (i = 0; i < PFord_count (p->sem.rownum.sortby); i++)
- if (PFord_order_col_at (p->sem.rownum.sortby, i)
+ /* lookup position of the inner rank column in
+ the list of sort criteria of the outer rank */
+ for (i = 0; i < PFord_count (p->sem.rank.sortby); i++)
+ if (PFord_order_col_at (p->sem.rank.sortby, i)
== inner_att &&
/* make sure the order is the same */
- PFord_order_dir_at (p->sem.rownum.sortby, i)
+ PFord_order_dir_at (p->sem.rank.sortby, i)
== DIR_ASC) {
pos_att = i;
break;
}
- /* inner rownum column is not used in the outer rownum
- (thus the inner rownum is probably superfluous
- -- let the icols optimization remove the operator)
- or the inner partition column does not occur as
- sort criterion before the inner rownum column */
- if (i == PFord_count (p->sem.rownum.sortby) ||
- pos_part > pos_att)
- break;
+ /* inner rank column is not used in the outer rank
+ (thus the inner rank is probably superfluous
+ -- let the icols optimization remove the operator) */
+ if (i == PFord_count (p->sem.rank.sortby)) break;
sortby = PFordering ();
/* create new sort list where the sort criteria of the
- inner rownum substitute the inner rownum column */
+ inner rank substitute the inner rank column */
for (i = 0; i < pos_att; i++)
sortby = PFord_refine (sortby,
PFord_order_col_at (
- p->sem.rownum.sortby,
+ p->sem.rank.sortby,
i),
PFord_order_dir_at (
- p->sem.rownum.sortby,
+ p->sem.rank.sortby,
i));
- for (i = 0; i < PFord_count (rownum->sem.rownum.sortby); i++)
+ for (i = 0; i < PFord_count (rank->sem.rank.sortby); i++)
sortby = PFord_refine (sortby,
PFord_order_col_at (
- rownum->sem.rownum.sortby,
+ rank->sem.rank.sortby,
i),
PFord_order_dir_at (
- rownum->sem.rownum.sortby,
+ rank->sem.rank.sortby,
i));
for (i = pos_att + 1;
- i < PFord_count (p->sem.rownum.sortby);
+ i < PFord_count (p->sem.rank.sortby);
i++)
sortby = PFord_refine (sortby,
PFord_order_col_at (
- p->sem.rownum.sortby,
+ p->sem.rank.sortby,
i),
PFord_order_dir_at (
- p->sem.rownum.sortby,
+ p->sem.rank.sortby,
i));
if (proj) {
- /* Introduce the projection above the new rownum
+ /* Introduce the projection above the new rank
operator to maintain the correct result schema.
- As the result column name of the old outer rownum
+ As the result column name of the old outer rank
may collide with the attribute name of one of the
- inner rownums sort criteria, we use the column name
- of the inner rownum as resulting attribute name
+ inner ranks sort criteria, we use the column name
+ of the inner rank as resulting attribute name
and adjust the name in the new projection. */
count = 0;
@@ -773,65 +745,30 @@
proj_list = PFmalloc (p->schema.count *
sizeof (*(proj_list)));
- /* adjust column name of the rownum operator */
+ /* adjust column name of the rank operator */
proj_list[count++] = PFalg_proj (
- p->sem.rownum.res,
- rownum->sem.rownum.res);
+ p->sem.rank.res,
+ rank->sem.rank.res);
for (i = 0; i < p->schema.count; i++)
if (p->schema.items[i].name !=
- p->sem.rownum.res)
+ p->sem.rank.res)
proj_list[count++] = PFalg_proj (
p->schema.items[i].name,
p->schema.items[i].name);
- *p = *PFla_project_ (PFla_rownum (L(rownum),
- rownum->sem.rownum.res,
- sortby,
- p->sem.rownum.part),
+ *p = *PFla_project_ (PFla_rank (L(rank),
+ rank->sem.rank.res,
+ sortby),
count, proj_list);
}
else
- *p = *PFla_rownum (rownum,
- p->sem.rownum.res,
- sortby,
- p->sem.rownum.part);
+ *p = *PFla_rank (rank, p->sem.rank.res, sortby);
break;
}
} break;
-#endif
-
- /* Replace a rank operator with a single ascending order
- criterion by a projection that links the output column
- to the order criterion. */
- case la_rank:
- if (PFord_count (p->sem.rank.sortby) == 1 &&
- PFord_order_dir_at (p->sem.rank.sortby, 0) == DIR_ASC) {
- PFalg_proj_t *proj_list;
- unsigned int count = 0;
-
- /* create projection list */
- proj_list = PFmalloc (p->schema.count *
- sizeof (*(proj_list)));
-
- /* adjust column name of the rank operator */
- proj_list[count++] = PFalg_proj (
- p->sem.rank.res,
- PFord_order_col_at (
- p->sem.rank.sortby,
- 0));
-
- for (unsigned int i = 0; i < p->schema.count; i++)
- if (p->schema.items[i].name != p->sem.rank.res)
- proj_list[count++] = PFalg_proj (
- p->schema.items[i].name,
- p->schema.items[i].name);
-
- *p = *PFla_project_ (L(p), count, proj_list);
- }
- break;
case la_number:
if (PFprop_card (p->prop) == 1) {
-------------------------------------------------------------------------
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-pf-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-pf-checkins