Changeset: bfa00796e8a8 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/bfa00796e8a8
Modified Files:
        sql/server/rel_unnest.c
Branch: resource_management
Log Message:

merge upstream


diffs (298 lines):

diff --git a/monetdb5/modules/atoms/str.c b/monetdb5/modules/atoms/str.c
--- a/monetdb5/modules/atoms/str.c
+++ b/monetdb5/modules/atoms/str.c
@@ -2192,7 +2192,7 @@ ng_create(size_t cnt, size_t ng_sz)
                ng->idx  = GDKmalloc(ng_sz * sizeof(NG_TYPE));
                ng->sigs = GDKmalloc(cnt * sizeof(NG_TYPE));
                ng->histogram = GDKmalloc(ng_sz * sizeof(unsigned));
-               ng->lists = GDKmalloc(ng_sz * sizeof(oid));
+               ng->lists = GDKmalloc(ng_sz * sizeof(unsigned));
                ng->rids = GDKmalloc(NG_MULTIPLE * cnt * sizeof(oid));
        }
        if (!ng || !ng->idx || !ng->sigs || !ng->histogram || !ng->lists || 
!ng->rids) {
@@ -2208,19 +2208,13 @@ init_bigram_idx(NGrams *ng, BATiter *bi,
        NG_TYPE *idx = ng->idx;
        NG_TYPE *sigs = ng->sigs;
        unsigned *h = ng->histogram;
-       unsigned (*h_tmp)[NG_BITS] = GDKzalloc(BIGRAM_SZ * sizeof(unsigned));
+       unsigned h_tmp[NG_BITS][NG_BITS] = { 0 };
        unsigned *h_tmp_ptr = (unsigned *) h_tmp;
-       unsigned *map = GDKmalloc(BIGRAM_SZ * sizeof(unsigned));
+       unsigned map[BIGRAM_SZ];
        unsigned *lists = ng->lists;
        oid *rids = ng->rids;
        unsigned k = 1;
 
-       if (!h_tmp || !map) {
-               GDKfree(h_tmp);
-               GDKfree(map);
-               throw(MAL, "init_bigram_idx", SQLSTATE(HY013) MAL_MALLOC_FAIL);
-       }
-
        oid b_base = bi->b->hseqbase;
        const char *b_vars = bi->vh->base, *b_vals = bi->base;
 
@@ -2239,7 +2233,7 @@ init_bigram_idx(NGrams *ng, BATiter *bi,
                h[i] = h_tmp_ptr[i];
        }
 
-       GDKqsort(h_tmp, map, NULL, BIGRAM_SZ,
+       GDKqsort(h_tmp_ptr, map, NULL, BIGRAM_SZ,
                         sizeof(unsigned), sizeof(unsigned), TYPE_int, true, 
false);
 
        unsigned j = BIGRAM_SZ - 1, sum = 0;
@@ -2248,8 +2242,11 @@ init_bigram_idx(NGrams *ng, BATiter *bi,
                        break;
                sum += h_tmp_ptr[j];
        }
+       unsigned larger_cnt = h_tmp_ptr[j];
+       for(; h_tmp_ptr[j] == larger_cnt; j++)
+               ;
        ng->max = h_tmp_ptr[0];
-       ng->min = h_tmp_ptr[j + 1];
+       ng->min = h_tmp_ptr[j];
 
        for (NG_TYPE i = 0, n = 0; i < BIGRAM_SZ && h_tmp_ptr[i] > 0; i++) {
                idx[map[i]] = (NG_TYPE)1 << n;
@@ -2288,8 +2285,6 @@ init_bigram_idx(NGrams *ng, BATiter *bi,
                sigs++;
        }
 
-       GDKfree(h_tmp);
-       GDKfree(map);
        return MAL_SUCCEED;
 }
 
diff --git a/sql/backends/monet5/sql_gencode.c 
b/sql/backends/monet5/sql_gencode.c
--- a/sql/backends/monet5/sql_gencode.c
+++ b/sql/backends/monet5/sql_gencode.c
@@ -1021,6 +1021,7 @@ backend_dumpstmt_body(backend *be, MalBl
        InstrPtr q, querylog = NULL;
        int old_mv = be->mvc_var;
        MalBlkPtr old_mb = be->mb;
+       char *cq_query = NULL, *buf = NULL;
 
        assert(mb->ma);
        /* Always keep the SQL query around for monitoring */
@@ -1034,9 +1035,23 @@ backend_dumpstmt_body(backend *be, MalBl
                        return -1;
                }
                setVarType(mb, getArg(q, 0), TYPE_void);
+               if (r->flag == ddl_psm && r->exps
+                       && exps_have_func(r->exps) && r->exps->cnt == 1) {
+                       sql_func *f = r->exps->h->data;
+                       cq *cq = qc_find(m->qc, f->base.id);
+                       cq_query = cq ? cq->f->query : NULL;
+                       if (cq_query) {
+                               size_t buf_sz = strlen(query) + 
strlen(cq_query);
+                               buf = GDKmalloc(buf_sz);
+                               snprintf(buf, buf_sz, "%.*s %s", 
(int)strlen(query) - 1, query, cq_query);
+                               query = buf;
+                       }
+               }
                q = pushStr(mb, q, query);
                q = pushStr(mb, q, getSQLoptimizer(be->mvc));
                pushInstruction(mb, q);
+               if (cq_query)
+                       GDKfree(buf);
        }
 
        /* announce the transaction mode */
diff --git a/sql/server/rel_distribute.c b/sql/server/rel_distribute.c
--- a/sql/server/rel_distribute.c
+++ b/sql/server/rel_distribute.c
@@ -128,6 +128,7 @@ do_replica_rewrite(mvc *sql, list *exps,
                sql_exp *ne = m->data;
 
                exp_prop_alias(sql->sa, ne, e);
+               ne->nid = e->nid;
        }
        list_hash_clear(r->exps); /* the child table may have different column 
names, so clear the hash */
 
diff --git a/sql/server/rel_exp.c b/sql/server/rel_exp.c
--- a/sql/server/rel_exp.c
+++ b/sql/server/rel_exp.c
@@ -824,8 +824,6 @@ exp_ref(mvc *sql, sql_exp *e)
        sql_exp *ne = exp_propagate(sql->sa, exp_column(sql->sa, 
exp_relname(e), exp_name(e), exp_subtype(e), exp_card(e), has_nil(e), 
is_unique(e), is_intern(e)), e);
        if (ne) {
                ne->nid = e->alias.label;
-               assert(ne->nid);
-               assert(!ne->nid || ne->alias.name);
                ne->alias.label = ne->nid;
        }
        return ne;
diff --git a/sql/server/rel_rewriter.c b/sql/server/rel_rewriter.c
--- a/sql/server/rel_rewriter.c
+++ b/sql/server/rel_rewriter.c
@@ -217,14 +217,19 @@ rewrite_simplify_exp(visitor *v, sql_rel
        }
        if (is_compare(e->type) && e->flag == cmp_equal && !is_semantics(e)) { 
/* predicate_func = TRUE */
                sql_exp *l = e->l, *r = e->r;
-               if (is_func(l->type) && exp_is_true(r) && 
(is_anyequal_func(((sql_subfunc*)l->f)) || 
is_exists_func(((sql_subfunc*)l->f))))
+               if (is_func(l->type) && exp_is_true(r) && 
(is_anyequal_func(((sql_subfunc*)l->f)) || 
is_exists_func(((sql_subfunc*)l->f)))) {
+                       if (exp_name(e))
+                               exp_prop_alias(v->sql->sa, l, e);
                        return l;
+               }
                if (is_func(l->type) && exp_is_false(r) && exp_is_not_null(r) 
&& (is_anyequal_func(((sql_subfunc*)l->f)) || 
is_exists_func(((sql_subfunc*)l->f)))) {
                        sql_subfunc *sf = l->f;
                        if (is_anyequal_func(sf))
-                               return exp_in_func(v->sql, 
((list*)l->l)->h->data, ((list*)l->l)->h->next->data, !is_anyequal(sf), 0);
-                       if (is_exists_func(sf))
-                               return exp_exists(v->sql, 
((list*)l->l)->h->data, !is_exists(sf));
+                               l = exp_in_func(v->sql, ((list*)l->l)->h->data, 
((list*)l->l)->h->next->data, !is_anyequal(sf), 0);
+                       else if (is_exists_func(sf))
+                               l = exp_exists(v->sql, ((list*)l->l)->h->data, 
!is_exists(sf));
+                       if (exp_name(e))
+                               exp_prop_alias(v->sql->sa, l, e);
                        return l;
                }
        }
diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c
--- a/sql/server/rel_select.c
+++ b/sql/server/rel_select.c
@@ -1451,7 +1451,8 @@ set_dependent_( sql_rel *r)
 }
 
 static sql_rel*
-find_union(visitor *v, sql_rel *rel) {
+find_union(visitor *v, sql_rel *rel)
+{
        if (rel->op == op_munion)
                v->data = rel;
        return rel;
@@ -2410,7 +2411,7 @@ rel_in_exp(sql_query *query, sql_rel *re
                int r_is_atoms = rlist ? exps_are_atoms(e->r) : 
exp_is_atom(e->r);
                int r_has_freevar = rlist ? exps_have_freevar(sql, e->r) : 
exp_has_freevar(sql, e->r);
 
-               if (rcard <= CARD_ATOM && (r_is_atoms || r_has_freevar || 
exp_has_freevar(sql, ls))) {
+               if ((rcard <= CARD_ATOM && r_is_atoms) || r_has_freevar || 
exp_has_freevar(sql, ls)) {
                        if ((exp_card(ls) == rcard) || rel->processed) /* bin 
compare op */
                                return rel_select(sql->sa, rel, e);
 
@@ -2717,17 +2718,6 @@ rel_logical_value_exp(sql_query *query, 
        case SQL_IS_NOT_NULL:
        /* is (NOT) NULL */
        {
-               /*
-               sql_exp *le = rel_value_exp(query, rel, sc->data.sym, 
f|sql_farg, ek);
-
-               if (!le)
-                       return NULL;
-               le = rel_unop_(sql, rel ? *rel : NULL, le, "sys", sc->token == 
SQL_IS_NULL ? "isnull" : "isnotnull", card_value);
-               if (!le)
-                       return NULL;
-               set_has_no_nil(le);
-               return le;
-               */
                sql_exp *le = rel_value_exp(query, rel, sc->data.sym, 
f|sql_farg, ek);
                sql_subtype *t;
 
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
@@ -4014,7 +4014,8 @@ rewrite_fix_count(visitor *v, sql_rel *r
                                        list *args, *targs;
                                        sql_subfunc *isnil = 
sql_bind_func(v->sql, "sys", "isnull", exp_subtype(e), NULL, F_FUNC, true, 
true), *ifthen;
 
-                                       ne = exp_unop(v->sql->sa, 
exp_copy(v->sql, e), isnil);
+                                       ne = exp_unop(v->sql->sa, e, isnil);
+                                       e = exp_ref(v->sql, e);
                                        set_has_no_nil(ne);
                                        targs = sa_list(v->sql->sa);
                                        append(targs, 
sql_bind_localtype("bit"));
diff --git a/sql/test/BugTracker-2025/Tests/7635_name_propagation_missing.test 
b/sql/test/BugTracker-2025/Tests/7635_name_propagation_missing.test
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2025/Tests/7635_name_propagation_missing.test
@@ -0,0 +1,17 @@
+statement ok
+CREATE TABLE t0(c0 INT)
+
+statement ok
+INSERT INTO t0 VALUES (1)
+
+query II
+SELECT * FROM t0 INNER JOIN (SELECT (1 = ANY(VALUES (1)))) AS sub ON TRUE
+----
+1
+1
+
+query II
+SELECT * FROM t0 INNER JOIN (SELECT (1 = ANY(VALUES (1)) = TRUE)) AS sub ON 
TRUE
+----
+1
+1
diff --git a/sql/test/BugTracker-2025/Tests/7644_antijoin_crash.test 
b/sql/test/BugTracker-2025/Tests/7644_antijoin_crash.test
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2025/Tests/7644_antijoin_crash.test
@@ -0,0 +1,15 @@
+statement ok
+CREATE TABLE database0_t2(c0 DOUBLE)
+
+statement ok
+CREATE TABLE database0_t4(c0 DOUBLE)
+
+statement ok
+INSERT INTO database0_t2 VALUES(1.0)
+
+statement ok
+INSERT INTO database0_t4 VALUES(1.0)
+
+query I
+SELECT * FROM database0_t2 WHERE NOT EXISTS(SELECT 1 FROM database0_t4 WHERE 
(database0_t2.c0) IN (database0_t4.c0, database0_t2.c0))
+----
diff --git a/sql/test/BugTracker-2025/Tests/7646_leftjoin_crash.test 
b/sql/test/BugTracker-2025/Tests/7646_leftjoin_crash.test
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2025/Tests/7646_leftjoin_crash.test
@@ -0,0 +1,7 @@
+statement ok
+CREATE TABLE t1(c0 INT)
+
+query II
+SELECT * FROM t1 LEFT JOIN (SELECT 1) ON EXISTS (SELECT (VALUES (1)));
+----
+
diff --git a/sql/test/BugTracker-2025/Tests/All 
b/sql/test/BugTracker-2025/Tests/All
--- a/sql/test/BugTracker-2025/Tests/All
+++ b/sql/test/BugTracker-2025/Tests/All
@@ -10,4 +10,7 @@ HAVE_HGE?7637_str_to_decimal
 7632-crash-leftjoin-exists
 7633-crash-leftjoin-any
 7634_join_with_subquery_crash
+7635_name_propagation_missing
 7636_antijoin_crash
+7644_antijoin_crash
+7646_leftjoin_crash
diff --git a/sql/test/analytics/Tests/analytics13.test 
b/sql/test/analytics/Tests/analytics13.test
--- a/sql/test/analytics/Tests/analytics13.test
+++ b/sql/test/analytics/Tests/analytics13.test
@@ -679,7 +679,7 @@ 0
 0
 0
 
-query III nosort
+query III rowsort
 SELECT
     CASE WHEN t1.col1 IN (SELECT 1 FROM tbl_ProductSales tp LEFT JOIN 
another_T t2 ON tp.ColID = t1.col1) THEN 1 ELSE 2 END,
     CASE WHEN SUM(t1.col3) IN (SELECT MAX(t1.col3) FROM tbl_ProductSales tp 
LEFT JOIN another_T t2 ON tp.ColID = t1.col1) THEN 1 ELSE 2 END,
@@ -690,7 +690,7 @@ GROUP BY ROLLUP(t1.col1, t1.col2)
 1
 1
 2
-2
+1
 1
 2
 2
@@ -699,7 +699,7 @@ 2
 2
 1
 2
-1
+2
 1
 2
 2
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to