Changeset: 363a128a3522 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/363a128a3522 Modified Files: gdk/gdk.h gdk/gdk_bat.c gdk/gdk_batop.c monetdb5/modules/mal/remote.c sql/backends/monet5/sql.c sql/backends/monet5/sql_result.c sql/common/sql_types.c sql/server/rel_schema.c tools/monetdbe/monetdbe.c Branch: default Log Message:
Merge with Jul2021 branch. diffs (truncated from 1227 to 300 lines): diff --git a/gdk/gdk.h b/gdk/gdk.h --- a/gdk/gdk.h +++ b/gdk/gdk.h @@ -1896,7 +1896,7 @@ Tpos(BATiter *bi, BUN p) oid o; assert(!is_oid_nil(bi->tseq)); if (((ccand_t *) bi->vh)->type == CAND_NEGOID) { - BUN nexc = (bi->vh->free - sizeof(ccand_t)) / SIZEOF_OID; + BUN nexc = (bi->vhfree - sizeof(ccand_t)) / SIZEOF_OID; o = bi->tseq + p; if (nexc > 0) { const oid *exc = (const oid *) (bi->vh->base + sizeof(ccand_t)); @@ -1919,7 +1919,7 @@ Tpos(BATiter *bi, BUN p) } } else { const uint32_t *msk = (const uint32_t *) (bi->vh->base + sizeof(ccand_t)); - BUN nmsk = (bi->vh->free - sizeof(ccand_t)) / sizeof(uint32_t); + BUN nmsk = (bi->vhfree - sizeof(ccand_t)) / sizeof(uint32_t); o = 0; for (BUN i = 0; i < nmsk; i++) { uint32_t m = candmask_pop(msk[i]); diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c --- a/gdk/gdk_bat.c +++ b/gdk/gdk_bat.c @@ -1150,15 +1150,22 @@ BUNappendmulti(BAT *b, const void *value b->tnonil = false; b->tsorted = b->trevsorted = b->tkey = false; } - int (*atomcmp) (const void *, const void *) = ATOMcompare(b->ttype); - const void *atomnil = ATOMnilptr(b->ttype); - MT_lock_set(&b->theaplock); - BUN minpos = b->tminpos; - BUN maxpos = b->tmaxpos; - MT_lock_unset(&b->theaplock); MT_rwlock_wrlock(&b->thashlock); if (values && b->ttype) { + int (*atomcmp) (const void *, const void *) = ATOMcompare(b->ttype); + const void *atomnil = ATOMnilptr(b->ttype); + MT_lock_set(&b->theaplock); + BUN minpos = b->tminpos; + BUN maxpos = b->tmaxpos; + MT_lock_unset(&b->theaplock); + const void *minvalp = NULL, *maxvalp = NULL; + BATiter bi = bat_iterator_nolock(b); + if (minpos != BUN_NONE) + minvalp = BUNtail(bi, minpos); + if (maxpos != BUN_NONE) + maxvalp = BUNtail(bi, maxpos); if (b->tvarsized) { + const void *vbase = b->tvheap->base; for (BUN i = 0; i < count; i++) { t = ((void **) values)[i]; gdk_return rc = tfastins_nocheckVAR(b, p, t); @@ -1166,26 +1173,44 @@ BUNappendmulti(BAT *b, const void *value MT_rwlock_wrunlock(&b->thashlock); return rc; } + if (vbase != b->tvheap->base) { + /* tvheap changed location, so + * pointers may need to be + * updated (not if they were + * initialized from t below, but + * we don't know) */ + bi = bat_iterator_nolock(b); + vbase = b->tvheap->base; + if (minpos != BUN_NONE) + minvalp = BUNtvar(bi, minpos); + if (maxpos != BUN_NONE) + maxvalp = BUNtvar(bi, maxpos); + } if (b->thash) { HASHappend_locked(b, p, t); } if (atomcmp(t, atomnil) != 0) { if (p == 0) { minpos = maxpos = 0; + minvalp = maxvalp = t; } else { - BATiter bi = bat_iterator_nolock(b); if (minpos != BUN_NONE && - atomcmp(BUNtvar(bi, minpos), t) > 0) + atomcmp(minvalp, t) > 0) { minpos = p; + minvalp = t; + } if (maxpos != BUN_NONE && - atomcmp(BUNtvar(bi, maxpos), t) < 0) + atomcmp(maxvalp, t) < 0) { maxpos = p; + maxvalp = t; + } } } p++; } } else if (ATOMstorage(b->ttype) == TYPE_msk) { minpos = maxpos = BUN_NONE; + minvalp = maxvalp = NULL; for (BUN i = 0; i < count; i++) { t = (void *) ((char *) values + (i << b->tshift)); mskSetVal(b, p, *(msk *) t); @@ -1205,19 +1230,27 @@ BUNappendmulti(BAT *b, const void *value if (atomcmp(t, atomnil) != 0) { if (p == 0) { minpos = maxpos = 0; + minvalp = maxvalp = t; } else { - BATiter bi = bat_iterator_nolock(b); if (minpos != BUN_NONE && - atomcmp(BUNtloc(bi, minpos), t) > 0) + atomcmp(minvalp, t) > 0) { minpos = p; + minvalp = t; + } if (maxpos != BUN_NONE && - atomcmp(BUNtloc(bi, maxpos), t) < 0) + atomcmp(maxvalp, t) < 0) { maxpos = p; + maxvalp = t; + } } } p++; } } + MT_lock_set(&b->theaplock); + b->tminpos = minpos; + b->tmaxpos = maxpos; + MT_lock_unset(&b->theaplock); } else { for (BUN i = 0; i < count; i++) { gdk_return rc = tfastins_nocheck(b, p, t); @@ -1232,10 +1265,6 @@ BUNappendmulti(BAT *b, const void *value } } MT_rwlock_wrunlock(&b->thashlock); - MT_lock_set(&b->theaplock); - b->tminpos = minpos; - b->tmaxpos = maxpos; - MT_lock_unset(&b->theaplock); BATsetcount(b, p); IMPSdestroy(b); /* no support for inserts in imprints yet */ diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c --- a/gdk/gdk_batop.c +++ b/gdk/gdk_batop.c @@ -134,7 +134,7 @@ insert_string_bat(BAT *b, BAT *n, struct len = GDK_STRHASHSIZE + ci->ncand * (len + 12); /* len is total estimated expected size of vheap */ - if (len > ni.vh->free / 2) { + if (len > ni.vhfree / 2) { /* we copy the string heap, perhaps appending */ if (oldcnt == 0) { toff = 0; @@ -148,8 +148,8 @@ insert_string_bat(BAT *b, BAT *n, struct bat_iterator_end(&ni); return GDK_FAIL; } - memcpy(b->tvheap->base + toff, ni.vh->base, ni.vh->free); - b->tvheap->free = toff + ni.vh->free; + memcpy(b->tvheap->base + toff, ni.vh->base, ni.vhfree); + b->tvheap->free = toff + ni.vhfree; } } } @@ -256,7 +256,7 @@ insert_string_bat(BAT *b, BAT *n, struct break; } } - } else if (b->tvheap->free < ni.vh->free / 2 || + } else if (b->tvheap->free < ni.vhfree / 2 || GDK_ELIMDOUBLES(b->tvheap)) { /* if b's string heap is much smaller than n's string * heap, don't bother checking whether n's string diff --git a/gdk/gdk_project.c b/gdk/gdk_project.c --- a/gdk/gdk_project.c +++ b/gdk/gdk_project.c @@ -390,7 +390,7 @@ project_str(BAT *restrict l, struct cand TRANSIENT)) == NULL) return NULL; - v = (var_t) r1i->vh->free; + v = (var_t) r1i->vhfree; if (r1i->vh == r2i->vh) { h1off = 0; BBPshare(r1i->vh->parentid); @@ -400,18 +400,18 @@ project_str(BAT *restrict l, struct cand } else { v = (v + GDK_VARALIGN - 1) & ~(GDK_VARALIGN - 1); h1off = (BUN) v; - v += ((var_t) r2i->vh->free + GDK_VARALIGN - 1) & ~(GDK_VARALIGN - 1); + v += ((var_t) r2i->vhfree + GDK_VARALIGN - 1) & ~(GDK_VARALIGN - 1); if (HEAPextend(bn->tvheap, v, false) != GDK_SUCCEED) { BBPreclaim(bn); return NULL; } - memcpy(bn->tvheap->base, r1i->vh->base, r1i->vh->free); + memcpy(bn->tvheap->base, r1i->vh->base, r1i->vhfree); #ifndef NDEBUG - if (h1off > r1i->vh->free) - memset(bn->tvheap->base + r1i->vh->free, 0, h1off - r1i->vh->free); + if (h1off > r1i->vhfree) + memset(bn->tvheap->base + r1i->vhfree, 0, h1off - r1i->vhfree); #endif - memcpy(bn->tvheap->base + h1off, r2i->vh->base, r2i->vh->free); - bn->tvheap->free = h1off + r2i->vh->free; + memcpy(bn->tvheap->base + h1off, r2i->vh->base, r2i->vhfree); + bn->tvheap->free = h1off + r2i->vhfree; } if (v >= ((var_t) 1 << (8 << bn->tshift)) && 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 @@ -1558,7 +1558,7 @@ static str RMTbincopyto(Client cntxt, Ma vi.base, vi.count * vi.width, 1); if (sendtheap) mnstr_write(cntxt->fdout, /* theap */ - vi.vh->base, vi.vh->free, 1); + vi.vh->base, vi.vhfree, 1); bat_iterator_end(&vi); } /* flush is done by the calling environment (MAL) */ 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 @@ -6187,7 +6187,7 @@ rel2bin_catalog_table(backend *be, sql_r mvc *sql = be->mvc; node *en = rel->exps->h; stmt *action = exp_bin(be, en->data, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0); - stmt *table = NULL, *sname, *tname = NULL, *kname = NULL, *ifexists = NULL; + stmt *table = NULL, *sname, *tname = NULL, *kname = NULL, *ifexists = NULL, *replace = NULL; list *l = sa_list(sql->sa); if (!action) @@ -6222,6 +6222,7 @@ rel2bin_catalog_table(backend *be, sql_r table = exp_bin(be, en->data, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0); if (!table) return NULL; + en = en->next; } append(l, table); } else { @@ -6229,12 +6230,23 @@ rel2bin_catalog_table(backend *be, sql_r ifexists = exp_bin(be, en->data, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0); if (!ifexists) return NULL; + en = en->next; } else { ifexists = stmt_atom_int(be, 0); } append(l, ifexists); } append(l, action); + if (rel->flag == ddl_create_view) { + if (en) { + replace = exp_bin(be, en->data, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0); + if (!replace) + return NULL; + } else { + replace = stmt_atom_int(be, 0); + } + append(l, replace); + } return stmt_catalog(be, rel->flag, stmt_list(be, l)); } 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 @@ -307,33 +307,51 @@ SQLset_protocol(Client cntxt, MalBlkPtr } str -create_table_or_view(mvc *sql, char* sname, char *tname, sql_table *t, int temp) +create_table_or_view(mvc *sql, char *sname, char *tname, sql_table *t, int temp, int replace) { sql_allocator *osa; sql_schema *s = mvc_bind_schema(sql, sname); - sql_table *nt = NULL; + sql_table *nt = NULL, *ot; node *n; int check = 0; - const char *action = (temp == SQL_DECLARED_TABLE) ? "DECLARE" : "CREATE"; + const char *action = (temp == SQL_DECLARED_TABLE) ? "DECLARE" : (replace ? "CREATE OR REPLACE" : "CREATE"); const char *obj = t->query ? "VIEW" : "TABLE"; + str msg = MAL_SUCCEED; if (store_readonly(sql->session->tr->store)) return sql_error(sql, 06, SQLSTATE(25006) "schema statements cannot be executed on a readonly database."); if (!s) - return sql_message(SQLSTATE(3F000) "%s %s: schema '%s' doesn't exist", action, obj, sname); - if (mvc_bind_table(sql, s, t->base.name)) { - return sql_message(SQLSTATE(42S01) "%s %s: name '%s' already in use", action, obj, t->base.name); - } else if (temp != SQL_DECLARED_TABLE && (!mvc_schema_privs(sql, s) && !(isTempSchema(s) && temp == SQL_LOCAL_TEMP))) { - return sql_message(SQLSTATE(42000) "%s %s: insufficient privileges for user '%s' in schema '%s'", action, obj, get_string_global_var(sql, "current_user"), s->base.name); - } else if (temp == SQL_DECLARED_TABLE && ol_length(t->keys)) { - return sql_message(SQLSTATE(42000) "%s %s: '%s' cannot have constraints", action, obj, t->base.name); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list