Changeset: dbd43c1afe35 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/dbd43c1afe35
Modified Files:
        sql/backends/monet5/rel_bin.c
        sql/backends/monet5/sql_statement.c
        sql/backends/monet5/sql_upgrades.c
        sql/backends/monet5/vaults/csv/csv.c
        sql/backends/monet5/vaults/json/json.c
        sql/server/rel_dump.c
        sql/server/rel_exp.c
        sql/server/rel_exp.h
        sql/server/rel_optimize_others.c
        sql/server/rel_optimize_proj.c
        sql/server/rel_optimize_sel.c
        sql/server/rel_rewriter.c
        sql/server/rel_select.c
        sql/server/rel_statistics.c
        sql/server/rel_unnest.c
        sql/storage/store.c
        sql/test/emptydb/Tests/check.stable.out
        sql/test/emptydb/Tests/check.stable.out.32bit
Branch: nested
Log Message:

merged with default


diffs (truncated from 1738 to 300 lines):

diff --git a/common/stream/bs.c b/common/stream/bs.c
--- a/common/stream/bs.c
+++ b/common/stream/bs.c
@@ -93,8 +93,14 @@ bs_write(stream *restrict ss, const void
                         * to the left */
                        blksize <<= 1;
                        if (!mnstr_writeSht(ss->inner, (int16_t) blksize) ||
-                           ss->inner->write(ss->inner, s->buf, 1, s->nr) != 
(ssize_t) s->nr) {
-                               mnstr_copy_error(ss, ss->inner);
+                           ss->inner->write(ss->inner, s->buf, 1, s->nr) != 
(ssize_t) s->nr
+                       ) {
+                               if (mnstr_errnr(ss->inner) != MNSTR_NO__ERROR) {
+                                       mnstr_copy_error(ss, ss->inner);
+                               } else {
+                                       mnstr_set_error(ss, MNSTR_WRITE_ERROR, 
"connection closed unexpectedly");
+                               }
+
                                s->nr = 0; /* data is lost due to error */
                                return -1;
                        }
diff --git a/common/stream/mapi_stream.c b/common/stream/mapi_stream.c
--- a/common/stream/mapi_stream.c
+++ b/common/stream/mapi_stream.c
@@ -56,6 +56,7 @@ discard(stream *s)
 struct mapi_filetransfer {
        stream *from_client; // set to NULL after sending MAPI_PROMPT3
        stream *to_client; // set to NULL when client sends empty
+       bstream *bs;
 };
 
 static ssize_t
@@ -77,7 +78,8 @@ upload_read(stream *restrict s, void *re
                        mnstr_write(state->to_client, PROMPT2, strlen(PROMPT2), 
1) != 1
                ||      mnstr_flush(state->to_client, MNSTR_FLUSH_ALL) < 0
        ) {
-               mnstr_set_error(s, mnstr_errnr(state->to_client), "%s", 
mnstr_peek_error(state->to_client));
+               state->bs->pos = state->bs->len;
+               mnstr_copy_error(s, state->to_client);
                return -1;
        }
 
@@ -92,6 +94,7 @@ upload_read(stream *restrict s, void *re
                state->from_client = NULL;
                return nread;
        } else {
+               state->bs->pos = state->bs->len;
                mnstr_set_error(s, mnstr_errnr(state->from_client), "%s", 
mnstr_peek_error(state->from_client));
                return -1;
        }
@@ -116,7 +119,15 @@ download_write(stream *restrict s, const
 {
        struct mapi_filetransfer *state = s->stream_data.p;
        stream *to = state->to_client;
-       return to->write(to, buf, elmsize, cnt);
+       ssize_t res = to->write(to, buf, elmsize, cnt);
+       if (res < 0) {
+               state->bs->pos = state->bs->len;
+               mnstr_copy_error(s, to);
+       } else if (res == 0) {
+               assert(to->eof);
+               s->eof = to->eof;
+       }
+       return res;
 }
 
 static void
@@ -205,6 +216,7 @@ setup_transfer(const char *req, const ch
        }
        state->from_client = rs;
        state->to_client = ws;
+       state->bs = bs;
        s->stream_data.p = state;
 end:
        if (msg) {
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
@@ -2269,7 +2269,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l
                                }
                                if (!s)
                                        return s;
-                               if (s->nrcols == 0 && first && left)
+                               if (s->nrcols == 0 && first && left && 
left->nrcols)
                                        s = stmt_const(be, 
bin_find_smallest_column(be, swapped?right:left), s);
                                list_append(ops, s);
                                first = 0;
@@ -2996,7 +2996,7 @@ rel2bin_table(backend *be, sql_rel *rel,
 {
        mvc *sql = be->mvc;
        list *l;
-       stmt *sub = NULL, *osub = NULL;
+       stmt *sub = NULL;
        node *en, *n;
        sql_exp *op = rel->r;
 
@@ -3223,8 +3223,10 @@ rel2bin_table(backend *be, sql_rel *rel,
                s = stmt_alias(be, s, exp->alias.label, rnme, exp_name(exp));
                list_append(l, s);
        }
+       /*
        if (osub && osub->nrcols)
-               list_merge(l, osub->op4.lval, NULL);
+               list_join(l, osub->op4.lval);
+               */
        sub = stmt_list(be, l);
        return sub;
 }
@@ -5163,6 +5165,7 @@ rel2bin_project(backend *be, sql_rel *re
        psub = stmt_list(be, pl);
        if (psub == NULL)
                return NULL;
+       int nrcols = 0;
        for (en = rel->exps->h; en; en = en->next) {
                sql_exp *exp = en->data;
 
@@ -5184,6 +5187,8 @@ rel2bin_project(backend *be, sql_rel *re
                        s = const_column(be, s);
                else if (sub && sub->nrcols >= 1 && s->nrcols == 0)
                        s = stmt_const(be, bin_find_smallest_column(be, sub), 
s);
+               else if (nrcols && s->nrcols == 0)
+                       s = stmt_const(be, pl->h->data, s);
 
                if (!exp_name(exp))
                        exp_label(sql->sa, exp, ++sql->label);
@@ -5191,6 +5196,11 @@ rel2bin_project(backend *be, sql_rel *re
                        s = stmt_rename(be, exp, s);
                        s->label = exp->alias.label;
                }
+               if (!nrcols && s->nrcols && !list_empty(pl)) {
+                       for (node *n = pl->h; n; n=n->next)
+                               n->data = stmt_const(be, s, n->data);
+               }
+               nrcols = s->nrcols;
                list_append(pl, s);
        }
        stmt_set_nrcols(psub);
diff --git a/sql/backends/monet5/sql_optimizer.c 
b/sql/backends/monet5/sql_optimizer.c
--- a/sql/backends/monet5/sql_optimizer.c
+++ b/sql/backends/monet5/sql_optimizer.c
@@ -58,7 +58,6 @@ SQLgetSpace(mvc *m, MalBlkPtr mb, int pr
 {
        sql_trans *tr = m->session->tr;
        lng size,space = 0, i;
-       str lasttable = 0;
 
        for (i = 0; i < mb->stop; i++) {
                InstrPtr p = mb->stmt[i];
@@ -84,11 +83,10 @@ SQLgetSpace(mvc *m, MalBlkPtr mb, int pr
                                continue;
 
                        /* we have to sum the cost of all three components of a 
BAT */
-                       if (c && isTable(c->t) && (lasttable == 0 || 
strcmp(lasttable,tname)==0)) {
+                       if (c && isTable(c->t)) {
                                size = SQLgetColumnSize(tr, c, access);
                                space += size;  // accumulate once per table
-                               //lasttable = tname;     invalidate this attempt
-                               if (!prepare && size == 0 && !t->system)
+                               if (!prepare && size == 0  && !t->system)
                                        setFunctionId(p, emptybindRef);
                        }
                }
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
@@ -1113,6 +1113,7 @@ stmt_const(backend *be, stmt *s, stmt *v
                ns->nr = getDestVar(q);
                ns->tname = val->tname;
                ns->cname = val->cname;
+               ns->label = val->label;
                return ns;
        }
   bailout:
@@ -2053,7 +2054,7 @@ select2_join2(backend *be, stmt *op1, st
 
                int r1 = op2->nr;
                int r2 = op3->nr;
-               int rs = 0;
+               /* int rs = 0; */
                q = newStmtArgs(mb, algebraRef, cmd, 12);
                if (q == NULL)
                        goto bailout;
@@ -2071,12 +2072,12 @@ select2_join2(backend *be, stmt *op1, st
                }
                if (sub) /* only for uselect2 */
                        q = pushArgument(mb, q, sub->nr);
-               if (rs) {
-                       q = pushArgument(mb, q, rs);
-               } else {
-                       q = pushArgument(mb, q, r1);
-                       q = pushArgument(mb, q, r2);
-               }
+               /* if (rs) { */
+                       /* q = pushArgument(mb, q, rs); */
+               /* } else { */
+               q = pushArgument(mb, q, r1);
+               q = pushArgument(mb, q, r2);
+               /* } */
                if (type == st_join2) {
                        q = pushNilBat(mb, q);
                        q = pushNilBat(mb, q);
@@ -3407,13 +3408,11 @@ stmt_catalog(backend *be, int type, stmt
 void
 stmt_set_nrcols(stmt *s)
 {
-       unsigned nrcols = 0;
-       int key = 1;
-       node *n;
-       list *l = s->op4.lval;
+       unsigned int nrcols = 0;
+       unsigned int key = 1;
 
        assert(s->type == st_list);
-       for (n = l->h; n; n = n->next) {
+       for (node *n = s->op4.lval->h; n; n = n->next) {
                stmt *f = n->data;
 
                if (!f)
@@ -3433,9 +3432,8 @@ stmt_list(backend *be, list *l)
        if (l == NULL)
                return NULL;
        stmt *s = stmt_create(be->mvc->sa, st_list);
-       if(!s) {
+       if(!s)
                return NULL;
-       }
        s->op4.lval = l;
        stmt_set_nrcols(s);
        return s;
@@ -4509,7 +4507,6 @@ stmt_convert(backend *be, stmt *v, stmt 
        InstrPtr q = NULL;
        const char *convert = t->type->d.impl, *mod = calcRef;
        int pushed = (v->cand && v->cand == sel), no_candidates = 0;
-       bool add_tz = false;
        /* convert types and make sure they are rounded up correctly */
 
        if (v->nr < 0)
@@ -4601,15 +4598,13 @@ stmt_convert(backend *be, stmt *v, stmt 
                q = pushInt(mb, q, 3);
        }
        q = pushArgument(mb, q, v->nr);
-       if (add_tz)
-                       q = pushLng(mb, q, be->mvc->timezone);
        if (sel && !pushed && !v->cand) {
                q = pushArgument(mb, q, sel->nr);
                pushed = 1;
        } else if (v->nrcols > 0 && !no_candidates) {
                q = pushNilBat(mb, q);
        }
-       if (!add_tz && (t->type->eclass == EC_DEC || 
EC_TEMP_FRAC(t->type->eclass) || EC_INTERVAL(t->type->eclass))) {
+       if (t->type->eclass == EC_DEC || EC_TEMP_FRAC(t->type->eclass) || 
EC_INTERVAL(t->type->eclass)) {
                /* digits, scale of the result decimal */
                q = pushInt(mb, q, t->digits);
                if (!EC_TEMP_FRAC(t->type->eclass))
diff --git a/sql/backends/monet5/sql_upgrades.c 
b/sql/backends/monet5/sql_upgrades.c
--- a/sql/backends/monet5/sql_upgrades.c
+++ b/sql/backends/monet5/sql_upgrades.c
@@ -5246,6 +5246,36 @@ sql_update_dec2025(Client c, mvc *sql, s
        return err;
 }
 
+static str
+sql_update_default(Client c, mvc *sql, sql_schema *s)
+{
+       char *err;
+       res_table *output;
+       BAT *b;
+
+       (void) sql;
+       (void) s;
+
+       /* 2048 is id of column sys.table_partitions.id */
+       err = SQLstatementIntern(c, "select * from sys.dependencies where id = 
2048 and depend_id = (select f.id from sys.functions f where name = 
'get_merge_table_partition_expressions');\n", "update", true, false, &output);
+       if (err)
+               return err;
+       b = BATdescriptor(output->cols[0].b);
+       if (b != NULL) {
+               if (BATcount(b) != 0) {
+                       const char query[] =
+                               "delete from sys.dependencies where id = 2048 
and depend_id = (select f.id from sys.functions f where name = 
'get_merge_table_partition_expressions');\n";
+                       printf("Running database upgrade commands:\n%s\n", 
query);
+                       fflush(stdout);
+                       err = SQLstatementIntern(c, query, "update", true, 
false, NULL);
+               }
+               BBPreclaim(b);
+       }
+       res_table_destroy(output);
+
+       return err;
+}
+
 int
 SQLupgrades(Client c, mvc *m)
 {
@@ -5329,6 +5359,11 @@ SQLupgrades(Client c, mvc *m)
                goto handle_error;
        }
 
+       if ((err = sql_update_default(c, m, s)) != NULL) {
+               TRC_CRITICAL(SQL_PARSER, "%s\n", err);
+               goto handle_error;
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to