Changeset: d3126c3763ad for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/d3126c3763ad
Modified Files:
        sql/server/rel_optimize_proj.c
        
sql/test/BugTracker-2026/Tests/7967-optimize-in-select-distinct-queries.test
Branch: default
Log Message:

small fix for issue # 7967, ie no need for distinct on righthand of semijoin 
(should be handled with one hash on right)


diffs (35 lines):

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
@@ -3932,6 +3932,13 @@ rel_distinct_project2groupby_(visitor *v
                set_distinct(rel);
                v->changes++;
        }
+       sql_rel *p = v->parent;
+       if (!rel_is_ref(rel) && is_project(rel->op) && p && is_semi(p->op) && 
p->r == rel) { /* drop distinct on right handside of semi */
+               set_nodistinct(rel);
+               v->changes++;
+               return rel;
+       }
+
        /* rewrite distinct project (table) [ constant ] -> project [ constant 
] */
        if (rel->op == op_project && rel->l && !rel->r /* no order by */ && 
need_distinct(rel) &&
            exps_card(rel->exps) <= CARD_ATOM) {
diff --git 
a/sql/test/BugTracker-2026/Tests/7967-optimize-in-select-distinct-queries.test 
b/sql/test/BugTracker-2026/Tests/7967-optimize-in-select-distinct-queries.test
--- 
a/sql/test/BugTracker-2026/Tests/7967-optimize-in-select-distinct-queries.test
+++ 
b/sql/test/BugTracker-2026/Tests/7967-optimize-in-select-distinct-queries.test
@@ -34,11 +34,9 @@ project (
 | group by (
 | | semijoin (
 | | | table("sys"."probe") [ "probe"."v" as "p"."v" ],
-| | | group by (
-| | | | project (
-| | | | | table("sys"."rhs") [ "rhs"."v" as "r"."v" ]
-| | | | ) [ "r"."v" as "%1"."%1" ]
-| | | ) [ "%1"."%1" ] [ "%1"."%1" ]
+| | | project (
+| | | | table("sys"."rhs") [ "rhs"."v" as "r"."v" ]
+| | | ) [ "r"."v" as "%1"."%1" ]
 | | ) [ ("p"."v") + = ("%1"."%1") ]
 | ) [  ] [ "sys"."count"() as "%3"."%3" ]
 ) [ "%3"."%3" ]
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to