Changeset: 282bedfd5982 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=282bedfd5982
Modified Files:
sql/server/rel_optimizer.c
Branch: Jun2020
Log Message:
Attempt to push down topN/sample to the other side of union/crossproduct, even
if it's not possible at the other. Also look for projections needing distinct,
more than one ref or with ordering. At any of these cases, it can't be pushed
down
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
@@ -2104,7 +2104,7 @@ rel_push_topn_and_sample_down(visitor *v
}
}
- if (r && need_distinct(r))
+ if (r && is_simple_project(r->op) && need_distinct(r))
return rel;
/* push topn/sample under projections */
@@ -2131,24 +2131,28 @@ rel_push_topn_and_sample_down(visitor *v
sql_rel *u = r, *x;
sql_rel *ul = u->l;
sql_rel *ur = u->r;
-
- /* only push topn once */
+ bool changed = false;
+
x = ul;
- while (is_simple_project(x->op) && x->l)
+ while (is_simple_project(x->op) && !need_distinct(x) &&
!rel_is_ref(x) && x->l && !x->r)
x = x->l;
- if (x && x->op == rel->op)
- return rel;
+ if (x && x->op != rel->op) { /* only push topn once */
+ ul = func(v->sql->sa, ul,
sum_limit_offset(v->sql, rel));
+ u->l = ul;
+ changed = true;
+ }
+
x = ur;
- while (is_simple_project(x->op) && x->l)
+ while (is_simple_project(x->op) && !need_distinct(x) &&
!rel_is_ref(x) && x->l && !x->r)
x = x->l;
- if (x && x->op == rel->op)
- return rel;
-
- ul = func(v->sql->sa, ul, sum_limit_offset(v->sql,
rel));
- ur = func(v->sql->sa, ur, sum_limit_offset(v->sql,
rel));
- u->l = ul;
- u->r = ur;
- v->changes++;
+ if (x && x->op != rel->op) { /* only push topn once */
+ ur = func(v->sql->sa, ur,
sum_limit_offset(v->sql, rel));
+ u->r = ur;
+ changed = true;
+ }
+
+ if (changed)
+ v->changes++;
return rel;
}
@@ -2163,12 +2167,12 @@ rel_push_topn_and_sample_down(visitor *v
/* only push topn/sample once */
x = ul;
- while (is_simple_project(x->op) && x->l)
+ while (is_simple_project(x->op) && !need_distinct(x) &&
!rel_is_ref(x) && x->l && !x->r)
x = x->l;
if (x && x->op == rel->op)
return rel;
x = ur;
- while (is_simple_project(x->op) && x->l)
+ while (is_simple_project(x->op) && !need_distinct(x) &&
!rel_is_ref(x) && x->l && !x->r)
x = x->l;
if (x && x->op == rel->op)
return rel;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list