Changeset: 92d0ffca2da1 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/92d0ffca2da1
Added Files:
        sql/test/BugTracker-2026/Tests/7813_push_down_topn.test
Modified Files:
        sql/server/rel_optimize_others.c
        sql/test/BugTracker-2026/Tests/All
Branch: Dec2025
Log Message:

fixed issue #7813, push topn down optimizer for munion wasn't run


diffs (61 lines):

diff --git a/sql/server/rel_optimize_others.c b/sql/server/rel_optimize_others.c
--- a/sql/server/rel_optimize_others.c
+++ b/sql/server/rel_optimize_others.c
@@ -1350,7 +1350,7 @@ rel_push_topn_and_sample_down_(visitor *
                }
 
                /* duplicate topn/sample direct under union */
-               if (r && !rel_is_ref(r) && r->l && r->r && is_munion(r->op) && 
r->exps) {
+               if (r && !rel_is_ref(r) && r->l && is_munion(r->op) && r->exps) 
{
                        list *rels = r->l;
                        bool changed = false;
                        for(node *n = rels->h; n; n = n->next) {
diff --git a/sql/test/BugTracker-2026/Tests/7813_push_down_topn.test 
b/sql/test/BugTracker-2026/Tests/7813_push_down_topn.test
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2026/Tests/7813_push_down_topn.test
@@ -0,0 +1,36 @@
+statement ok
+create table x1 (i int)
+
+statement ok
+create table x2 (i int)
+
+statement ok rowcount 3
+insert into x1 values(1),(2),(5)
+
+statement ok rowcount 3
+insert into x2 values(11),(12),(15)
+
+statement ok
+create merge table x (i int)
+
+statement ok
+alter table x add table x1
+
+statement ok
+alter table x add table x2
+
+query T
+explain after logical rewrite select * from x limit 2
+----
+project (
+| top N (
+| | munion (
+| | | top N (
+| | | | table("sys"."x1") [ "x1"."i" as "x"."i" ]
+| | | ) [ bigint(63) "2" ],
+| | | top N (
+| | | | table("sys"."x2") [ "x2"."i" as "x"."i" ]
+| | | ) [ bigint(63) "2" ]
+| | ) [ "x"."i" ]
+| ) [ bigint(63) "2" ]
+) [ "x"."i" ]
diff --git a/sql/test/BugTracker-2026/Tests/All 
b/sql/test/BugTracker-2026/Tests/All
--- a/sql/test/BugTracker-2026/Tests/All
+++ b/sql/test/BugTracker-2026/Tests/All
@@ -30,3 +30,4 @@ KNOWNFAIL?7801-assertion-failure
 7804-querylog-catalog-orderby-bug
 7805-orderby-all-bug
 7806-numeric-no-prec-no-scale
+7813_push_down_topn
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to