Changeset: eee1e6384827 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/eee1e6384827
Modified Files:
        sql/test/BugTracker-2026/Tests/All
Branch: default
Log Message:

Merge branch unnest2 into default.


diffs (truncated from 6844 to 300 lines):

diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml
--- a/.github/workflows/linux.yml
+++ b/.github/workflows/linux.yml
@@ -46,7 +46,7 @@ jobs:
     runs-on: ${{ matrix.os }}
     steps:
       - name: Checkout
-        uses: actions/checkout@v4
+        uses: actions/checkout@v6
         with:
           ref: ${{ github.ref }}
 
@@ -163,7 +163,7 @@ jobs:
       - name: Tar files
         run: tar -cvf mtests.tar mTests
       - name: Publish mtest results
-        uses: actions/upload-artifact@v4
+        uses: actions/upload-artifact@v7
         with:
           name: mtest-${{ github.sha }}-${{ matrix.os }}-${{ matrix.c_compiler 
}}
           path: mtests.tar
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -1607,6 +1607,7 @@ cq *qc_find(qc *cache, int id);
 cq *qc_insert(qc *cache, allocator *sa, sql_rel *r, symbol *s, list *params, 
mapi_query_t type, char *codedstr, int no_mitosis);
 void rel_base_use_all(mvc *sql, sql_rel *rel);
 sql_rel *rel_basetable(mvc *sql, sql_table *t, const char *tname);
+list *rel_boundvar(mvc *sql, sql_rel *rel);
 sql_rel *rel_project(allocator *sa, sql_rel *l, list *e);
 list *rel_projections(mvc *sql, sql_rel *rel, const char *tname, int settname, 
int intern);
 void res_tables_destroy(res_table *results);
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
@@ -2606,7 +2606,6 @@ rel2bin_table(backend *be, sql_rel *rel,
                sql_subfunc *f = op->f;
                stmt *psub = NULL;
                list *ops = NULL;
-               stmt *ids = NULL;
 
                if (rel->l) { /* first construct the sub relation */
                        sql_rel *l = rel->l;
@@ -2624,22 +2623,31 @@ rel2bin_table(backend *be, sql_rel *rel,
                }
 
                assert(f);
-               if (f->func->res && list_length(f->func->res) + 1 == 
list_length(rel->exps) && !f->func->varres) {
+               list *outers = NULL;
+               if (f->func->res && rel->nr_outers && list_length(f->func->res) 
+ rel->nr_outers == list_length(rel->exps) && !f->func->varres) {
                        /* add inputs in correct order ie loop through args of 
f and pass column */
                        list *exps = op->l;
+                       outers = sa_list(be->mvc->sa);
                        ops = sa_list(be->mvc->sa);
                        if (exps) {
-                               for (node *en = exps->h; en; en = en->next) {
+                               node *en = exps->h;
+                               for (int c = 0; en && c < rel->nr_outers; en = 
en->next, c++) {
                                        sql_exp *e = en->data;
 
                                        /* find column */
                                        stmt *s = exp_bin(be, e, sub, NULL, 
NULL, NULL, NULL, NULL, 0, 0, 0);
                                        if (!s)
                                                return NULL;
-                                       if (en->next)
-                                               append(ops, s);
-                                       else /* last added exp is the ids (todo 
use name base lookup !!) */
-                                               ids = s;
+                                       append(outers, s);
+                               }
+                               for (; en; en = en->next) {
+                                       sql_exp *e = en->data;
+
+                                       /* find column */
+                                       stmt *s = exp_bin(be, e, sub, NULL, 
NULL, NULL, NULL, NULL, 0, 0, 0);
+                                       if (!s)
+                                               return NULL;
+                                       append(ops, s);
                                }
                        }
                } else {
@@ -2666,18 +2674,21 @@ rel2bin_table(backend *be, sql_rel *rel,
                                int i = 0;
 
                                /* correlated table returning function */
-                               if (list_length(f->func->res) + 1 == 
list_length(rel->exps)) {
+                               if (rel->nr_outers && 
(list_length(f->func->res) + rel->nr_outers) == list_length(rel->exps)) {
                                        /* use a simple nested loop solution 
for this case, ie
-                                        * output a table of (input) row-ids, 
the output of the table producing function
+                                        * output a table of (input) row, the 
output of the table producing function
                                         */
                                        /* make sure the input for 
sql.unionfunc are bats */
-                                       if (ids)
-                                               ids = column(be, ids);
+                                       if (outers)
+                                               for(node *n = outers->h; n; n = 
n->next)
+                                                       n->data = column(be, 
n->data);
                                        if (ops)
                                                for (node *en = ops->h; en; en 
= en->next)
                                                        en->data = column(be, 
(stmt *) en->data);
 
-                                       int narg = 3 + list_length(rel->exps);
+                                       int narg = 2 + list_length(rel->exps);
+                                       if (outers)
+                                               narg += list_length(outers);
                                        if (ops)
                                                narg += list_length(ops);
                                        InstrPtr q = newStmtArgs(be->mb, 
sqlRef, "unionfunc", narg);
@@ -2705,14 +2716,18 @@ rel2bin_table(backend *be, sql_rel *rel,
                                        str fcn = backend_function_imp(be, 
f->func);
                                        q = pushStr(be->mb, q, mod);
                                        q = pushStr(be->mb, q, fcn);
+                                       q = pushInt(be->mb, q, rel->nr_outers);
                                        psub = stmt_direct_func(be, q);
                                        if (psub == NULL) {
                                                freeInstruction(be->mb, q);
                                                return NULL;
                                        }
 
-                                       if (ids) /* push input rowids column */
-                                               q = pushArgument(be->mb, q, 
ids->nr);
+                                       if (outers) /* push input row column */
+                                               for (node *n = outers->h; n; n 
= n->next) {
+                                                       stmt *outer = n->data;
+                                                       q = 
pushArgument(be->mb, q, outer->nr);
+                                               }
 
                                        /* add inputs in correct order ie loop 
through args of f and pass column */
                                        if (ops) {
@@ -2725,9 +2740,8 @@ rel2bin_table(backend *be, sql_rel *rel,
                                        pushInstruction(be->mb, q);
 
                                        /* name output of dependent columns, 
output of function is handled the same as without correlation */
-                                       int len = 
list_length(rel->exps)-list_length(f->func->res);
-                                       assert(len== 1);
-                                       for (i=0, m=rel->exps->h; m && i<len; m 
= m->next, i++) {
+                                       //int len = 
list_length(rel->exps)-list_length(f->func->res);
+                                       for (i=0, m=rel->exps->h; m; m = 
m->next, i++) {
                                                sql_exp *exp = m->data;
                                                stmt *s = stmt_rs_column(be, 
psub, i, exp_subtype(exp));
 
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
@@ -183,7 +183,9 @@ has_groupby(sql_rel *rel)
                case op_select:
                case op_topn:
                case op_sample:
-                       return has_groupby(rel->l);
+                       if (rel->l)
+                               return has_groupby(rel->l);
+                       return 0;
                case op_insert:
                case op_update:
                case op_delete:
@@ -206,11 +208,14 @@ has_groupby(sql_rel *rel)
 }
 
 static sql_rel *
-rel_partition(mvc *sql, sql_rel *rel)
+rel_partition(visitor *v, mvc *sql, sql_rel *rel)
 {
        if (mvc_highwater(sql))
                return sql_error(sql, 10, SQLSTATE(42000) "Query too complex: 
running out of stack space");
 
+       if (v->opt >= 0 && rel->opt >= v->opt) /* only once */
+        return 0;
+
        switch (rel->op) {
        case op_basetable:
        case op_sample:
@@ -221,7 +226,7 @@ rel_partition(mvc *sql, sql_rel *rel)
        case op_groupby:
        case op_topn:
                if (rel->l)
-                       rel_partition(sql, rel->l);
+                       rel_partition(v, sql, rel->l);
                break;
        case op_semi:
        case op_anti:
@@ -229,20 +234,20 @@ rel_partition(mvc *sql, sql_rel *rel)
        case op_inter:
        case op_except:
                if (rel->l)
-                       rel_partition(sql, rel->l);
+                       rel_partition(v, sql, rel->l);
                if (rel->r)
-                       rel_partition(sql, rel->r);
+                       rel_partition(v, sql, rel->r);
                break;
        case op_munion:
                for (node *n = ((list*)rel->l)->h; n; n = n->next)
-                       rel_partition(sql, n->data);
+                       rel_partition(v, sql, n->data);
                break;
        case op_insert:
        case op_update:
        case op_delete:
        case op_truncate:
                if (rel->r && rel->card <= CARD_AGGR)
-                       rel_partition(sql, rel->r);
+                       rel_partition(v, sql, rel->r);
                break;
        case op_join:
        case op_left:
@@ -250,9 +255,9 @@ rel_partition(mvc *sql, sql_rel *rel)
        case op_full:
                if (has_groupby(rel->l) || has_groupby(rel->r)) {
                        if (rel->l)
-                               rel_partition(sql, rel->l);
+                               rel_partition(v, sql, rel->l);
                        if (rel->r)
-                               rel_partition(sql, rel->r);
+                               rel_partition(v, sql, rel->r);
                } else {
                        _rel_partition(sql, rel);
                }
@@ -260,22 +265,24 @@ rel_partition(mvc *sql, sql_rel *rel)
        case op_ddl:
                if (rel->flag == ddl_output || rel->flag == ddl_create_seq || 
rel->flag == ddl_alter_seq || rel->flag == ddl_alter_table || rel->flag == 
ddl_create_table || rel->flag == ddl_create_view) {
                        if (rel->l)
-                               rel_partition(sql, rel->l);
+                               rel_partition(v, sql, rel->l);
                } else if (rel->flag == ddl_list || rel->flag == ddl_exception) 
{
                        if (rel->l)
-                               rel_partition(sql, rel->l);
+                               rel_partition(v, sql, rel->l);
                        if (rel->r)
-                               rel_partition(sql, rel->r);
+                               rel_partition(v, sql, rel->r);
                }
                break;
        case op_table:
                if ((IS_TABLE_PROD_FUNC(rel->flag) || rel->flag == 
TABLE_FROM_RELATION) && rel->l)
-                       rel_partition(sql, rel->l);
+                       rel_partition(v, sql, rel->l);
                break;
        default:
                assert(0);
                break;
        }
+       if (rel && v->opt >= 0)
+        rel->opt = v->opt;
        return rel;
 }
 
@@ -378,7 +385,9 @@ rel_physical(mvc *sql, sql_rel *rel)
 
        v.changes = 0;
        if (!sql->recursive) {
-                       (void)rel_partition(sql, rel);
+                       if (v.opt >= 0)
+                               v.opt = rel->opt+1;
+                       (void)rel_partition(&v, sql, rel);
        }
 
        rel = rel_exp_visitor_topdown(&v, rel, &exp_timezone, true);
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -4981,9 +4981,9 @@ bailout:
        return msg;
 }
 
-/* input id, row-input-values
- * for each id call function(with row-input-values) return table
- * return for each id the table, ie id (*length of table) and table results
+/*
+ * for each input row call function(with row-input-values) return table
+ * return for each input row the table, ie input-row (*length of table) and 
table results
  */
 str
 SQLunionfunc(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
@@ -4997,21 +4997,22 @@ SQLunionfunc(Client cntxt, MalBlkPtr mb,
                return createException(MAL, "sql.unionfunc", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
        mod = *getArgReference_str(stk, pci, arg++);
        fcn = *getArgReference_str(stk, pci, arg++);
+       int nr_outers = *getArgReference_int(stk, pci, arg++);
        npci = newStmtArgs(nmb, mod, fcn, pci->argc);
        if (npci == NULL) {
                freeMalBlk(nmb);
                return createException(MAL, "sql.unionfunc", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
        }
 
-       for (int i = 1; i < pci->retc; i++) {
+       for (int i = nr_outers; i < pci->retc; i++) {
                int type = getArgType(mb, pci, i);
 
-               if (i==1)
+               if (i==nr_outers)
                        getArg(npci, 0) = newTmpVariable(nmb, type);
                else
                        npci = pushReturn(nmb, npci, newTmpVariable(nmb, type));
        }
-       for (int i = pci->retc+2+1; i < pci->argc; i++) {
+       for (int i = pci->retc+3+nr_outers; i < pci->argc; i++) {
                int type = getBatType(getArgType(mb, pci, i));
 
                npci = pushNil(nmb, npci, type);
@@ -5027,7 +5028,7 @@ SQLunionfunc(Client cntxt, MalBlkPtr mb,
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to