Changeset: 2b345d7a347d for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/2b345d7a347d Modified Files: sql/server/rel_optimize_proj.c Branch: const_aggr_elim Log Message:
Adds some comments for clarity diffs (54 lines): diff --git a/sql/server/rel_optimize_proj.c b/sql/server/rel_optimize_proj.c --- a/sql/server/rel_optimize_proj.c +++ b/sql/server/rel_optimize_proj.c @@ -2515,6 +2515,11 @@ rel_remove_const_aggr(visitor *v, sql_re } if(!list_empty(rel->r)) { + /* in the general case in an expression of an aggregate over + * a constant can be rewritten as just the const e.g. + * aggr(const) -> const + */ + for(node *n = exps->h; n; n = n->next) { sql_exp *e = n->data; @@ -2524,11 +2529,17 @@ rel_remove_const_aggr(visitor *v, sql_re sql_func *j = ((sql_subfunc *)e->f)->func; + /* some aggregates with const values can only be eliminated + * under certain circumstances e.g. + * sum(NULL) -> NULL, sum(0) -> 0 + * prod(NULL) -> NULL, prod(1) -> 1 + * count(NULL) -> 0 + */ int sum = strcmp(j->base.name, "sum") == 0, prd = strcmp(j->base.name, "prod") == 0, cnt = strcmp(j->base.name, "count") == 0; - if(!j->s && j->system == 1) { // && !cnt + if(!j->s && j->system == 1) { list *se = e->l; if(se == NULL) { @@ -2549,7 +2560,6 @@ rel_remove_const_aggr(visitor *v, sql_re continue; } - /* Handle: select count(distinct NULL) + 3 == 3 */ if(cnt) { if(wa->isnull) { list_remove_node(se, NULL, m); @@ -2572,9 +2582,9 @@ rel_remove_const_aggr(visitor *v, sql_re } } - /* + /* * Below code replaces GROUP BY with PROJECT in some cases; - * Triggers on... + * Triggers on... * select 1 having true; select 42 from foo group by x; select n from foo group by rollup(n); */ _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org