Changeset: a025809d22de for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/a025809d22de Modified Files: sql/backends/monet5/rel_bin.c sql/server/rel_exp.c sql/server/rel_exp.h sql/server/rel_unnest.c sql/test/BugTracker-2015/Tests/crash.Bug-3736.test Branch: Jul2021 Log Message:
on convert use expression (even if its a input any type (bound to be null)) in rewrite_compare check for depth of the inner relation. diffs (164 lines): diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c --- a/sql/backends/monet5/rel_bin.c +++ b/sql/backends/monet5/rel_bin.c @@ -1234,7 +1234,9 @@ exp_bin(backend *be, sql_exp *e, stmt *l stmt *l; if (from->type->localtype == 0) { - l = stmt_atom(be, atom_general(sql->sa, to, NULL)); + l = exp_bin(be, e->l, left, right, grp, ext, cnt, sel, depth+1, 0, push); + if (l) + l = stmt_atom(be, atom_general(sql->sa, to, NULL)); } else { l = exp_bin(be, e->l, left, right, grp, ext, cnt, sel, depth+1, 0, push); } diff --git a/sql/server/rel_exp.c b/sql/server/rel_exp.c --- a/sql/server/rel_exp.c +++ b/sql/server/rel_exp.c @@ -2046,6 +2046,29 @@ exps_rel_get_rel(sql_allocator *sa, list return xp; } +int +exp_rel_depth(sql_exp *e) +{ + if (!e) + return 0; + switch(e->type){ + case e_func: + case e_aggr: + case e_cmp: + return 1; + case e_convert: + return 0; + case e_psm: + if (exp_is_rel(e)) + return 0; + return 1; + case e_atom: + case e_column: + return 0; + } + return 0; +} + sql_rel * exp_rel_get_rel(sql_allocator *sa, sql_exp *e) { diff --git a/sql/server/rel_exp.h b/sql/server/rel_exp.h --- a/sql/server/rel_exp.h +++ b/sql/server/rel_exp.h @@ -160,6 +160,7 @@ extern int exps_have_func(list *exps); extern sql_rel *exp_rel_get_rel(sql_allocator *sa, sql_exp *e); extern sql_exp *exp_rel_update_exp(mvc *sql, sql_exp *e); extern sql_exp *exp_rel_label(mvc *sql, sql_exp *e); +extern int exp_rel_depth(sql_exp *e); extern int exps_are_atoms(list *exps); extern int exp_has_func(sql_exp *e); extern int exps_have_unsafe(list *exps, int allow_identity); diff --git a/sql/server/rel_unnest.c b/sql/server/rel_unnest.c --- a/sql/server/rel_unnest.c +++ b/sql/server/rel_unnest.c @@ -2781,8 +2781,10 @@ rewrite_compare(visitor *v, sql_rel *rel int quantifier = e->flag; /* possibly this is already done ? */ - if (exp_has_rel(ile)) + if (exp_has_rel(ile)) { + depth += exp_rel_depth(ile); lsq = exp_rel_get_rel(v->sql->sa, ile); /* get subquery */ + } if (lsq) le = exp_rel_update_exp(v->sql, ile); diff --git a/sql/test/BugTracker-2015/Tests/crash.Bug-3736.test b/sql/test/BugTracker-2015/Tests/crash.Bug-3736.test --- a/sql/test/BugTracker-2015/Tests/crash.Bug-3736.test +++ b/sql/test/BugTracker-2015/Tests/crash.Bug-3736.test @@ -117,47 +117,53 @@ join ( | table("sys"."bidder") [ "bidder"."id" NOT NULL HASHCOL as "b"."id", "bidder"."open_auction_id" NOT NULL as "b"."open_auction_id", "bidder"."date" NOT NULL as "b"."date", "bidder"."time" NOT NULL as "b"."time", "bidder"."personref" NOT NULL as "b"."personref", "bidder"."increase" NOT NULL as "b"."increase", "bidder"."%TID%" NOT NULL as "b"."%TID%" ] COUNT ) [ "o"."open_auction_id" NOT NULL = "b"."open_auction_id" NOT NULL ] REF 2 (2) -single project ( -| single join ( -| | & REF 1 , -| | project ( -| | | join ( -| | | | table("sys"."bidder") [ "bidder"."id" NOT NULL HASHCOL as "b3"."id", "bidder"."increase" NOT NULL as "b3"."increase", "bidder"."%TID%" NOT NULL as "b3"."%TID%" ] COUNT , -| | | | group by ( -| | | | | join ( -| | | | | | group by ( -| | | | | | | project ( -| | | | | | | | & REF 1 -| | | | | | | ) [ "o"."open_auction_id" NOT NULL ] -| | | | | | ) [ "o"."open_auction_id" NOT NULL ] [ "o"."open_auction_id" NOT NULL ], -| | | | | | table("sys"."bidder") [ "bidder"."id" NOT NULL HASHCOL as "b3a"."id", "bidder"."open_auction_id" NOT NULL as "b3a"."open_auction_id", "bidder"."%TID%" NOT NULL as "b3a"."%TID%" ] COUNT -| | | | | ) [ "b3a"."open_auction_id" NOT NULL = "o"."open_auction_id" NOT NULL ] -| | | | ) [ "o"."open_auction_id" NOT NULL ] [ "sys"."min" no nil ("b3a"."id" NOT NULL HASHCOL ) as "%1"."%1", "o"."open_auction_id" NOT NULL ] -| | | ) [ "b3"."id" NOT NULL HASHCOL = "%1"."%1" ] -| | ) [ "b3"."id" NOT NULL HASHCOL , "b3"."increase" NOT NULL, "b3"."%TID%" NOT NULL, "%1"."%1", "o"."open_auction_id" NOT NULL as "%5"."%5" ] -| ) [ "o"."open_auction_id" NOT NULL * = "%5"."%5" NOT NULL ] -) [ "o"."open_auction_id" NOT NULL, "o"."%TID%" NOT NULL, "b"."id" NOT NULL HASHCOL , "b"."open_auction_id" NOT NULL, "b"."date" NOT NULL, "b"."time" NOT NULL, "b"."personref" NOT NULL, "b"."increase" NOT NULL, "b"."%TID%" NOT NULL, "b3"."increase" NOT NULL as "%2"."%2" ] +single left outer join ( +| & REF 1 , +| project ( +| | select ( +| | | project ( +| | | | crossproduct ( +| | | | | table("sys"."bidder") [ "bidder"."id" NOT NULL HASHCOL as "b3"."id", "bidder"."increase" NOT NULL as "b3"."increase", "bidder"."%TID%" NOT NULL as "b3"."%TID%" ] COUNT , +| | | | | group by ( +| | | | | | join ( +| | | | | | | group by ( +| | | | | | | | project ( +| | | | | | | | | & REF 1 +| | | | | | | | ) [ "o"."open_auction_id" NOT NULL ] +| | | | | | | ) [ "o"."open_auction_id" NOT NULL ] [ "o"."open_auction_id" NOT NULL ], +| | | | | | | table("sys"."bidder") [ "bidder"."id" NOT NULL HASHCOL as "b3a"."id", "bidder"."open_auction_id" NOT NULL as "b3a"."open_auction_id", "bidder"."%TID%" NOT NULL as "b3a"."%TID%" ] COUNT +| | | | | | ) [ "b3a"."open_auction_id" NOT NULL = "o"."open_auction_id" NOT NULL ] +| | | | | ) [ "o"."open_auction_id" NOT NULL ] [ "sys"."min" no nil ("b3a"."id" NOT NULL HASHCOL ) as "%1"."%1", "o"."open_auction_id" NOT NULL ] +| | | | ) [ ] +| | | ) [ "o"."open_auction_id" NOT NULL, "b3"."id" NOT NULL HASHCOL , "b3"."increase" NOT NULL, "b3"."%TID%" NOT NULL, "%1"."%1", "b3"."increase" NOT NULL as "%2"."%2" ] +| | ) [ "b3"."id" NOT NULL HASHCOL = "%1"."%1" ] +| ) [ "b3"."id" NOT NULL HASHCOL , "b3"."increase" NOT NULL, "b3"."%TID%" NOT NULL, "%1"."%1", "%2"."%2" NOT NULL, "o"."open_auction_id" NOT NULL as "%5"."%5" ] +) [ "o"."open_auction_id" NOT NULL * = "%5"."%5" NOT NULL ] project ( | single select ( | | single join ( | | | & REF 2 , | | | project ( -| | | | join ( -| | | | | table("sys"."bidder") [ "bidder"."id" NOT NULL HASHCOL as "b2"."id", "bidder"."increase" NOT NULL as "b2"."increase" ] COUNT , -| | | | | group by ( -| | | | | | join ( -| | | | | | | single group by ( -| | | | | | | | single project ( -| | | | | | | | | & REF 2 -| | | | | | | | ) [ "o"."open_auction_id" NOT NULL ] -| | | | | | | ) [ "o"."open_auction_id" NOT NULL ] [ "o"."open_auction_id" NOT NULL ], -| | | | | | | table("sys"."bidder") [ "bidder"."id" NOT NULL HASHCOL as "b2a"."id", "bidder"."open_auction_id" NOT NULL as "b2a"."open_auction_id" ] COUNT -| | | | | | ) [ "b2a"."open_auction_id" NOT NULL = "o"."open_auction_id" NOT NULL ] -| | | | | ) [ "o"."open_auction_id" NOT NULL ] [ "sys"."max" no nil ("b2a"."id" NOT NULL HASHCOL ) as "%3"."%3", "o"."open_auction_id" NOT NULL ] +| | | | select ( +| | | | | project ( +| | | | | | crossproduct ( +| | | | | | | table("sys"."bidder") [ "bidder"."id" NOT NULL HASHCOL as "b2"."id", "bidder"."increase" NOT NULL as "b2"."increase" ] COUNT , +| | | | | | | group by ( +| | | | | | | | join ( +| | | | | | | | | single group by ( +| | | | | | | | | | single project ( +| | | | | | | | | | | & REF 2 +| | | | | | | | | | ) [ "o"."open_auction_id" NOT NULL ] +| | | | | | | | | ) [ "o"."open_auction_id" NOT NULL ] [ "o"."open_auction_id" NOT NULL ], +| | | | | | | | | table("sys"."bidder") [ "bidder"."id" NOT NULL HASHCOL as "b2a"."id", "bidder"."open_auction_id" NOT NULL as "b2a"."open_auction_id" ] COUNT +| | | | | | | | ) [ "b2a"."open_auction_id" NOT NULL = "o"."open_auction_id" NOT NULL ] +| | | | | | | ) [ "o"."open_auction_id" NOT NULL ] [ "sys"."max" no nil ("b2a"."id" NOT NULL HASHCOL ) as "%3"."%3", "o"."open_auction_id" NOT NULL ] +| | | | | | ) [ ] +| | | | | ) [ "o"."open_auction_id" NOT NULL, "b2"."id" NOT NULL HASHCOL , "%3"."%3", "b2"."increase" NOT NULL as "%4"."%4" ] | | | | ) [ "b2"."id" NOT NULL HASHCOL = "%3"."%3" ] -| | | ) [ "b2"."increase" NOT NULL, "o"."open_auction_id" NOT NULL as "%6"."%6" ] +| | | ) [ "%4"."%4" NOT NULL, "o"."open_auction_id" NOT NULL as "%6"."%6" ] | | ) [ "o"."open_auction_id" NOT NULL * = "%6"."%6" NOT NULL ] -| ) [ "sys"."sql_mul"("%2"."%2" NOT NULL, double "2") NOT NULL <= "b2"."increase" NOT NULL ] +| ) [ "sys"."<="("sys"."sql_mul"("%2"."%2", double "2"), "%4"."%4") = boolean "true" ] ) [ "b"."id" NOT NULL HASHCOL , "b"."open_auction_id" NOT NULL, "b"."date" NOT NULL, "b"."time" NOT NULL, "b"."personref" NOT NULL, "b"."increase" NOT NULL ] query ITTTTR rowsort _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list