Changeset: 2f8a0dbdab75 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/2f8a0dbdab75
Modified Files:
        sql/server/rel_optimizer.c
        sql/test/BugTracker-2015/Tests/crash.Bug-3736.test
Branch: Jul2021
Log Message:

Don't pushdown selections on single relations


diffs (110 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
@@ -4634,13 +4634,13 @@ rel_push_select_down(visitor *v, sql_rel
        exps = rel->exps;
 
        /* push select through join */
-       if (is_select(rel->op) && r && is_join(r->op) && !(rel_is_ref(r))) {
+       if (is_select(rel->op) && r && is_join(r->op) && !rel_is_ref(r) && 
!is_single(r)){
                sql_rel *jl = r->l;
                sql_rel *jr = r->r;
                int left = r->op == op_join || r->op == op_left;
                int right = r->op == op_join || r->op == op_right;
 
-               if (r->op == op_full || is_single(r))
+               if (r->op == op_full)
                        return rel;
 
                /* introduce selects under the join (if needed) */
@@ -4668,7 +4668,7 @@ rel_push_select_down(visitor *v, sql_rel
        }
 
        /* merge select and cross product ? */
-       if (is_select(rel->op) && r && r->op == op_join && !(rel_is_ref(r))) {
+       if (is_select(rel->op) && r && r->op == op_join && !rel_is_ref(r) && 
!is_single(r)){
                for (n = exps->h; n;) {
                        node *next = n->next;
                        sql_exp *e = n->data;
@@ -4684,7 +4684,7 @@ rel_push_select_down(visitor *v, sql_rel
                }
        }
 
-       if (is_select(rel->op) && r && r->op == op_project && !(rel_is_ref(r))){
+       if (is_select(rel->op) && r && r->op == op_project && !rel_is_ref(r) && 
!is_single(r)){
                sql_rel *pl = r->l;
                /* we cannot push through rank (row_number etc) functions or 
projects with distinct */
                if (pl && !project_unsafe(r, 1, 1)) {
@@ -4712,12 +4712,12 @@ rel_push_select_down(visitor *v, sql_rel
        }
 
        /* try push select under set relation */
-       if (is_select(rel->op) && r && !(rel_is_ref(r)) && !list_empty(exps)) {
+       if (is_select(rel->op) && r && !rel_is_ref(r) && !is_single(r) && 
!list_empty(exps)) {
                sql_rel *u = r, *ou = u;
                sql_rel *ul = u->l;
                sql_rel *ur = u->r;
 
-               if (!rel_is_ref(u) && u->op == op_project)
+               if (!rel_is_ref(u) && !is_single(u) && u->op == op_project)
                        u = u->l;
 
                if (u && is_set(u->op) && !is_single(u) && !list_empty(u->exps) 
&& !rel_is_ref(u)) {
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
@@ -140,29 +140,31 @@ single left outer join (
 | ) [ "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 (
-| | | | 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" ]
-| | | ) [ "%4"."%4" NOT NULL, "o"."open_auction_id" NOT NULL as "%6"."%6" ]
-| | ) [ "o"."open_auction_id" NOT NULL * = "%6"."%6" NOT NULL ]
+| select (
+| | single project (
+| | | single left outer join (
+| | | | & REF 2 ,
+| | | | project (
+| | | | | 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" ]
+| | | | ) [ "%4"."%4" NOT NULL, "o"."open_auction_id" NOT NULL as "%6"."%6" ]
+| | | ) [ "o"."open_auction_id" NOT NULL * = "%6"."%6" 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, "%2"."%2", "%4"."%4" ]
 | ) [ "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 ]
 
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to