Changeset: 1549627ec354 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/1549627ec354
Modified Files:
        sql/server/rel_optimize_exps.c
        sql/server/rel_optimize_others.c
        sql/server/rel_optimize_proj.c
        sql/server/rel_optimize_sel.c
        sql/server/rel_optimizer_private.h
Branch: sqloptimizer
Log Message:

Give possibility to disable individual optimizers


diffs (293 lines):

diff --git a/sql/server/rel_optimize_exps.c b/sql/server/rel_optimize_exps.c
--- a/sql/server/rel_optimize_exps.c
+++ b/sql/server/rel_optimize_exps.c
@@ -371,7 +371,9 @@ rel_simplify_math(visitor *v, global_pro
 run_optimizer
 bind_simplify_math(visitor *v, global_props *gp)
 {
-       return gp->opt_cycle == 0 && gp->opt_level == 1 && v->value_based_opt 
&& (gp->cnt[op_project] || gp->cnt[op_ddl] || gp->cnt[ddl_psm]) ? 
rel_simplify_math : NULL;
+       int flag = v->sql->sql_optimizer;
+       return gp->opt_cycle == 0 && gp->opt_level == 1 && v->value_based_opt 
&& (gp->cnt[op_project]
+                  || gp->cnt[op_ddl] || gp->cnt[ddl_psm]) && (flag & 
simplify_math) ? rel_simplify_math : NULL;
 }
 
 
@@ -788,6 +790,8 @@ rel_optimize_exps(visitor *v, global_pro
 run_optimizer
 bind_optimize_exps(visitor *v, global_props *gp)
 {
-       (void) v;
-       return gp->opt_cycle < 2 && gp->opt_level == 1 && (gp->cnt[op_project] 
|| gp->cnt[op_join] || gp->cnt[op_left] || gp->cnt[op_right] || 
gp->cnt[op_full] || gp->cnt[op_semi] || gp->cnt[op_anti] || gp->cnt[op_select]) 
? rel_optimize_exps : NULL;
+       int flag = v->sql->sql_optimizer;
+       return gp->opt_cycle < 2 && gp->opt_level == 1 && (gp->cnt[op_project] 
|| gp->cnt[op_join]
+                  || gp->cnt[op_left] || gp->cnt[op_right] || gp->cnt[op_full] 
|| gp->cnt[op_semi]
+                  || gp->cnt[op_anti] || gp->cnt[op_select]) && (flag & 
optimize_exps) ? rel_optimize_exps : NULL;
 }
diff --git a/sql/server/rel_optimize_others.c b/sql/server/rel_optimize_others.c
--- a/sql/server/rel_optimize_others.c
+++ b/sql/server/rel_optimize_others.c
@@ -1004,8 +1004,8 @@ rel_dce(visitor *v, global_props *gp, sq
 run_optimizer
 bind_dce(visitor *v, global_props *gp)
 {
-       (void) v;
-       return gp->opt_cycle == 0 && gp->opt_level == 1 ? rel_dce : NULL;
+       int flag = v->sql->sql_optimizer;
+       return gp->opt_cycle == 0 && gp->opt_level == 1 && (flag & dce) ? 
rel_dce : NULL;
 }
 
 
@@ -1259,6 +1259,7 @@ rel_push_topn_and_sample_down(visitor *v
 run_optimizer
 bind_push_topn_and_sample_down(visitor *v, global_props *gp)
 {
-       (void) v;
-       return gp->opt_level == 1 && (gp->cnt[op_topn] || gp->cnt[op_sample]) ? 
rel_push_topn_and_sample_down : NULL;
+       int flag = v->sql->sql_optimizer;
+       return gp->opt_level == 1 && (gp->cnt[op_topn] || gp->cnt[op_sample]) &&
+                  (flag & push_topn_and_sample_down) ? 
rel_push_topn_and_sample_down : NULL;
 }
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
@@ -103,8 +103,9 @@ rel_push_project_down(visitor *v, global
 run_optimizer
 bind_push_project_down(visitor *v, global_props *gp)
 {
-       (void) v;
-       return gp->opt_level == 1 && (gp->cnt[op_project] || 
gp->cnt[op_groupby]) ? rel_push_project_down : NULL;
+       int flag = v->sql->sql_optimizer;
+       return gp->opt_level == 1 && (flag & push_project_down) &&
+                  (gp->cnt[op_project] || gp->cnt[op_groupby]) ? 
rel_push_project_down : NULL;
 }
 
 
@@ -313,8 +314,9 @@ rel_merge_projects(visitor *v, global_pr
 run_optimizer
 bind_merge_projects(visitor *v, global_props *gp)
 {
-       (void) v;
-       return gp->opt_level == 1 && (gp->cnt[op_project] || 
gp->cnt[op_groupby]) ? rel_merge_projects : NULL;
+       int flag = v->sql->sql_optimizer;
+       return gp->opt_level == 1 && (flag & merge_projects) &&
+                  (gp->cnt[op_project] || gp->cnt[op_groupby]) ? 
rel_merge_projects : NULL;
 }
 
 
@@ -684,8 +686,9 @@ rel_push_project_up(visitor *v, global_p
 run_optimizer
 bind_push_project_up(visitor *v, global_props *gp)
 {
-       (void) v;
-       return gp->opt_level == 1 && gp->cnt[op_project] ? rel_push_project_up 
: NULL;
+       int flag = v->sql->sql_optimizer;
+       return gp->opt_level == 1 && (flag & push_project_up) &&
+                  gp->cnt[op_project] ? rel_push_project_up : NULL;
 }
 
 
@@ -881,8 +884,9 @@ rel_split_project(visitor *v, global_pro
 run_optimizer
 bind_split_project(visitor *v, global_props *gp)
 {
-       (void) v;
-       return gp->opt_cycle == 0 && gp->opt_level == 1 && (gp->cnt[op_project] 
|| gp->cnt[op_groupby]) ? rel_split_project : NULL;
+       int flag = v->sql->sql_optimizer;
+       return gp->opt_cycle == 0 && gp->opt_level == 1 && (flag & 
split_project) &&
+                  (gp->cnt[op_project] || gp->cnt[op_groupby]) ? 
rel_split_project : NULL;
 }
 
 
@@ -936,8 +940,8 @@ rel_project_reduce_casts(visitor *v, glo
 run_optimizer
 bind_project_reduce_casts(visitor *v, global_props *gp)
 {
-       (void) v;
-       return gp->cnt[op_project] ? rel_project_reduce_casts : NULL;
+       int flag = v->sql->sql_optimizer;
+       return gp->cnt[op_project] && (flag & project_reduce_casts) ? 
rel_project_reduce_casts : NULL;
 }
 
 
@@ -1278,8 +1282,9 @@ rel_optimize_unions_bottomup(visitor *v,
 run_optimizer
 bind_optimize_unions_bottomup(visitor *v, global_props *gp)
 {
-       (void) v;
-       return gp->opt_level == 1 && gp->cnt[op_union] ? 
rel_optimize_unions_bottomup : NULL;
+       int flag = v->sql->sql_optimizer;
+       return gp->opt_level == 1 && gp->cnt[op_union] && (flag & 
optimize_unions_bottomup)
+                  ? rel_optimize_unions_bottomup : NULL;
 }
 
 
@@ -2490,8 +2495,9 @@ rel_optimize_projections(visitor *v, glo
 run_optimizer
 bind_optimize_projections(visitor *v, global_props *gp)
 {
-       (void) v;
-       return gp->opt_level == 1 && (gp->cnt[op_groupby] || 
gp->cnt[op_project] || gp->cnt[op_union] || gp->cnt[op_inter] || 
gp->cnt[op_except]) ? rel_optimize_projections : NULL;
+       int flag = v->sql->sql_optimizer;
+       return gp->opt_level == 1 && (gp->cnt[op_groupby] || 
gp->cnt[op_project] || gp->cnt[op_union]
+                  || gp->cnt[op_inter] || gp->cnt[op_except]) && (flag & 
optimize_projections) ? rel_optimize_projections : NULL;
 }
 
 
@@ -3062,6 +3068,7 @@ rel_distinct_project2groupby(visitor *v,
 run_optimizer
 bind_distinct_project2groupby(visitor *v, global_props *gp)
 {
-       (void) v;
-       return gp->opt_cycle == 0 && gp->opt_level == 1 && gp->needs_distinct 
&& gp->cnt[op_project] ? rel_distinct_project2groupby : NULL;
+       int flag = v->sql->sql_optimizer;
+       return gp->opt_cycle == 0 && gp->opt_level == 1 && gp->needs_distinct 
&& gp->cnt[op_project] &&
+                  (flag & distinct_project2groupby)? 
rel_distinct_project2groupby : NULL;
 }
diff --git a/sql/server/rel_optimize_sel.c b/sql/server/rel_optimize_sel.c
--- a/sql/server/rel_optimize_sel.c
+++ b/sql/server/rel_optimize_sel.c
@@ -148,8 +148,9 @@ rel_split_select(visitor *v, global_prop
 run_optimizer
 bind_split_select(visitor *v, global_props *gp)
 {
-       (void) v;
-       return gp->opt_cycle == 0 && gp->opt_level == 1 && gp->cnt[op_select] ? 
rel_split_select : NULL;
+       int flag = v->sql->sql_optimizer;
+       return gp->opt_cycle == 0 && gp->opt_level == 1 && (flag & split_select)
+                  && gp->cnt[op_select] ? rel_split_select : NULL;
 }
 
 
@@ -214,8 +215,10 @@ rel_remove_redundant_join(visitor *v, gl
 run_optimizer
 bind_remove_redundant_join(visitor *v, global_props *gp)
 {
-       (void) v;
-       return gp->opt_cycle == 0 && gp->opt_level == 1 && (gp->cnt[op_left] || 
gp->cnt[op_right] || gp->cnt[op_full] || gp->cnt[op_join] || gp->cnt[op_semi] 
|| gp->cnt[op_anti]) ? rel_remove_redundant_join : NULL;
+       int flag = v->sql->sql_optimizer;
+       return gp->opt_cycle == 0 && gp->opt_level == 1 && (gp->cnt[op_left] || 
gp->cnt[op_right]
+                  || gp->cnt[op_full] || gp->cnt[op_join] || gp->cnt[op_semi] 
|| gp->cnt[op_anti]) &&
+                  (flag & remove_redundant_join) ? rel_remove_redundant_join : 
NULL;
 }
 
 
@@ -958,8 +961,10 @@ rel_optimize_select_and_joins_bottomup(v
 run_optimizer
 bind_optimize_select_and_joins_bottomup(visitor *v, global_props *gp)
 {
-       (void) v;
-       return gp->opt_level == 1 && (gp->cnt[op_join] || gp->cnt[op_left] || 
gp->cnt[op_right] || gp->cnt[op_full] || gp->cnt[op_semi] || gp->cnt[op_anti] 
|| gp->cnt[op_select]) ? rel_optimize_select_and_joins_bottomup : NULL;
+       int flag = v->sql->sql_optimizer;
+       return gp->opt_level == 1 && (gp->cnt[op_join] || gp->cnt[op_left] || 
gp->cnt[op_right] ||
+                  gp->cnt[op_full] || gp->cnt[op_semi] || gp->cnt[op_anti] ||
+                  gp->cnt[op_select]) && (flag & 
optimize_select_and_joins_bottomup) ? rel_optimize_select_and_joins_bottomup : 
NULL;
 }
 
 
@@ -1547,8 +1552,9 @@ rel_optimize_joins(visitor *v, global_pr
 run_optimizer
 bind_optimize_joins(visitor *v, global_props *gp)
 {
-       (void) v;
-       return gp->opt_level == 1 && (gp->cnt[op_join] || gp->cnt[op_left] || 
gp->cnt[op_right] || gp->cnt[op_full] || gp->cnt[op_semi] || gp->cnt[op_anti]) 
? rel_optimize_joins : NULL;
+       int flag = v->sql->sql_optimizer;
+       return gp->opt_level == 1 && (gp->cnt[op_join] || gp->cnt[op_left] || 
gp->cnt[op_right]
+                  || gp->cnt[op_full] || gp->cnt[op_semi] || gp->cnt[op_anti]) 
&& (flag & optimize_joins) ? rel_optimize_joins : NULL;
 }
 
 
@@ -2444,8 +2450,9 @@ rel_join_order(visitor *v, global_props 
 run_optimizer
 bind_join_order(visitor *v, global_props *gp)
 {
-       (void) v;
-       return gp->opt_level == 1 && !gp->cnt[op_update] && (gp->cnt[op_join] 
|| gp->cnt[op_left] || gp->cnt[op_right] || gp->cnt[op_full] || 
gp->cnt[op_semi] || gp->cnt[op_anti]) ? rel_join_order : NULL;
+       int flag = v->sql->sql_optimizer;
+       return gp->opt_level == 1 && !gp->cnt[op_update] && (gp->cnt[op_join] 
|| gp->cnt[op_left] ||
+                  gp->cnt[op_right] || gp->cnt[op_full] || gp->cnt[op_semi] || 
gp->cnt[op_anti]) && (flag & join_order) ? rel_join_order : NULL;
 }
 
 
@@ -2785,8 +2792,9 @@ run_optimizer
 bind_optimize_semi_and_anti(visitor *v, global_props *gp)
 {
        /* Important -> Re-write semijoins after rel_join_order */
-       (void) v;
-       return gp->opt_level == 1 && (gp->cnt[op_join] || gp->cnt[op_left] || 
gp->cnt[op_right] || gp->cnt[op_full] || gp->cnt[op_semi] || gp->cnt[op_anti]) 
? rel_optimize_semi_and_anti : NULL;
+       int flag = v->sql->sql_optimizer;
+       return gp->opt_level == 1 && (gp->cnt[op_join] || gp->cnt[op_left] || 
gp->cnt[op_right]
+                  || gp->cnt[op_full] || gp->cnt[op_semi] || gp->cnt[op_anti]) 
&& (flag & optimize_semi_and_anti) ? rel_optimize_semi_and_anti : NULL;
 }
 
 
@@ -3539,8 +3547,10 @@ rel_optimize_select_and_joins_topdown(vi
 run_optimizer
 bind_optimize_select_and_joins_topdown(visitor *v, global_props *gp)
 {
-       (void) v;
-       return gp->opt_level == 1 && (gp->cnt[op_join] || gp->cnt[op_left] || 
gp->cnt[op_right] || gp->cnt[op_full] || gp->cnt[op_semi] || gp->cnt[op_anti] 
|| gp->cnt[op_select]) ? rel_optimize_select_and_joins_topdown : NULL;
+       int flag = v->sql->sql_optimizer;
+       return gp->opt_level == 1 && (gp->cnt[op_join] || gp->cnt[op_left] || 
gp->cnt[op_right]
+                  || gp->cnt[op_full] || gp->cnt[op_semi] || gp->cnt[op_anti] 
||
+                  gp->cnt[op_select]) && (flag & 
optimize_select_and_joins_topdown) ? rel_optimize_select_and_joins_topdown : 
NULL;
 }
 
 
@@ -3795,8 +3805,10 @@ rel_push_func_and_select_down(visitor *v
 run_optimizer
 bind_push_func_and_select_down(visitor *v, global_props *gp)
 {
-       (void) v;
-       return gp->opt_level == 1 && (gp->cnt[op_join] || gp->cnt[op_left] || 
gp->cnt[op_right] || gp->cnt[op_full] || gp->cnt[op_semi] || gp->cnt[op_anti] 
|| gp->cnt[op_select]) ? rel_push_func_and_select_down : NULL;
+       int flag = v->sql->sql_optimizer;
+       return gp->opt_level == 1 && (gp->cnt[op_join] || gp->cnt[op_left] || 
gp->cnt[op_right]
+                       || gp->cnt[op_full] || gp->cnt[op_semi] || 
gp->cnt[op_anti] || gp->cnt[op_select])
+                       && (flag & push_func_and_select_down) ? 
rel_push_func_and_select_down : NULL;
 }
 
 
@@ -3871,6 +3883,7 @@ rel_push_select_up(visitor *v, global_pr
 run_optimizer
 bind_push_select_up(visitor *v, global_props *gp)
 {
-       (void) v;
-       return gp->opt_level == 1 && gp->cnt[op_select] && (gp->cnt[op_join] || 
gp->cnt[op_left] || gp->cnt[op_right] || gp->cnt[op_full] || gp->cnt[op_semi] 
|| gp->cnt[op_anti]) ? rel_push_select_up : NULL;
+       int flag = v->sql->sql_optimizer;
+       return gp->opt_level == 1 && gp->cnt[op_select] && (gp->cnt[op_join] || 
gp->cnt[op_left] ||
+                  gp->cnt[op_right] || gp->cnt[op_full] || gp->cnt[op_semi] || 
gp->cnt[op_anti]) && (flag & push_select_up) ? rel_push_select_up : NULL;
 }
diff --git a/sql/server/rel_optimizer_private.h 
b/sql/server/rel_optimizer_private.h
--- a/sql/server/rel_optimizer_private.h
+++ b/sql/server/rel_optimizer_private.h
@@ -33,6 +33,31 @@ typedef struct sql_optimizer {
        run_optimizer (*bind_optimizer)(visitor *v, global_props *gp); /* if 
cannot run (disabled or not needed) returns NULL */
 } sql_optimizer;
 
+/* At the moment the follwowing optimizers 'packs' can be disabled,
+   later we could disable individual optimizers from the 'pack' */
+#define split_select                        (1 << 0)
+#define push_project_down                   (1 << 1)
+#define merge_projects                      (1 << 2)
+#define push_project_up                     (1 << 3)
+#define split_project                       (1 << 4)
+#define remove_redundant_join               (1 << 5)
+#define simplify_math                       (1 << 6)
+#define optimize_exps                       (1 << 7)
+#define optimize_select_and_joins_bottomup  (1 << 8)
+#define project_reduce_casts                (1 << 9)
+#define optimize_unions_bottomup           (1 << 10)
+#define optimize_projections               (1 << 11)
+#define optimize_joins                     (1 << 12)
+#define join_order                         (1 << 13)
+#define optimize_semi_and_anti             (1 << 14)
+#define optimize_select_and_joins_topdown  (1 << 15)
+#define optimize_unions_topdown            (1 << 16)
+#define dce                                (1 << 17)
+#define push_func_and_select_down          (1 << 18)
+#define push_topn_and_sample_down          (1 << 19)
+#define distinct_project2groupby           (1 << 20)
+#define push_select_up                     (1 << 21)
+
 extern run_optimizer bind_split_select(visitor *v, global_props *gp) 
__attribute__((__visibility__("hidden")));
 extern run_optimizer bind_push_project_down(visitor *v, global_props *gp) 
__attribute__((__visibility__("hidden")));
 extern run_optimizer bind_merge_projects(visitor *v, global_props *gp) 
__attribute__((__visibility__("hidden")));
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to