Changeset: 17c946f67a6a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/17c946f67a6a
Modified Files:
sql/backends/monet5/rel_bin.c
sql/include/sql_catalog.h
sql/server/sql_parser.y
sql/storage/store.c
Branch: check
Log Message:
merge with default
diffs (truncated from 979 to 300 lines):
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -1711,6 +1711,9 @@ BBPjson_upgrade(json_storage_conversion
const char *nme;
nme = ATOMunknown_name(b->ttype);
+ int tt = ATOMindex(nme);
+ if (tt >= 0)
+ b->ttype = tt;
if (strcmp(nme, "json") != 0)
continue;
} else if (b->ttype != JSON_type) {
@@ -4065,34 +4068,41 @@ BBPsync(int cnt, bat *restrict subcommit
if (lock)
MT_lock_set(&GDKswapLock(bid));
}
- if (subcommit) {
+ BAT *b = BBP_desc(bid);
+ if (subcommit && b->ttype != TYPE_void) {
/* move any tail/theap files we find for this bat that
* are in the BACKUP directory to the SUBCOMMIT
* directory */
char fname[16]; /* plenty big enough */
- if (snprintf(fname, sizeof(fname), "%o", i) < 16) {
+ if (snprintf(fname, sizeof(fname), "%o", (unsigned)
bid) < 16) {
/* the snprintf never fails, any of the
* below may fail */
- if (GDKmove(0, BAKDIR, fname, "tail", SUBDIR,
fname, "tail", false) == GDK_SUCCEED)
- TRC_DEBUG(BAT_, "moved %s.tail from %s
to %s\n",
+ uint8_t stpe = ATOMstorage(b->ttype);
+ if ((b->ttype != TYPE_str || b->twidth >= 8) &&
+ GDKmove(0, BAKDIR, fname, "tail", SUBDIR,
fname, "tail", false) == GDK_SUCCEED)
+ TRC_DEBUG(IO_, "moved %s.tail from %s
to %s\n",
fname, BAKDIR, SUBDIR);
- if (GDKmove(0, BAKDIR, fname, "tail1", SUBDIR,
fname, "tail1", false) == GDK_SUCCEED)
- TRC_DEBUG(BAT_, "moved %s.tail1 from %s
to %s\n",
+ if (stpe == TYPE_str &&
+ GDKmove(0, BAKDIR, fname, "tail1", SUBDIR,
fname, "tail1", false) == GDK_SUCCEED)
+ TRC_DEBUG(IO_, "moved %s.tail1 from %s
to %s\n",
fname, BAKDIR, SUBDIR);
- if (GDKmove(0, BAKDIR, fname, "tail2", SUBDIR,
fname, "tail2", false) == GDK_SUCCEED)
- TRC_DEBUG(BAT_, "moved %s.tail2 from %s
to %s\n",
+ if (stpe == TYPE_str && b->twidth >= 2 &&
+ GDKmove(0, BAKDIR, fname, "tail2", SUBDIR,
fname, "tail2", false) == GDK_SUCCEED)
+ TRC_DEBUG(IO_, "moved %s.tail2 from %s
to %s\n",
fname, BAKDIR, SUBDIR);
#if SIZEOF_VAR_T == 8
- if (GDKmove(0, BAKDIR, fname, "tail4", SUBDIR,
fname, "tail4", false) == GDK_SUCCEED)
- TRC_DEBUG(BAT_, "moved %s.tail4 from %s
to %s\n",
+ if (stpe == TYPE_str && b->twidth >= 4 &&
+ GDKmove(0, BAKDIR, fname, "tail4", SUBDIR,
fname, "tail4", false) == GDK_SUCCEED)
+ TRC_DEBUG(IO_, "moved %s.tail4 from %s
to %s\n",
fname, BAKDIR, SUBDIR);
#endif
- if (GDKmove(0, BAKDIR, fname, "theap", SUBDIR,
fname, "theap", false) == GDK_SUCCEED)
- TRC_DEBUG(BAT_, "moved %s.theap from %s
to %s\n",
+ if (ATOMvarsized(b->ttype) &&
+ GDKmove(0, BAKDIR, fname, "theap", SUBDIR,
fname, "theap", false) == GDK_SUCCEED)
+ TRC_DEBUG(IO_, "moved %s.theap from %s
to %s\n",
fname, BAKDIR, SUBDIR);
}
}
- BAT *b = dirty_bat(&i, subcommit != NULL);
+ b = dirty_bat(&i, subcommit != NULL);
if (i <= 0)
ret = GDK_FAIL;
else if (BBP_status(bid) & BBPEXISTING &&
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
@@ -1519,8 +1519,13 @@ exp_bin(backend *be, sql_exp *e, stmt *l
}
if (!l)
return NULL;
- s = stmt_convert(be, l, (!push&&l->nrcols==0)?NULL:sel, from,
to);
- } break;
+ if (from->type->eclass == EC_SEC && to->type->eclass == EC_SEC)
{
+ // trivial conversion because EC_SEC is always in
milliseconds
+ s = l;
+ } else {
+ s = stmt_convert(be, l, (!push&&l->nrcols==0)?NULL:sel,
from, to);
+ }
+ } break;
case e_func: {
node *en;
list *l = sa_list(sql->sa), *exps = e->l;
diff --git a/sql/backends/monet5/sql_scenario.c
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -819,7 +819,7 @@ SQLtrans(mvc *m)
}
s = m->session;
if (!s->schema) {
- switch (monet5_user_get_def_schema(m, m->user_id,
&s->schema_name)) {
+ switch (monet5_user_get_def_schema(m, m->user_id,
&s->def_schema_name)) {
case -1:
mvc_cancel_session(m);
throw(SQL, "sql.trans", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
@@ -832,6 +832,7 @@ SQLtrans(mvc *m)
default:
break;
}
+ s->schema_name = s->def_schema_name;
if (!(s->schema = find_sql_schema(s->tr,
s->schema_name))) {
mvc_cancel_session(m);
throw(SQL, "sql.trans", SQLSTATE(42000) "The
session's schema was not found, this session is going to terminate");
diff --git a/sql/backends/monet5/sql_user.c b/sql/backends/monet5/sql_user.c
--- a/sql/backends/monet5/sql_user.c
+++ b/sql/backends/monet5/sql_user.c
@@ -849,6 +849,8 @@ monet5_user_set_def_schema(mvc *m, oid u
}
/* while getting the session's schema, set the search path as well */
+ /* new default schema */
+ m->session->def_schema_name = schema;
if (!(ok = mvc_set_schema(m, schema)) || (path_err =
parse_schema_path_str(m, schema_path, true)) != MAL_SUCCEED) {
if (m->session->tr->active && (other = mvc_rollback(m, 0, NULL,
false)) != MAL_SUCCEED)
freeException(other);
diff --git a/sql/common/sql_types.c b/sql/common/sql_types.c
--- a/sql/common/sql_types.c
+++ b/sql/common/sql_types.c
@@ -421,22 +421,29 @@ subtype_cmp(sql_subtype *t1, sql_subtype
{
if (!t1->type || !t2->type)
return -1;
+ if (t1->type->eclass != t2->type->eclass)
+ return -1;
+ switch (t1->type->eclass) {
+ case EC_SEC:
+ case EC_MONTH:
+ if (t1->digits != t2->digits)
+ return -1;
+ return 0;
+ case EC_NUM:
+ break;
+ case EC_FLT:
+ if (t1->digits != t2->digits)
+ return -1;
+ break;
+ default:
+ if (t1->digits != t2->digits)
+ return -1;
+ if (t1->scale != t2->scale)
+ return -1;
+ break;
+ }
- if (t1->type->eclass == t2->type->eclass && t1->type->eclass == EC_SEC)
- return 0;
- if (t1->type->eclass == t2->type->eclass && t1->type->eclass ==
EC_MONTH)
- return 0;
- if ( !(t1->type->eclass == t2->type->eclass &&
- (EC_INTERVAL(t1->type->eclass) || t1->type->eclass == EC_NUM)) &&
- (t1->digits != t2->digits ||
- (!(t1->type->eclass == t2->type->eclass &&
- t1->type->eclass == EC_FLT) &&
- t1->scale != t2->scale)) )
- return -1;
-
- /* subtypes are only equal iff
- they map onto the same systemtype */
- return (type_cmp(t1->type, t2->type));
+ return type_cmp(t1->type, t2->type);
}
int
diff --git a/sql/include/sql_catalog.h b/sql/include/sql_catalog.h
--- a/sql/include/sql_catalog.h
+++ b/sql/include/sql_catalog.h
@@ -759,6 +759,7 @@ typedef struct sql_session {
allocator *sa;
sql_trans *tr; /* active transaction */
+ char *def_schema_name; /* users default schema name */
char *schema_name; /* transaction's schema name */
sql_schema *schema;
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
@@ -2964,7 +2964,7 @@ exp_scale_algebra(mvc *sql, sql_subfunc
sql_subtype *lt = exp_subtype(l);
sql_subtype *rt = exp_subtype(r);
- if (lt->type->scale == SCALE_FIX && (lt->scale || rt->scale) &&
+ if (!EC_INTERVAL(lt->type->eclass) && lt->type->scale == SCALE_FIX &&
(lt->scale || rt->scale) &&
strcmp(sql_func_imp(f->func), "/") == 0) {
sql_subtype *res = f->res->h->data;
unsigned int scale, digits, digL, scaleL;
diff --git a/sql/server/rel_optimize_proj.c b/sql/server/rel_optimize_proj.c
--- a/sql/server/rel_optimize_proj.c
+++ b/sql/server/rel_optimize_proj.c
@@ -2983,10 +2983,41 @@ rel_groupjoin(visitor *v, sql_rel *rel)
return rel;
}
+/* select k1 from bla where k1 = const -> select const from bla where k1 =
const */
+static sql_rel *
+rel_project_select_exp(visitor *v, sql_rel *rel)
+{
+ if (is_simple_project(rel->op) && rel->exps && rel->l) {
+ sql_rel *l = rel->l;
+ if (is_select(l->op) && l->exps) {
+ for(node *n = rel->exps->h; n; n = n->next) {
+ sql_exp *col = n->data;
+ if (col->type == e_column) {
+ for(node *m = l->exps->h; m; m =
m->next) {
+ sql_exp *cmp = m->data;
+ if (cmp->type == e_cmp &&
cmp->flag == cmp_equal && !is_anti(cmp) && !is_semantics(cmp) &&
exp_is_atom(cmp->r)) {
+ sql_exp *l = cmp->l;
+ if(l->type == e_column
&& ((!col->l && !l->l) || (col->l && l->l && strcmp(col->l, l->l) == 0)) &&
strcmp(col->r, l->r) == 0) {
+ /* replace
column with the constant */
+ sql_exp *e =
n->data = exp_copy(v->sql, cmp->r);
+
exp_setname(v->sql->sa, e, exp_relname(col), exp_name(col));
+
exp_propagate(v->sql->sa, e, col);
+
list_hash_clear(rel->exps);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return rel;
+}
+
static sql_rel *
rel_optimize_projections_(visitor *v, sql_rel *rel)
{
rel = rel_project_cse(v, rel);
+ rel = rel_project_select_exp(v, rel);
if (!rel || !is_groupby(rel->op))
return rel;
diff --git a/sql/server/rel_psm.c b/sql/server/rel_psm.c
--- a/sql/server/rel_psm.c
+++ b/sql/server/rel_psm.c
@@ -614,6 +614,69 @@ has_return( list *l )
}
static list *
+psm_analyze(sql_query *query, dlist *qname, dlist *columns)
+{
+ mvc *sql = query->sql;
+ const char *sname = qname_schema(qname), *tname =
qname_schema_object(qname);
+ list *tl = sa_list(sql->sa), *exps = sa_list(sql->sa), *analyze_calls =
sa_list(sql->sa);
+ sql_subfunc *f = NULL;
+ sql_subtype tpe;
+
+ if (!sql_find_subtype(&tpe, "varchar", 1024, 0))
+ return sql_error(sql, 02, SQLSTATE(HY013) "varchar type
missing?");
+
+ if (sname && tname) {
+ sql_table *t = NULL;
+
+ if (!(t = find_table_or_view_on_scope(sql, NULL, sname, tname,
"ANALYZE", false)))
+ return NULL;
+ if (isDeclaredTable(t))
+ return sql_error(sql, 02, SQLSTATE(42000) "Cannot
analyze a declared table");
+ sname = t->s->base.name;
+ }
+ /* call analyze( [schema, [ table ]] ) */
+ if (sname) {
+ sql_exp *sname_exp = exp_atom_str(sql->sa, sname, &tpe);
+
+ list_append(exps, sname_exp);
+ list_append(tl, exp_subtype(sname_exp));
+ }
+ if (tname) {
+ sql_exp *tname_exp = exp_atom_str(sql->sa, tname, &tpe);
+
+ list_append(exps, tname_exp);
+ list_append(tl, exp_subtype(tname_exp));
+
+ if (columns)
+ list_append(tl, exp_subtype(tname_exp));
+ }
+ if (!columns) {
+ if (!(f = sql_bind_func_(sql, "sys", "analyze", tl, F_PROC,
true, false)))
+ return sql_error(sql, ERR_NOTFOUND, SQLSTATE(42000)
"Analyze procedure missing");
+ if (!execute_priv(sql, f->func))
+ return sql_error(sql, 02, SQLSTATE(42000) "No privilege
to call analyze procedure");
+ list_append(analyze_calls, exp_op(sql->sa, exps, f));
+ } else {
+ if (!sname || !tname)
+ return sql_error(sql, ERR_NOTFOUND, SQLSTATE(42000)
"Analyze schema or table name missing");
+ if (!(f = sql_bind_func_(sql, "sys", "analyze", tl, F_PROC,
true, false)))
+ return sql_error(sql, ERR_NOTFOUND, SQLSTATE(42000)
"Analyze procedure missing");
+ if (!execute_priv(sql, f->func))
+ return sql_error(sql, 02, SQLSTATE(42000) "No privilege
to call analyze procedure");
+ for(dnode *n = columns->h; n; n = n->next) {
+ const char *cname = n->data.sval;
+ list *nexps = list_dup(exps, NULL);
+ sql_exp *cname_exp = exp_atom_str(sql->sa, cname, &tpe);
+
+ list_append(nexps, cname_exp);
+ /* call analyze( opt_minmax, opt_sample_size, sname,
tname, cname) */
+ list_append(analyze_calls, exp_op(sql->sa, nexps, f));
+ }
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]