Changeset: 432f0a4a6acb for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=432f0a4a6acb
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: Oct2020
Log Message:
fixed issue with project_push_down which removed a needed project
diffs (228 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
@@ -381,7 +381,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
@@ -5566,8 +5566,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_set(l->op) || is_select(l->op)
- || is_join(l->op) || is_semi(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
@@ -71,19 +71,19 @@ end user.main;
% clob # type
% 189 # length
function user.main():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, 21: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, 31: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.main;
#inline actions= 0 time=1 usec
#remap actions= 0 time=1 usec
@@ -117,40 +117,40 @@ end user.main;
% clob # type
% 194 # length
function user.main():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, 63: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, 73: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.main;
#inline actions= 0 time=1 usec
#remap actions= 0 time=2 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
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list