Changeset: ff622de38d8d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/ff622de38d8d
Branch: dict
Log Message:

merged with default


diffs (truncated from 379 to 300 lines):

diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -2350,7 +2350,7 @@ gdk_export BAT *BATsample_with_seed(BAT 
  * on each iteration */
 #define TIMEOUT_LOOP_IDX(IDX, REPEATS, TIMEOFFSET)                     \
        for (BUN REPS = (IDX = 0, (REPEATS)); REPS > 0; REPS = 0) /* "loops" at 
most once */ \
-               for (BUN CTR1 = 0, END1 = (REPS + CHECK_QRY_TIMEOUT_MASK) >> 
CHECK_QRY_TIMEOUT_SHIFT; CTR1 < END1 && TIMEOFFSET >= 0; CTR1++, TIMEOFFSET = 
TIMEOFFSET > 0 && GDKusec() > TIMEOFFSET ? -1 : TIMEOFFSET) \
+               for (BUN CTR1 = 0, END1 = (REPS + 1 + CHECK_QRY_TIMEOUT_MASK) 
>> CHECK_QRY_TIMEOUT_SHIFT; CTR1 < END1 && TIMEOFFSET >= 0; CTR1++, TIMEOFFSET 
= TIMEOFFSET > 0 && GDKusec() > TIMEOFFSET ? -1 : TIMEOFFSET) \
                        for (BUN CTR2 = 0, END2 = CTR1 == END1 - 1 ? REPS & 
CHECK_QRY_TIMEOUT_MASK : CHECK_QRY_TIMEOUT_STEP; CTR2 < END2; CTR2++, IDX++)
 
 /* declare and use IDX as a loop variable, initializing it to 0 and
diff --git a/monetdb5/modules/mal/remote.c b/monetdb5/modules/mal/remote.c
--- a/monetdb5/modules/mal/remote.c
+++ b/monetdb5/modules/mal/remote.c
@@ -321,9 +321,9 @@ static str
 RMTconnectTable(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
        char *local_table;
-       char *remoteuser;
-       char *passwd;
-       char *uri;
+       char *remoteuser = NULL;
+       char *passwd = NULL;
+       char *uri = NULL;
        char *tmp;
        char *ret;
        str scen;
@@ -340,7 +340,10 @@ RMTconnectTable(Client cntxt, MalBlkPtr 
        }
 
        rethrow("remote.connect", tmp, 
AUTHgetRemoteTableCredentials(local_table, &uri, &remoteuser, &passwd));
-
+       if (!remoteuser)
+               remoteuser = GDKstrdup("");
+       if (!passwd)
+               passwd = GDKstrdup("");
        /* The password we just got is hashed. Add the byte \1 in front to
         * signal this fact to the mapi. */
        size_t pwlen = strlen(passwd);
diff --git a/monetdb5/optimizer/opt_mitosis.c b/monetdb5/optimizer/opt_mitosis.c
--- a/monetdb5/optimizer/opt_mitosis.c
+++ b/monetdb5/optimizer/opt_mitosis.c
@@ -21,7 +21,7 @@ OPTmitosisImplementation(Client cntxt, M
        InstrPtr p, q, *old, target = 0;
        size_t argsize = 6 * sizeof(lng), m = 0, memclaim;
        /*       estimate size per operator estimate:   4 args + 2 res*/
-       int threads = GDKnr_threads ? GDKnr_threads : 1;
+       int threads = GDKnr_threads ? GDKnr_threads : 1, maxslices = MAXSLICES;
        str msg = MAL_SUCCEED;
 
        /* if the user has associated limitation on the number of threads, 
respect it in the
@@ -47,6 +47,9 @@ OPTmitosisImplementation(Client cntxt, M
                }
 
                /* mitosis/mergetable bailout conditions */
+               /* Crude protection against self join explosion */
+               if (p->retc == 2 && isMatJoinOp(p))
+                       maxslices = threads;
 
                if (p->argc > 2 && getModuleId(p) == aggrRef &&
                                getFunctionId(p) != subcountRef &&
@@ -152,8 +155,8 @@ OPTmitosisImplementation(Client cntxt, M
                 * Determine the memory available for this client
                 */
 
-               /* respect the memory limit size set for the user 
-               * and determine the column slice size 
+               /* respect the memory limit size set for the user
+               * and determine the column slice size
                */
                if( cntxt->memorylimit)
                        m = (((size_t) cntxt->memorylimit) * 1048576) / argsize;
@@ -175,7 +178,7 @@ OPTmitosisImplementation(Client cntxt, M
                         * i.e., (rowcnt/pieces <= m/threads),
                         * i.e., (pieces => rowcnt/(m/threads))
                         * (assuming that (m > threads*MINPARTCNT)) */
-                       /* the number of pieces affects SF-100, going beyond 8x 
increases 
+                       /* the number of pieces affects SF-100, going beyond 8x 
increases
                         * the optimizer costs beyond the execution time
                         */
                        pieces = 4 * (int) ceil((double)rowcnt / m / threads);
@@ -192,8 +195,8 @@ OPTmitosisImplementation(Client cntxt, M
        if (pieces < threads)
                pieces = (int) MIN((BUN) threads, rowcnt);
        /* prevent plan explosion */
-       if (pieces > MAXSLICES)
-               pieces = MAXSLICES;
+       if (pieces > maxslices)
+               pieces = maxslices;
        /* to enable experimentation we introduce the option to set
         * the number of parts required and/or the size of each chunk (in K)
         */
diff --git a/sql/server/rel_dump.c b/sql/server/rel_dump.c
--- a/sql/server/rel_dump.c
+++ b/sql/server/rel_dump.c
@@ -986,15 +986,18 @@ function_error_string(mvc *sql, const ch
                                        schema ? "'.":"", fname, arg_list ? 
arg_list : "");
 }
 
-static void /* keep updating the label count */
+static unsigned int /* keep updating the label count */
 try_update_label_count(mvc *sql, const char *label)
 {
        if (label && label[0] == '%' && isdigit(label[1])) {
                char *eptr = NULL;
                unsigned int value = (unsigned int) strtol(label + 1, &eptr, 
10);
-               if (eptr && eptr[0] == '\0')
+               if (eptr && eptr[0] == '\0') {
                        sql->label = MAX(sql->label, value);
+                       return value;
+               }
        }
+       return 0;
 }
 
 static sql_exp*
@@ -1047,10 +1050,6 @@ exp_read(mvc *sql, sql_rel *lrel, sql_re
                        } else if (!exp) {
                                exp = exp_column(sql->sa, tname, cname, NULL, 
CARD_ATOM, 1, 0, cname[0] == '%');
                        }
-                       if (exp) {
-                               try_update_label_count(sql, tname);
-                               try_update_label_count(sql, cname);
-                       }
                }
                break;
        /* atom */
@@ -1500,8 +1499,6 @@ exp_read(mvc *sql, sql_rel *lrel, sql_re
                if (!exp && rrel)
                        exp = rel_bind_column(sql, rrel, var_cname, 0, 1);
                *e = old;
-               if (exp)
-                       try_update_label_count(sql, var_cname);
                skipWS(r,pos);
        }
 
@@ -1560,6 +1557,7 @@ exp_read(mvc *sql, sql_rel *lrel, sql_re
 
        /* as alias */
        if (strncmp(r+*pos, "as", 2) == 0) {
+               unsigned int rlabel = 0, nlabel = 0;
                (*pos)+=2;
                skipWS(r, pos);
 
@@ -1581,8 +1579,10 @@ exp_read(mvc *sql, sql_rel *lrel, sql_re
                        skipWS(r, pos);
                        exp_setname(sql->sa, exp, tname, cname);
                }
-               try_update_label_count(sql, tname);
-               try_update_label_count(sql, cname);
+               rlabel = try_update_label_count(sql, tname);
+               nlabel = try_update_label_count(sql, cname);
+               if (rlabel && rlabel == nlabel)
+                       exp->alias.label = rlabel;
        }
        return exp;
 }
@@ -1911,8 +1911,6 @@ rel_read(mvc *sql, char *r, int *pos, li
                                        set_basecol(next);
                                        append(outputs, next);
                                        m = m->next;
-                                       try_update_label_count(sql, nrname);
-                                       try_update_label_count(sql, ncname);
                                        skipWS(r, pos);
                                }
                                if (r[*pos] != ']')
diff --git a/sql/server/rel_optimizer.c b/sql/server/rel_optimizer.c
--- a/sql/server/rel_optimizer.c
+++ b/sql/server/rel_optimizer.c
@@ -1443,7 +1443,7 @@ static list *
 exps_push_single_func_down(visitor *v, sql_rel *rel, sql_rel *ol, sql_rel *or, 
list *exps, int depth)
 {
        if (mvc_highwater(v->sql))
-               return sql_error(v->sql, 10, SQLSTATE(42000) "Query too 
complex: running out of stack space");
+               return exps;
 
        for (node *n = exps->h; n; n = n->next)
                if ((n->data = exp_push_single_func_down(v, rel, ol, or, 
n->data, depth)) == NULL)
@@ -1455,7 +1455,7 @@ static sql_exp *
 exp_push_single_func_down(visitor *v, sql_rel *rel, sql_rel *ol, sql_rel *or, 
sql_exp *e, int depth)
 {
        if (mvc_highwater(v->sql))
-               return sql_error(v->sql, 10, SQLSTATE(42000) "Query too 
complex: running out of stack space");
+               return e;
 
        switch(e->type) {
        case e_cmp: {
@@ -1590,8 +1590,7 @@ rel_push_count_down(visitor *v, sql_rel 
 {
        sql_rel *r = rel->l;
 
-       assert(is_groupby(rel->op));
-       if (!rel_is_ref(rel) && list_empty(rel->r) &&
+       if (is_groupby(rel->op) && !rel_is_ref(rel) && list_empty(rel->r) &&
                r && !r->exps && r->op == op_join && !(rel_is_ref(r)) &&
                /* currently only single count aggregation is handled, no other 
projects or aggregation */
                list_length(rel->exps) == 1 && 
exp_aggr_is_count(rel->exps->h->data)) {
@@ -7925,7 +7924,7 @@ static sql_rel *
 rel_split_project(visitor *v, sql_rel *rel, int top)
 {
        if (mvc_highwater(v->sql))
-               return sql_error(v->sql, 10, SQLSTATE(42000) "Query too 
complex: running out of stack space");
+               return rel;
 
        if (!rel)
                return NULL;
@@ -8043,7 +8042,7 @@ static sql_rel *
 rel_split_select(visitor *v, sql_rel *rel, int top)
 {
        if (mvc_highwater(v->sql))
-               return sql_error(v->sql, 10, SQLSTATE(42000) "Query too 
complex: running out of stack space");
+               return rel;
 
        if (!rel)
                return NULL;
@@ -9662,7 +9661,7 @@ rel_push_func_and_select_down(visitor *v
 }
 
 static sql_rel *
-optimize_rel(mvc *sql, sql_rel *rel, visitor *v, global_props *gp)
+optimize_rel(visitor *v, sql_rel *rel, global_props *gp)
 {
        int level = *(int*)v->data;
 
@@ -9750,7 +9749,7 @@ optimize_rel(mvc *sql, sql_rel *rel, vis
 
        /* Remove unused expressions */
        if (level <= 0)
-               rel = rel_dce(sql, rel);
+               rel = rel_dce(v->sql, rel);
 
        if (gp->cnt[op_join] || gp->cnt[op_left] || gp->cnt[op_right] || 
gp->cnt[op_full] || gp->cnt[op_semi] || gp->cnt[op_anti] || gp->cnt[op_select])
                rel = rel_visitor_topdown(v, rel, 
&rel_push_func_and_select_down);
@@ -9847,7 +9846,7 @@ rel_optimizer(mvc *sql, sql_rel *rel, in
                gp = (global_props) {.cnt = {0},};
                rel_properties(sql, &gp, rel); /* collect relational tree 
properties */
                if (opt == 2) {
-                       rel = optimize_rel(sql, rel, &v, &gp);
+                       rel = optimize_rel(&v, rel, &gp);
                } else { /* the merge table rewriter may have to run */
                        rel = rel_visitor_topdown(&v, rel, 
&rel_merge_table_rewrite);
                }
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
@@ -3211,9 +3211,9 @@ rewrite_ifthenelse(visitor *v, sql_rel *
                sql_exp *cond = l->h->data;
                sql_exp *then_exp = l->h->next->data;
                sql_exp *else_exp = l->h->next->next->data;
-               sql_exp *not_cond, *cond_is_null;
-
-               if (exp_has_rel(then_exp) || exp_has_rel(else_exp)) {
+               sql_exp *not_cond;//, *cond_is_null;
+
+               if (!exp_has_rel(cond) && (exp_has_rel(then_exp) || 
exp_has_rel(else_exp))) {
                        bool single = false;
                        //return sql_error(v->sql, 10, SQLSTATE(42000) "time to 
rewrite into union\n");
                        // union(
@@ -3249,13 +3249,19 @@ rewrite_ifthenelse(visitor *v, sql_rel *
                        rsq = rel_project(v->sql->sa, rsq, 
append(sa_list(v->sql->sa), else_exp));
                        cond = exp_copy(v->sql, cond);
                        exp_set_freevar(v->sql, cond, rsq);
-                       not_cond = exp_compare(v->sql->sa, cond, 
exp_atom_bool(v->sql->sa, 0), cmp_equal);
+                       //not_cond = exp_compare(v->sql->sa, cond, 
exp_atom_bool(v->sql->sa, 0), cmp_equal);
+                       not_cond = exp_compare(v->sql->sa, cond, 
exp_atom_bool(v->sql->sa, 1), cmp_notequal);
+                       set_semantics(not_cond); /* also compare nulls */
+
+                       /*
                        cond = exp_copy(v->sql, cond);
                        cond_is_null = exp_compare(v->sql->sa, cond, 
exp_atom(v->sql->sa, atom_general(v->sql->sa, exp_subtype(cond), NULL)), 
cmp_equal);
                        set_has_no_nil(cond_is_null);
                        set_semantics(cond_is_null);
+                       */
                        set_processed(rsq);
-                       rsq = rel_select(v->sql->sa, rsq, exp_or(v->sql->sa, 
list_append(new_exp_list(v->sql->sa), not_cond), 
list_append(new_exp_list(v->sql->sa), cond_is_null), 0));
+                       //rsq = rel_select(v->sql->sa, rsq, exp_or(v->sql->sa, 
list_append(new_exp_list(v->sql->sa), not_cond), 
list_append(new_exp_list(v->sql->sa), cond_is_null), 0));
+                       rsq = rel_select(v->sql->sa, rsq, not_cond);
                        usq = rel_setop(v->sql->sa, lsq, rsq, op_union);
                        rel_setop_set_exps(v->sql, usq, 
append(sa_list(v->sql->sa), exp_ref(v->sql, e)), false);
                        if (single)
diff --git a/sql/test/SQLancer/Tests/sqlancer18.test 
b/sql/test/SQLancer/Tests/sqlancer18.test
--- a/sql/test/SQLancer/Tests/sqlancer18.test
+++ b/sql/test/SQLancer/Tests/sqlancer18.test
@@ -499,3 +499,19 @@ 16384
 
 statement ok
 ROLLBACK
+
+statement ok
+CREATE TABLE "t0" ("c0" BIGINT,"c1" BOOLEAN)
+
+statement ok rowcount 16
+INSERT INTO "t0" VALUES (NULL, true),(1, true),(4, true),(NULL, true),(NULL, 
true),(NULL, false),(9, true),(-217, true),
+(2, true),(4, false),(3, true),(7, true),(3, NULL),(-24, true),(2, true),(9, 
false)
+
+statement error GDK reported error: BATsubcross: more than one match
+SELECT 6 = ANY(SELECT 1 FROM t0 GROUP BY (SELECT t0.c0)), CASE WHEN 'a' = 
(SELECT 'b' FROM t0) THEN (VALUES (1)) END
+
+statement error GDK reported error: BATsubcross: more than one match
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to