Changeset: d4ff5b6d61eb for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d4ff5b6d61eb
Modified Files:
        sql/server/rel_optimizer.c
        
sql/test/BugTracker-2010/Tests/ORDER_BY_over_UNION_EXCEPT_INTERSECT.Bug-2606.stable.out
        sql/test/BugTracker-2015/Tests/crash.Bug-3736.stable.out
        sql/test/Tests/order_by_complex_exp.stable.out
        sql/test/miscellaneous/Tests/simple_plans.stable.out
        sql/test/miscellaneous/Tests/simple_plans.stable.out.single
Branch: Jun2020
Log Message:

Simplify rel_push_project_down optimizer. Don't re-project again


diffs (truncated from 627 to 300 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
@@ -5661,53 +5661,8 @@ rel_push_project_down(visitor *v, sql_re
                                return l;
                        }
                        return rel;
-#if 0
-                       /* keep important internal columns */
-                       for (node *n = l->exps->h; n; n = n->next) {
-                               sql_exp *e = n->data;
-
-                               if (is_intern(e))
-                                       append(rel->exps, e);
-                       }
-                       l->exps = rel->exps;
-                       rel->l = NULL;
-                       rel_destroy(rel);
-                       v->changes++;
-                       return l;
-#endif
                } else if (list_check_prop_all(rel->exps, 
(prop_check_func)&exp_is_useless_rename)) {
-                       if (is_simple_project(l->op) && list_length(l->exps) == 
list_length(rel->exps)) {
-                               rel->l = NULL;
-                               rel_destroy(rel);
-                               v->changes++;
-                               return l;
-                       } else if (is_select(l->op)) {
-                               /* push project under select (include exps used 
by selection) */
-                               l->l = rel_project(v->sql->sa, l->l, 
rel_projections(v->sql, l, NULL, 1, 1));
-                               l->l = rel_push_project_down(v, l->l);
-                               rel->l = NULL;
-                               rel_destroy(rel);
-                               v->changes++;
-                               return l;
-                       } else if (is_join(l->op)) {
-                               /* for each exp add to left or right project 
under join */
-                               sql_rel *ll = l->l, *lr = l->r;
-                               list *lexps = sa_list(v->sql->sa), *rexps = 
sa_list(v->sql->sa);
-
-                               list *exps = rel_projections(v->sql, l, NULL, 
1, 1); /* include exps used by join exps */
-                               for(node *n = exps->h; n; n = n->next) {
-                                       sql_exp *e = n->data;
-                                       if ((exp_relname(e) && exp_name(e) && 
rel_bind_column2(v->sql, ll, exp_relname(e), exp_name(e), 0)) ||
-                                               (!exp_relname(e) && exp_name(e) 
&& rel_bind_column(v->sql, ll, exp_name(e), 0, 1))) {
-                                               append(lexps, e);
-                                       } else {
-                                               append(rexps, e);
-                                       }
-                               }
-                               l->l = rel_project(v->sql->sa, ll, lexps);
-                               l->l = rel_push_project_down(v, l->l);
-                               l->r = rel_project(v->sql->sa, lr, rexps);
-                               l->r = rel_push_project_down(v, l->r);
+                       if ((is_project(l->op) && list_length(l->exps) == 
list_length(rel->exps)) || is_select(l->op) || is_join(l->op) || is_topn(l->op) 
|| is_sample(l->op)) {
                                rel->l = NULL;
                                rel_destroy(rel);
                                v->changes++;
diff --git 
a/sql/test/BugTracker-2010/Tests/ORDER_BY_over_UNION_EXCEPT_INTERSECT.Bug-2606.stable.out
 
b/sql/test/BugTracker-2010/Tests/ORDER_BY_over_UNION_EXCEPT_INTERSECT.Bug-2606.stable.out
--- 
a/sql/test/BugTracker-2010/Tests/ORDER_BY_over_UNION_EXCEPT_INTERSECT.Bug-2606.stable.out
+++ 
b/sql/test/BugTracker-2010/Tests/ORDER_BY_over_UNION_EXCEPT_INTERSECT.Bug-2606.stable.out
@@ -60,22 +60,20 @@ stdout of test 'ORDER_BY_over_UNION_EXCE
 % .plan # table_name
 % rel # name
 % clob # type
-% 51 # length
+% 49 # length
 project (
-| project (
-| | distinct union (
-| | | project (
-| | | | group by (
-| | | | | table(sys.t2606a) [ "t2606a"."a" ] COUNT 
-| | | | ) [ "t2606a"."a" ] [ "t2606a"."a" ]
-| | | ) [ "t2606a"."a" as "%3"."a" ],
-| | | project (
-| | | | group by (
-| | | | | table(sys.t2606b) [ "t2606b"."a" ] COUNT 
-| | | | ) [ "t2606b"."a" ] [ "t2606b"."a" ]
-| | | ) [ "t2606b"."a" as "%4"."a" ]
-| | ) [ "%3"."a" as "%7"."a" ]
-| ) [ "%7"."a" ]
+| distinct union (
+| | project (
+| | | group by (
+| | | | table(sys.t2606a) [ "t2606a"."a" ] COUNT 
+| | | ) [ "t2606a"."a" ] [ "t2606a"."a" ]
+| | ) [ "t2606a"."a" as "%3"."a" ],
+| | project (
+| | | group by (
+| | | | table(sys.t2606b) [ "t2606b"."a" ] COUNT 
+| | | ) [ "t2606b"."a" ] [ "t2606b"."a" ]
+| | ) [ "t2606b"."a" as "%4"."a" ]
+| ) [ "%3"."a" as "%7"."a" ]
 ) [ "%7"."a" ] [ "%7"."a" ASC ]
 #select * from t2606a   union   select * from t2606b   order by a;
 % .%7 # table_name
@@ -95,22 +93,20 @@ project (
 % .plan # table_name
 % rel # name
 % clob # type
-% 51 # length
+% 49 # length
 project (
-| project (
-| | distinct union (
-| | | project (
-| | | | group by (
-| | | | | table(sys.t2606a) [ "t2606a"."a" ] COUNT 
-| | | | ) [ "t2606a"."a" ] [ "t2606a"."a" ]
-| | | ) [ "t2606a"."a" as "%3"."a" ],
-| | | project (
-| | | | group by (
-| | | | | table(sys.t2606b) [ "t2606b"."a" ] COUNT 
-| | | | ) [ "t2606b"."a" ] [ "t2606b"."a" ]
-| | | ) [ "t2606b"."a" as "%4"."a" ]
-| | ) [ "%3"."a" as "%7"."a" ]
-| ) [ "%7"."a" ]
+| distinct union (
+| | project (
+| | | group by (
+| | | | table(sys.t2606a) [ "t2606a"."a" ] COUNT 
+| | | ) [ "t2606a"."a" ] [ "t2606a"."a" ]
+| | ) [ "t2606a"."a" as "%3"."a" ],
+| | project (
+| | | group by (
+| | | | table(sys.t2606b) [ "t2606b"."a" ] COUNT 
+| | | ) [ "t2606b"."a" ] [ "t2606b"."a" ]
+| | ) [ "t2606b"."a" as "%4"."a" ]
+| ) [ "%3"."a" as "%7"."a" ]
 ) [ "%7"."a" ] [ "%7"."a" ASC ]
 #( select * from t2606a   union   select * from t2606b ) order by a;
 % .%7 # table_name
@@ -130,22 +126,20 @@ project (
 % .plan # table_name
 % rel # name
 % clob # type
-% 51 # length
+% 49 # length
 project (
-| project (
-| | distinct union (
-| | | project (
-| | | | group by (
-| | | | | table(sys.t2606a) [ "t2606a"."a" ] COUNT 
-| | | | ) [ "t2606a"."a" ] [ "t2606a"."a" ]
-| | | ) [ "t2606a"."a" as "%3"."a" ],
-| | | project (
-| | | | group by (
-| | | | | table(sys.t2606b) [ "t2606b"."a" ] COUNT 
-| | | | ) [ "t2606b"."a" ] [ "t2606b"."a" ]
-| | | ) [ "t2606b"."a" as "%4"."a" ]
-| | ) [ "%3"."a" as "%7"."a" ]
-| ) [ "%7"."a" ]
+| distinct union (
+| | project (
+| | | group by (
+| | | | table(sys.t2606a) [ "t2606a"."a" ] COUNT 
+| | | ) [ "t2606a"."a" ] [ "t2606a"."a" ]
+| | ) [ "t2606a"."a" as "%3"."a" ],
+| | project (
+| | | group by (
+| | | | table(sys.t2606b) [ "t2606b"."a" ] COUNT 
+| | | ) [ "t2606b"."a" ] [ "t2606b"."a" ]
+| | ) [ "t2606b"."a" as "%4"."a" ]
+| ) [ "%3"."a" as "%7"."a" ]
 ) [ "%7"."a" ] [ "%7"."a" ASC ]
 #( select * from t2606a ) union ( select * from t2606b ) order by a;
 % .%7 # table_name
@@ -165,18 +159,16 @@ project (
 % .plan # table_name
 % rel # name
 % clob # type
-% 49 # length
+% 47 # length
 project (
-| project (
-| | distinct except (
-| | | project (
-| | | | table(sys.t2606a) [ "t2606a"."a" ] COUNT 
-| | | ) [ "t2606a"."a" as "%3"."a" ],
-| | | project (
-| | | | table(sys.t2606b) [ "t2606b"."a" ] COUNT 
-| | | ) [ "t2606b"."a" as "%4"."a" ]
-| | ) [ "%3"."a" as "%7"."a" ]
-| ) [ "%7"."a" ]
+| distinct except (
+| | project (
+| | | table(sys.t2606a) [ "t2606a"."a" ] COUNT 
+| | ) [ "t2606a"."a" as "%3"."a" ],
+| | project (
+| | | table(sys.t2606b) [ "t2606b"."a" ] COUNT 
+| | ) [ "t2606b"."a" as "%4"."a" ]
+| ) [ "%3"."a" as "%7"."a" ]
 ) [ "%7"."a" ] [ "%7"."a" ASC ]
 #select * from t2606a   except   select * from t2606b   order by a;
 % sys.%7 # table_name
@@ -190,18 +182,16 @@ project (
 % .plan # table_name
 % rel # name
 % clob # type
-% 49 # length
+% 47 # length
 project (
-| project (
-| | distinct except (
-| | | project (
-| | | | table(sys.t2606a) [ "t2606a"."a" ] COUNT 
-| | | ) [ "t2606a"."a" as "%3"."a" ],
-| | | project (
-| | | | table(sys.t2606b) [ "t2606b"."a" ] COUNT 
-| | | ) [ "t2606b"."a" as "%4"."a" ]
-| | ) [ "%3"."a" as "%7"."a" ]
-| ) [ "%7"."a" ]
+| distinct except (
+| | project (
+| | | table(sys.t2606a) [ "t2606a"."a" ] COUNT 
+| | ) [ "t2606a"."a" as "%3"."a" ],
+| | project (
+| | | table(sys.t2606b) [ "t2606b"."a" ] COUNT 
+| | ) [ "t2606b"."a" as "%4"."a" ]
+| ) [ "%3"."a" as "%7"."a" ]
 ) [ "%7"."a" ] [ "%7"."a" ASC ]
 #( select * from t2606a   except   select * from t2606b ) order by a;
 % sys.%7 # table_name
@@ -215,18 +205,16 @@ project (
 % .plan # table_name
 % rel # name
 % clob # type
-% 49 # length
+% 47 # length
 project (
-| project (
-| | distinct except (
-| | | project (
-| | | | table(sys.t2606a) [ "t2606a"."a" ] COUNT 
-| | | ) [ "t2606a"."a" as "%3"."a" ],
-| | | project (
-| | | | table(sys.t2606b) [ "t2606b"."a" ] COUNT 
-| | | ) [ "t2606b"."a" as "%4"."a" ]
-| | ) [ "%3"."a" as "%7"."a" ]
-| ) [ "%7"."a" ]
+| distinct except (
+| | project (
+| | | table(sys.t2606a) [ "t2606a"."a" ] COUNT 
+| | ) [ "t2606a"."a" as "%3"."a" ],
+| | project (
+| | | table(sys.t2606b) [ "t2606b"."a" ] COUNT 
+| | ) [ "t2606b"."a" as "%4"."a" ]
+| ) [ "%3"."a" as "%7"."a" ]
 ) [ "%7"."a" ] [ "%7"."a" ASC ]
 #( select * from t2606a ) except ( select * from t2606b ) order by a;
 % sys.%7 # table_name
@@ -240,18 +228,16 @@ project (
 % .plan # table_name
 % rel # name
 % clob # type
-% 49 # length
+% 47 # length
 project (
-| project (
-| | distinct intersect (
-| | | project (
-| | | | table(sys.t2606a) [ "t2606a"."a" ] COUNT 
-| | | ) [ "t2606a"."a" as "%3"."a" ],
-| | | project (
-| | | | table(sys.t2606b) [ "t2606b"."a" ] COUNT 
-| | | ) [ "t2606b"."a" as "%4"."a" ]
-| | ) [ "%3"."a" as "%7"."a" ]
-| ) [ "%7"."a" ]
+| distinct intersect (
+| | project (
+| | | table(sys.t2606a) [ "t2606a"."a" ] COUNT 
+| | ) [ "t2606a"."a" as "%3"."a" ],
+| | project (
+| | | table(sys.t2606b) [ "t2606b"."a" ] COUNT 
+| | ) [ "t2606b"."a" as "%4"."a" ]
+| ) [ "%3"."a" as "%7"."a" ]
 ) [ "%7"."a" ] [ "%7"."a" ASC ]
 #select * from t2606a   intersect   select * from t2606b   order by a;
 % sys.%7 # table_name
@@ -265,18 +251,16 @@ project (
 % .plan # table_name
 % rel # name
 % clob # type
-% 49 # length
+% 47 # length
 project (
-| project (
-| | distinct intersect (
-| | | project (
-| | | | table(sys.t2606a) [ "t2606a"."a" ] COUNT 
-| | | ) [ "t2606a"."a" as "%3"."a" ],
-| | | project (
-| | | | table(sys.t2606b) [ "t2606b"."a" ] COUNT 
-| | | ) [ "t2606b"."a" as "%4"."a" ]
-| | ) [ "%3"."a" as "%7"."a" ]
-| ) [ "%7"."a" ]
+| distinct intersect (
+| | project (
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to