Changeset: af9c26acb56f for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/af9c26acb56f
Modified Files:
        ChangeLog
        sql/backends/monet5/rel_physical.c
        sql/backends/monet5/sql_statement.c
        sql/server/rel_unnest.c
        sql/test/subquery/Tests/subquery3.test
        sql/test/subquery/Tests/subquery6.test
Branch: default
Log Message:

Tuple matching at projections has been implemented in the backend, so also allow
such queries in the plan generator.

approved and extended the tests,
added ChangeLog for this "new" feature


diffs (165 lines):

diff --git a/ChangeLog b/ChangeLog
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,11 @@
 # ChangeLog file for devel
 # This file is updated with Maddlog
 
+* Wed Nov 18 2026 Ying Zhang <[email protected]>
+- Added support for tuple matching at projections, so now one can run
+  queries like 'SELECT (1, 2) IN (SELECT 1, 2)' and 'SELECT (1, 2) NOT IN
+  (SELECT 1, 2)'
+
 * Thu Oct 22 2026 Martin van Dinther <[email protected]>
 - Added support for reading DNA sequence alignment data from *.sam and *.bam 
files.
   Usage examples:
diff --git a/sql/backends/monet5/rel_physical.c 
b/sql/backends/monet5/rel_physical.c
--- a/sql/backends/monet5/rel_physical.c
+++ b/sql/backends/monet5/rel_physical.c
@@ -512,6 +512,8 @@ find_cmp_exps(list **exps_hsh, list **ex
                                        set_any(er);
                                if (semantic)
                                        set_semantics(er);
+                               if (er->nid != er->alias.label)
+                                       er->alias.label = 0;
                                append(*exps_hsh, er);
                                append(*exps_prb, e->l);
                        } else {
@@ -526,6 +528,8 @@ find_cmp_exps(list **exps_hsh, list **ex
                                        set_any(el);
                                if (semantic)
                                        set_semantics(el);
+                               if (el->nid != el->alias.label)
+                                       el->alias.label = 0;
                                append(*exps_hsh, el);
                                append(*exps_prb, e->r);
                        }
diff --git a/sql/backends/monet5/sql_statement.c 
b/sql/backends/monet5/sql_statement.c
--- a/sql/backends/monet5/sql_statement.c
+++ b/sql/backends/monet5/sql_statement.c
@@ -4829,7 +4829,6 @@ stmt_aggr(backend *be, stmt *op1, stmt *
 static stmt *
 stmt_alias_(backend *be, stmt *op1, int label, const char *tname, const char 
*alias)
 {
-       assert(label);
        stmt *s = stmt_create(be->mvc->sa, st_alias);
        if(!s) {
                return NULL;
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
@@ -10,6 +10,7 @@
 
 #include "monetdb_config.h"
 #include "rel_optimizer_private.h"
+#include "rel_rel.h"
 #include "sql_decimal.h"
 #include "rel_unnest.h"
 #include "rel_basetable.h"
@@ -2318,7 +2319,18 @@ rewrite_anyequal(visitor *v, sql_rel *re
                                                        set_any(inexp);
                                                append(join->exps, inexp);
                                        }
-                                       return sql_error(sql, 02, 
SQLSTATE(42000) "Tuple matching at projections not implemented in the backend 
yet");
+                                       if (!join->attr)
+                                               join->attr = 
sa_list(v->sql->sa);
+                                       sql_exp *a = exp_atom_bool(v->sql->sa, 
is_anyequal(sf));
+                                       set_no_nil(a);
+                                       if (!e->alias.label)
+                                               exp_label(v->sql->sa, a, 
++v->sql->label);
+                                       else
+                                               exp_setalias(a, e->alias.label, 
exp_relname(e), exp_name(e));
+                                       le = exp_ref(v->sql, a);
+                                       le->card = CARD_MULTI; /* mark as multi 
value, the real attribute is introduced later */
+                                       append(join->attr, a);
+                                       return le;
                                } else {
                                        use_any = true;
                                        sql_exp *inexp = 
exp_compare(v->sql->sa, le, re, cmp_equal);
diff --git a/sql/test/subquery/Tests/subquery3.test 
b/sql/test/subquery/Tests/subquery3.test
--- a/sql/test/subquery/Tests/subquery3.test
+++ b/sql/test/subquery/Tests/subquery3.test
@@ -588,14 +588,53 @@ SELECT col1 FROM another_T WHERE 1 IN (S
 111
 1111
 
-statement error 42000!Tuple matching at projections not implemented in the 
backend yet
-SELECT (col1, col2) IN (VALUES (1,2)) FROM another_T
+query I nosort
+SELECT (col1, col2) IN (VALUES (1,2)) FROM another_T ORDER BY col1
+----
+1
+0
+0
+0
+
+query I nosort
+SELECT (col1, col2) IN (SELECT 1,2) FROM another_T ORDER BY col1
+----
+1
+0
+0
+0
+
+query I nosort
+SELECT (col1, col2) IN (SELECT 1,3) FROM another_T
+----
+0
+0
+0
+0
 
-statement error 42000!Tuple matching at projections not implemented in the 
backend yet
-SELECT (col1, col2) IN (SELECT 1,2) FROM another_T
+query I nosort
+SELECT (col1, col2) NOT IN (VALUES (1,2)) FROM another_T ORDER BY col1
+----
+0
+1
+1
+1
 
-statement error 42000!Tuple matching at projections not implemented in the 
backend yet
-SELECT (col1, col2) IN (SELECT 1,3) FROM another_T
+query I nosort
+SELECT (col1, col2) NOT IN (SELECT 1,2) FROM another_T ORDER BY col1
+----
+0
+1
+1
+1
+
+query I nosort
+SELECT (col1, col2) NOT IN (SELECT 1,3) FROM another_T
+----
+1
+1
+1
+1
 
 query I rowsort
 SELECT col1 FROM another_T WHERE (col2, col3) IN (SELECT col4, col5)
@@ -613,8 +652,10 @@ query I rowsort
 SELECT col1 FROM another_T WHERE col2 IN (VALUES(1))
 ----
 
-statement error 42000!Tuple matching at projections not implemented in the 
backend yet
+query I nosort
 SELECT (1,2) IN (SELECT 1,2)
+----
+1
 
 query I rowsort
 SELECT col1 FROM another_T WHERE (col2, col3) IN (VALUES(1,2))
diff --git a/sql/test/subquery/Tests/subquery6.test 
b/sql/test/subquery/Tests/subquery6.test
--- a/sql/test/subquery/Tests/subquery6.test
+++ b/sql/test/subquery/Tests/subquery6.test
@@ -416,7 +416,7 @@ select 1 in (ColID), max(totalsales) fro
 statement error 42000!SELECT: cannot use non GROUP BY column 
'tbl_productsales.colid' in query results without an aggregate function
 select 1 in (ColID, (select 1)), max(totalsales) from tbl_ProductSales
 
-statement error 42000!Tuple matching at projections not implemented in the 
backend yet
+statement error /more than one match/
 select (select (i1.i, i2.i) in (select i2.i, i1.i) from integers i2) from 
integers i1
 
 statement error 42000!MIN: aggregate function 'min' not allowed in GROUP BY 
clause
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to