Changeset: 746812559954 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=746812559954
Modified Files:
sql/server/rel_optimizer.c
Branch: Oct2020
Log Message:
make sure we only rewrite aggr(distinct) when there are no other aggregates.
diffs (70 lines):
diff --git a/sql/server/rel_optimizer.c b/sql/server/rel_optimizer.c
--- a/sql/server/rel_optimizer.c
+++ b/sql/server/rel_optimizer.c
@@ -5863,22 +5863,6 @@ rel_reduce_groupby_exps(visitor *v, sql_
return rel;
}
-/* Rewrite group by expressions with distinct
- *
- * ie select a, count(distinct b) from c where ... groupby a;
- * No other aggregations should be present
- *
- * Rewrite the more general case, good for parallel execution
- *
- * groupby(R) [e,f] [ aggr1 a distinct, aggr2 b distinct, aggr3 c, aggr4 d]
- *
- * into
- *
- * groupby(
- * groupby(R) [e,f,a,b] [ a, b, aggr3 c, aggr4 d]
- * ) [e,f]( aggr1 a distinct, aggr2 b distinct, aggr3_phase2 c, aggr4_phase2 d)
- */
-
#if 0
static sql_rel *
rel_groupby_distinct2(visitor *v, sql_rel *rel)
@@ -5966,6 +5950,21 @@ rel_groupby_distinct2(visitor *v, sql_re
}
#endif
+/* Rewrite group by expressions with distinct
+ *
+ * ie select a, count(distinct b) from c where ... groupby a;
+ * No other aggregations should be present
+ *
+ * Rewrite the more general case, good for parallel execution
+ *
+ * groupby(R) [e,f] [ aggr1 a distinct, aggr2 b distinct, aggr3 c, aggr4 d]
+ *
+ * into
+ *
+ * groupby(
+ * groupby(R) [e,f,a,b] [ a, b, aggr3 c, aggr4 d]
+ * ) [e,f]( aggr1 a distinct, aggr2 b distinct, aggr3_phase2 c, aggr4_phase2 d)
+ */
static sql_rel *
rel_groupby_distinct(visitor *v, sql_rel *rel)
{
@@ -5989,7 +5988,7 @@ rel_groupby_distinct(visitor *v, sql_rel
return rel;
}
if (is_groupby(rel->op) && rel->r && !rel_is_ref(rel)) {
- int nr = 0;
+ int nr = 0, anr = 0;
list *gbe, *ngbe, *arg, *exps, *nexps;
sql_exp *distinct = NULL, *darg;
sql_rel *l = NULL;
@@ -6000,10 +5999,11 @@ rel_groupby_distinct(visitor *v, sql_rel
distinct = n->data;
nr++;
}
+ anr += is_aggr(e->type);
}
if (nr < 1 || distinct->type != e_aggr)
return rel;
- if (nr > 1 || list_length(rel->r) + nr !=
list_length(rel->exps))
+ if (nr > 1 || anr > nr)
return rel;//rel_groupby_distinct2(v, rel);
arg = distinct->l;
if (list_length(arg) != 1 || list_length(rel->r) + nr !=
list_length(rel->exps))
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list