Changeset: 5f66a91f2f8c for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5f66a91f2f8c Modified Files: sql/common/sql_list.c sql/server/rel_optimizer.c sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-explain-2join-query.stable.out sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-2join-query.stable.out Branch: Jun2020 Log Message:
fixed issue with project_push_down which removed a needed project diffs (259 lines): diff --git a/sql/common/sql_list.c b/sql/common/sql_list.c --- a/sql/common/sql_list.c +++ b/sql/common/sql_list.c @@ -377,7 +377,7 @@ list_check_prop_all(list *l, prop_check_ { int res = 1; if (l) - for (node *n = l->h; n; n = n->next) + for (node *n = l->h; n && res; n = n->next) res &= f(n->data); return res; } 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 @@ -5651,7 +5651,9 @@ rel_push_project_down(visitor *v, sql_re } return rel; } else if (list_check_prop_all(rel->exps, (prop_check_func)&exp_is_useless_rename)) { - 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)) { + if ((is_project(l->op) && list_length(l->exps) == list_length(rel->exps)) || + ((v->parent && is_project(v->parent->op)) && (is_set(l->op) || is_select(l->op) || is_join(l->op) || is_semi(l->op))) || + is_topn(l->op) || is_sample(l->op)) { rel->l = NULL; rel_destroy(rel); v->changes++; diff --git a/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-explain-2join-query.stable.out b/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-explain-2join-query.stable.out --- a/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-explain-2join-query.stable.out +++ b/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-explain-2join-query.stable.out @@ -39,7 +39,7 @@ function user.s4_0():void; X_23:lng := aggr.count(C_5:bat[:oid]); sql.resultSet(".%5":str, "%5":str, "bigint":str, 64:int, 0:int, 7:int, X_23:lng); end user.s4_0; -#inline actions= 0 time=1 usec +#inline actions= 0 time=0 usec #remap actions= 0 time=1 usec #costmodel actions= 1 time=0 usec #coercion actions= 0 time=1 usec @@ -71,21 +71,21 @@ end user.s4_0; % clob # type % 189 # length function user.s6_0():void; - X_1:void := querylog.define("explain select id from fk left outer join pk1 on fk.fk1 = pk1.pk1 left outer join pk2 on fk.fk2 = pk2.pk2 order by id;":str, "sequential_pipe":str, 22:int); - X_30:bat[:str] := bat.pack("sys.fk":str); - X_31:bat[:str] := bat.pack("id":str); - X_32:bat[:str] := bat.pack("int":str); - X_33:bat[:int] := bat.pack(32:int); - X_34:bat[:int] := bat.pack(0:int); + X_1:void := querylog.define("explain select id from fk left outer join pk1 on fk.fk1 = pk1.pk1 left outer join pk2 on fk.fk2 = pk2.pk2 order by id;":str, "sequential_pipe":str, 32:int); + X_44:bat[:str] := bat.pack("sys.fk":str); + X_45:bat[:str] := bat.pack("id":str); + X_46:bat[:str] := bat.pack("int":str); + X_47:bat[:int] := bat.pack(32:int); + X_48:bat[:int] := bat.pack(0:int); X_4:int := sql.mvc(); C_5:bat[:oid] := sql.tid(X_4:int, "sys":str, "fk":str); X_17:bat[:int] := sql.bind(X_4:int, "sys":str, "fk":str, "id":str, 0:int); - X_22:bat[:int] := algebra.projection(C_5:bat[:oid], X_17:bat[:int]); - (X_23:bat[:int], X_24:bat[:oid]) := algebra.sort(X_22:bat[:int], false:bit, false:bit, false:bit); - X_28:bat[:int] := algebra.projection(X_24:bat[:oid], X_22:bat[:int]); - sql.resultSet(X_30:bat[:str], X_31:bat[:str], X_32:bat[:str], X_33:bat[:int], X_34:bat[:int], X_28:bat[:int]); + X_34:bat[:int] := algebra.projection(C_5:bat[:oid], X_17:bat[:int]); + (X_37:bat[:int], X_38:bat[:oid]) := algebra.sort(X_34:bat[:int], false:bit, false:bit, false:bit); + X_42:bat[:int] := algebra.projection(X_38:bat[:oid], X_34:bat[:int]); + sql.resultSet(X_44:bat[:str], X_45:bat[:str], X_46:bat[:str], X_47:bat[:int], X_48:bat[:int], X_42:bat[:int]); end user.s6_0; -#inline actions= 0 time=0 usec +#inline actions= 0 time=1 usec #remap actions= 0 time=1 usec #costmodel actions= 1 time=1 usec #coercion actions= 0 time=1 usec @@ -117,40 +117,40 @@ end user.s6_0; % clob # type % 194 # length function user.s8_0():void; - X_1:void := querylog.define("explain select id , v1 from fk left outer join pk1 on fk.fk1 = pk1.pk1 left outer join pk2 on fk.fk2 = pk2.pk2 order by id;":str, "sequential_pipe":str, 64:int); - X_54:bat[:int] := bat.new(nil:int); + X_1:void := querylog.define("explain select id , v1 from fk left outer join pk1 on fk.fk1 = pk1.pk1 left outer join pk2 on fk.fk2 = pk2.pk2 order by id;":str, "sequential_pipe":str, 74:int); + X_61:bat[:int] := bat.new(nil:int); X_4:int := sql.mvc(); C_5:bat[:oid] := sql.tid(X_4:int, "sys":str, "fk":str); X_22:bat[:oid] := sql.bind_idxbat(X_4:int, "sys":str, "fk":str, "fk_fk1_fkey":str, 0:int); (X_25:bat[:oid], X_26:bat[:oid]) := sql.bind_idxbat(X_4:int, "sys":str, "fk":str, "fk_fk1_fkey":str, 2:int); X_24:bat[:oid] := sql.bind_idxbat(X_4:int, "sys":str, "fk":str, "fk_fk1_fkey":str, 1:int); X_27:bat[:oid] := sql.delta(X_22:bat[:oid], X_25:bat[:oid], X_26:bat[:oid], X_24:bat[:oid]); - X_43:bat[:oid] := algebra.projection(C_5:bat[:oid], X_27:bat[:oid]); - C_28:bat[:oid] := sql.tid(X_4:int, "sys":str, "pk1":str); - (X_45:bat[:oid], X_46:bat[:oid]) := algebra.join(X_43:bat[:oid], C_28:bat[:oid], nil:BAT, nil:BAT, false:bit, nil:lng); + X_49:bat[:oid] := algebra.projection(C_5:bat[:oid], X_27:bat[:oid]); + C_34:bat[:oid] := sql.tid(X_4:int, "sys":str, "pk1":str); + (X_52:bat[:oid], X_53:bat[:oid]) := algebra.join(X_49:bat[:oid], C_34:bat[:oid], nil:BAT, nil:BAT, false:bit, nil:lng); X_17:bat[:int] := sql.bind(X_4:int, "sys":str, "fk":str, "id":str, 0:int); - X_42:bat[:int] := algebra.projection(C_5:bat[:oid], X_17:bat[:int]); - X_53:bat[:int] := algebra.projection(X_45:bat[:oid], X_42:bat[:int]); - C_51:bat[:oid] := bat.mirror(X_42:bat[:int]); - C_52:bat[:oid] := algebra.difference(C_51:bat[:oid], X_45:bat[:oid], nil:BAT, nil:BAT, false:bit, false:bit, nil:lng); - X_36:bat[:int] := sql.bind(X_4:int, "sys":str, "pk1":str, "v1":str, 0:int); - X_56:bat[:int] := bat.append(X_54:bat[:int], X_53:bat[:int], true:bit); - X_58:bat[:int] := algebra.projection(C_52:bat[:oid], X_42:bat[:int]); - X_59:bat[:int] := bat.append(X_56:bat[:int], X_58:bat[:int], true:bit); - X_67:bat[:int] := bat.new(nil:int); - X_66:bat[:int] := algebra.projectionpath(X_46:bat[:oid], C_28:bat[:oid], X_36:bat[:int]); - X_68:bat[:int] := bat.append(X_67:bat[:int], X_66:bat[:int], true:bit); - X_70:bat[:int] := algebra.project(C_52:bat[:oid], nil:int); - X_71:bat[:int] := bat.append(X_68:bat[:int], X_70:bat[:int], true:bit); - X_84:bat[:str] := bat.pack(".fk":str, ".pk1":str); - X_85:bat[:str] := bat.pack("id":str, "v1":str); - X_86:bat[:str] := bat.pack("int":str, "int":str); - X_87:bat[:int] := bat.pack(32:int, 32:int); - X_88:bat[:int] := bat.pack(0:int, 0:int); - (X_78:bat[:int], X_79:bat[:oid]) := algebra.sort(X_59:bat[:int], false:bit, false:bit, false:bit); - X_81:bat[:int] := algebra.projection(X_79:bat[:oid], X_59:bat[:int]); - X_82:bat[:int] := algebra.projection(X_79:bat[:oid], X_71:bat[:int]); - sql.resultSet(X_84:bat[:str], X_85:bat[:str], X_86:bat[:str], X_87:bat[:int], X_88:bat[:int], X_81:bat[:int], X_82:bat[:int]); + X_48:bat[:int] := algebra.projection(C_5:bat[:oid], X_17:bat[:int]); + X_60:bat[:int] := algebra.projection(X_52:bat[:oid], X_48:bat[:int]); + C_58:bat[:oid] := bat.mirror(X_48:bat[:int]); + C_59:bat[:oid] := algebra.difference(C_58:bat[:oid], X_52:bat[:oid], nil:BAT, nil:BAT, false:bit, false:bit, nil:lng); + X_42:bat[:int] := sql.bind(X_4:int, "sys":str, "pk1":str, "v1":str, 0:int); + X_63:bat[:int] := bat.append(X_61:bat[:int], X_60:bat[:int], true:bit); + X_65:bat[:int] := algebra.projection(C_59:bat[:oid], X_48:bat[:int]); + X_66:bat[:int] := bat.append(X_63:bat[:int], X_65:bat[:int], true:bit); + X_79:bat[:int] := bat.new(nil:int); + X_78:bat[:int] := algebra.projectionpath(X_53:bat[:oid], C_34:bat[:oid], X_42:bat[:int]); + X_80:bat[:int] := bat.append(X_79:bat[:int], X_78:bat[:int], true:bit); + X_82:bat[:int] := algebra.project(C_59:bat[:oid], nil:int); + X_83:bat[:int] := bat.append(X_80:bat[:int], X_82:bat[:int], true:bit); + X_98:bat[:str] := bat.pack(".fk":str, ".pk1":str); + X_99:bat[:str] := bat.pack("id":str, "v1":str); + X_100:bat[:str] := bat.pack("int":str, "int":str); + X_101:bat[:int] := bat.pack(32:int, 32:int); + X_102:bat[:int] := bat.pack(0:int, 0:int); + (X_90:bat[:int], X_91:bat[:oid]) := algebra.sort(X_66:bat[:int], false:bit, false:bit, false:bit); + X_95:bat[:int] := algebra.projection(X_91:bat[:oid], X_66:bat[:int]); + X_96:bat[:int] := algebra.projection(X_91:bat[:oid], X_83:bat[:int]); + sql.resultSet(X_98:bat[:str], X_99:bat[:str], X_100:bat[:str], X_101:bat[:int], X_102:bat[:int], X_95:bat[:int], X_96:bat[:int]); end user.s8_0; #inline actions= 0 time=1 usec #remap actions= 0 time=2 usec @@ -239,12 +239,13 @@ function user.s10_0():void; X_136:bat[:int] := algebra.projection(X_131:bat[:oid], X_123:bat[:int]); sql.resultSet(X_138:bat[:str], X_139:bat[:str], X_140:bat[:str], X_141:bat[:int], X_142:bat[:int], X_135:bat[:int], X_136:bat[:int]); end user.s10_0; -#inline actions= 0 time=1 usec -#remap actions= 0 time=2 usec -#costmodel actions= 1 time=1 usec -#coercion actions= 2 time=6 usec -#evaluate actions= 0 time=7 usec -#emptybind actions= 2 time=8 usec +#inline actions= 0 time=2 usec +#remap actions= 0 time=3 usec +#costmodel actions= 1 time=2 usec +#coercion actions= 3 time=9 usec +#aliases actions= 3 time=11 usec +#evaluate actions= 0 time=10 usec +#emptybind actions= 4 time=14 usec #pushselect actions= 0 time=2 usec #aliases actions= 2 time=26 usec #mergetable actions= 0 time=52 usec diff --git a/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-2join-query.stable.out b/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-2join-query.stable.out --- a/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-2join-query.stable.out +++ b/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-2join-query.stable.out @@ -41,19 +41,19 @@ project ( % .plan # table_name % rel # name % clob # type -% 69 # length +% 168 # length project ( -| table(sys.fk) [ "fk"."id" NOT NULL HASHCOL ] COUNT +| table(sys.fk) [ "fk"."id" NOT NULL HASHCOL , "fk"."%fk_fk1_fkey" NOT NULL JOINIDX sys.fk.fk_fk1_fkey, "fk"."%fk_fk2_fkey" NOT NULL JOINIDX sys.fk.fk_fk2_fkey ] COUNT ) [ "fk"."id" NOT NULL HASHCOL ] [ "fk"."id" ASC NOT NULL HASHCOL ] #plan select id , v1 from fk left outer join pk1 on fk.fk1 = pk1.pk1 left outer join pk2 on fk.fk2 = pk2.pk2 order by id; % .plan # table_name % rel # name % clob # type -% 114 # length +% 171 # length project ( | left outer join ( -| | table(sys.fk) [ "fk"."id" NOT NULL HASHCOL , "fk"."%fk_fk1_fkey" NOT NULL JOINIDX sys.fk.fk_fk1_fkey ] COUNT , +| | table(sys.fk) [ "fk"."id" NOT NULL HASHCOL , "fk"."%fk_fk1_fkey" NOT NULL JOINIDX sys.fk.fk_fk1_fkey, "fk"."%fk_fk2_fkey" NOT NULL JOINIDX sys.fk.fk_fk2_fkey ] COUNT , | | table(sys.pk1) [ "pk1"."v1", "pk1"."%TID%" NOT NULL ] COUNT | ) [ "fk"."%fk_fk1_fkey" NOT NULL = "pk1"."%TID%" NOT NULL JOINIDX sys.fk.fk_fk1_fkey ] ) [ "fk"."id" NOT NULL HASHCOL , "pk1"."v1" ] [ "fk"."id" ASC NOT NULL HASHCOL ] @@ -86,19 +86,19 @@ project ( % .plan # table_name % rel # name % clob # type -% 69 # length +% 168 # length project ( -| table(sys.fk) [ "fk"."id" NOT NULL HASHCOL ] COUNT +| table(sys.fk) [ "fk"."id" NOT NULL HASHCOL , "fk"."%fk_fk1_fkey" NOT NULL JOINIDX sys.fk.fk_fk1_fkey, "fk"."%fk_fk2_fkey" NOT NULL JOINIDX sys.fk.fk_fk2_fkey ] COUNT ) [ "fk"."id" NOT NULL HASHCOL ] [ "fk"."id" ASC NOT NULL HASHCOL ] #plan select id , v1 from pk2 right outer join (pk1 right outer join fk on fk.fk1 = pk1.pk1) on fk.fk2 = pk2.pk2 order by id; % .plan # table_name % rel # name % clob # type -% 113 # length +% 170 # length project ( | right outer join ( | | table(sys.pk1) [ "pk1"."v1", "pk1"."%TID%" NOT NULL ] COUNT , -| | table(sys.fk) [ "fk"."id" NOT NULL HASHCOL , "fk"."%fk_fk1_fkey" NOT NULL JOINIDX sys.fk.fk_fk1_fkey ] COUNT +| | table(sys.fk) [ "fk"."id" NOT NULL HASHCOL , "fk"."%fk_fk1_fkey" NOT NULL JOINIDX sys.fk.fk_fk1_fkey, "fk"."%fk_fk2_fkey" NOT NULL JOINIDX sys.fk.fk_fk2_fkey ] COUNT | ) [ "fk"."%fk_fk1_fkey" NOT NULL = "pk1"."%TID%" NOT NULL JOINIDX sys.fk.fk_fk1_fkey ] ) [ "fk"."id" NOT NULL HASHCOL , "pk1"."v1" ] [ "fk"."id" ASC NOT NULL HASHCOL ] #plan select id , v2 from pk2 right outer join (pk1 right outer join fk on fk.fk1 = pk1.pk1) on fk.fk2 = pk2.pk2 order by id; @@ -129,19 +129,19 @@ project ( % .plan # table_name % rel # name % clob # type -% 54 # length +% 168 # length project ( -| table(sys.fk) [ "fk"."id" NOT NULL HASHCOL ] COUNT +| table(sys.fk) [ "fk"."id" NOT NULL HASHCOL , "fk"."%fk_fk1_fkey" NOT NULL JOINIDX sys.fk.fk_fk1_fkey, "fk"."%fk_fk2_fkey" NOT NULL JOINIDX sys.fk.fk_fk2_fkey ] COUNT ) [ "fk"."id" HASHCOL ] [ "fk"."id" ASC HASHCOL ] #plan select id , v1 from pk2 full outer join (pk1 full outer join fk on fk.fk1 = pk1.pk1) on fk.fk2 = pk2.pk2 order by id; % .plan # table_name % rel # name % clob # type -% 113 # length +% 170 # length project ( | full outer join ( | | table(sys.pk1) [ "pk1"."v1", "pk1"."%TID%" NOT NULL ] COUNT , -| | table(sys.fk) [ "fk"."id" NOT NULL HASHCOL , "fk"."%fk_fk1_fkey" NOT NULL JOINIDX sys.fk.fk_fk1_fkey ] COUNT +| | table(sys.fk) [ "fk"."id" NOT NULL HASHCOL , "fk"."%fk_fk1_fkey" NOT NULL JOINIDX sys.fk.fk_fk1_fkey, "fk"."%fk_fk2_fkey" NOT NULL JOINIDX sys.fk.fk_fk2_fkey ] COUNT | ) [ "fk"."%fk_fk1_fkey" NOT NULL = "pk1"."%TID%" NOT NULL JOINIDX sys.fk.fk_fk1_fkey ] ) [ "fk"."id" HASHCOL , "pk1"."v1" ] [ "fk"."id" ASC HASHCOL ] #plan select id , v2 from pk2 full outer join (pk1 full outer join fk on fk.fk1 = pk1.pk1) on fk.fk2 = pk2.pk2 order by id; @@ -172,9 +172,9 @@ project ( % .plan # table_name % rel # name % clob # type -% 69 # length +% 168 # length project ( -| table(sys.fk) [ "fk"."id" NOT NULL HASHCOL ] COUNT +| table(sys.fk) [ "fk"."id" NOT NULL HASHCOL , "fk"."%fk_fk1_fkey" NOT NULL JOINIDX sys.fk.fk_fk1_fkey, "fk"."%fk_fk2_fkey" NOT NULL JOINIDX sys.fk.fk_fk2_fkey ] COUNT ) [ "fk"."id" NOT NULL HASHCOL ] [ "fk"."id" ASC NOT NULL HASHCOL ] #plan select id , v1 from pk2 join (pk1 join fk on fk.fk1 = pk1.pk1) on fk.fk2 = pk2.pk2 order by id; % .plan # table_name @@ -191,10 +191,10 @@ project ( % .plan # table_name % rel # name % clob # type -% 114 # length +% 171 # length project ( | join ( -| | table(sys.fk) [ "fk"."id" NOT NULL HASHCOL , "fk"."%fk_fk2_fkey" NOT NULL JOINIDX sys.fk.fk_fk2_fkey ] COUNT , +| | table(sys.fk) [ "fk"."id" NOT NULL HASHCOL , "fk"."%fk_fk1_fkey" NOT NULL JOINIDX sys.fk.fk_fk1_fkey, "fk"."%fk_fk2_fkey" NOT NULL JOINIDX sys.fk.fk_fk2_fkey ] COUNT , | | table(sys.pk2) [ "pk2"."v2", "pk2"."%TID%" NOT NULL ] COUNT | ) [ "fk"."%fk_fk2_fkey" NOT NULL = "pk2"."%TID%" NOT NULL JOINIDX sys.fk.fk_fk2_fkey ] ) [ "fk"."id" NOT NULL HASHCOL , "pk2"."v2" ] [ "fk"."id" ASC NOT NULL HASHCOL ] _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list