Changeset: d81aa6801791 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d81aa6801791
Modified Files:
        sql/server/sql_partition.c
        sql/server/sql_semantic.c
        sql/storage/bat/bat_storage.c
        sql/storage/sql_storage.h
        sql/storage/store.c
Branch: Nov2019
Log Message:

merged


diffs (truncated from 337 to 300 lines):

diff --git a/sql/server/sql_partition.c b/sql/server/sql_partition.c
--- a/sql/server/sql_partition.c
+++ b/sql/server/sql_partition.c
@@ -10,6 +10,7 @@
 
 #include "sql_partition.h"
 #include "rel_rel.h"
+#include "rel_exp.h"
 #include "sql_mvc.h"
 #include "sql_catalog.h"
 #include "sql_relation.h"
@@ -217,50 +218,8 @@ exp_find_table_columns(mvc *sql, sql_exp
        }
 }
 
-static str
-find_expression_type(sql_exp *e, sql_subtype *tpe)
-{
-       switch (e->type) {
-               case e_convert: {
-                       assert(list_length(e->r) == 2);
-                       *tpe = *(sql_subtype *)list_fetch(e->r, 1);
-               } break;
-               case e_atom: {
-                       if (e->l) {
-                               atom *a = e->l;
-                               *tpe = a->tpe;
-                       } else if (e->r) {
-                               *tpe = e->tpe;
-                       } else if (e->f) {
-                               throw(SQL,"sql.partition", SQLSTATE(42000) 
"List of values not allowed in expressions");
-                       } else {
-                               throw(SQL,"sql.partition", SQLSTATE(42000) 
"Variables/parameters are not allowed in expressions");
-                       }
-               } break;
-               case e_func: {
-                       sql_subfunc *f = e->f;
-                       sql_func *func = f->func;
-                       if (list_length(func->res) != 1)
-                               throw(SQL,"sql.partition", SQLSTATE(42000) "An 
expression should return a single value");
-                       *tpe = *(sql_subtype *)f->res->h->data;
-               }       break;
-               case e_cmp: {
-                       sql_subtype *other = sql_bind_localtype("bit");
-                       *tpe = *other;
-               } break;
-               case e_column: {
-                       *tpe = e->tpe;
-               } break;
-               case e_psm:
-                       throw(SQL,"sql.partition", SQLSTATE(42000) "PSM calls 
are not allowed in expressions");
-               case e_aggr:
-                       throw(SQL,"sql.partition", SQLSTATE(42000) "Aggregation 
functions are not allowed in expressions");
-       }
-       return NULL;
-}
-
 str
-bootstrap_partition_expression(mvc* sql, sql_allocator *rsa, sql_table *mt, 
int instantiate)
+bootstrap_partition_expression(mvc *sql, sql_allocator *rsa, sql_table *mt, 
int instantiate)
 {
        sql_exp *exp;
        char *query, *msg = NULL;
@@ -288,9 +247,7 @@ bootstrap_partition_expression(mvc* sql,
                mt->part.pexp->cols = sa_list(rsa);
        exp_find_table_columns(sql, exp, mt, mt->part.pexp->cols);
 
-       if ((msg = find_expression_type(exp, &(mt->part.pexp->type))) != NULL)
-               return msg;
-
+       mt->part.pexp->type = *exp_subtype(exp);
        sql_ec = mt->part.pexp->type.type->eclass;
        if (!(sql_ec == EC_BIT || EC_VARCHAR(sql_ec) || EC_TEMP(sql_ec) || 
sql_ec == EC_POS || sql_ec == EC_NUM ||
                 EC_INTERVAL(sql_ec)|| sql_ec == EC_DEC || sql_ec == EC_BLOB)) {
@@ -306,8 +263,7 @@ bootstrap_partition_expression(mvc* sql,
 
        if (instantiate) {
                r = rel_project(sql->sa, r, NULL);
-               r->exps = sa_list(sql->sa);
-               list_append(r->exps, exp);
+               exp = rel_project_add_exp(sql, r, exp);
 
                if (r)
                        r = rel_unnest(sql, r);
@@ -346,40 +302,43 @@ initialize_sql_parts(mvc* sql, sql_table
        str res = NULL;
        sql_subtype found;
        int localtype;
+       sql_trans *tr = sql->session->tr;
 
-       if (isPartitionedByExpressionTable(mt) && (res = 
bootstrap_partition_expression(sql, sql->session->tr->sa, mt, 0)) != NULL)
+       if (isPartitionedByExpressionTable(mt) && (res = 
bootstrap_partition_expression(sql, tr->sa, mt, 0)) != NULL)
                return res;
        find_partition_type(&found, mt);
        localtype = found.type->localtype;
+       if (isPartitionedByExpressionTable(mt)) /* Propagate type to outer 
transaction table */
+               mt->po->part.pexp->type = mt->part.pexp->type;
 
        if (localtype != TYPE_str && mt->members.set && 
list_length(mt->members.set)) {
-               list *new = sa_list(sql->session->tr->sa), *old = 
sa_list(sql->session->tr->sa);
+               list *new = sa_list(tr->sa), *old = sa_list(tr->sa);
 
                for (node *n = mt->members.set->h; n; n = n->next) {
-                       sql_part* next = (sql_part*) n->data, *p = 
SA_ZNEW(sql->session->tr->sa, sql_part);
+                       sql_part* next = (sql_part*) n->data, *p = 
SA_ZNEW(tr->sa, sql_part);
                        sql_table* pt = find_sql_table(mt->s, next->base.name);
 
-                       base_init(sql->session->tr->sa, &p->base, pt->base.id, 
TR_NEW, pt->base.name);
+                       base_init(tr->sa, &p->base, pt->base.id, TR_NEW, 
pt->base.name);
                        p->t = mt;
                        assert(isMergeTable(mt) || isReplicaTable(mt));
-                       dup_sql_type(sql->session->tr, mt->s, &found, 
&(p->tpe));
+                       p->tpe = found;
                        p->with_nills = next->with_nills;
 
                        if (isListPartitionTable(mt)) {
-                               p->part.values = sa_list(sql->session->tr->sa);
+                               p->part.values = sa_list(tr->sa);
 
                                for (node *m = next->part.values->h; m; m = 
m->next) {
-                                       sql_part_value *v = (sql_part_value*) 
m->data, *nv = SA_ZNEW(sql->session->tr->sa, sql_part_value);
+                                       sql_part_value *v = (sql_part_value*) 
m->data, *nv = SA_ZNEW(tr->sa, sql_part_value);
                                        ValRecord vvalue;
                                        ptr ok;
 
-                                       dup_sql_type(sql->session->tr, mt->s, 
&found, &(nv->tpe));
+                                       nv->tpe = found;
                                        vvalue = (ValRecord) {.vtype = 
TYPE_void,};
                                        ok = VALinit(&vvalue, TYPE_str, 
v->value);
                                        if (ok)
                                                ok = VALconvert(localtype, 
&vvalue);
                                        if (ok) {
-                                               nv->value = 
sa_alloc(sql->session->tr->sa, vvalue.len);
+                                               nv->value = sa_alloc(tr->sa, 
vvalue.len);
                                                memcpy(nv->value, 
VALget(&vvalue), vvalue.len);
                                                nv->length = vvalue.len;
                                        }
@@ -407,8 +366,8 @@ initialize_sql_parts(mvc* sql, sql_table
                                                size_t nil_len = ATOMlen(tpe, 
nil_ptr);
 
                                                assert(p->with_nills && 
next->with_nills);
-                                               p->part.range.minvalue = 
sa_alloc(sql->session->tr->sa, nil_len);
-                                               p->part.range.maxvalue = 
sa_alloc(sql->session->tr->sa, nil_len);
+                                               p->part.range.minvalue = 
sa_alloc(tr->sa, nil_len);
+                                               p->part.range.maxvalue = 
sa_alloc(tr->sa, nil_len);
                                                memcpy(p->part.range.minvalue, 
nil_ptr, nil_len);
                                                memcpy(p->part.range.maxvalue, 
nil_ptr, nil_len);
                                                p->part.range.minlength = 
nil_len;
@@ -418,8 +377,8 @@ initialize_sql_parts(mvc* sql, sql_table
                                                if (ok)
                                                        ok = 
VALconvert(localtype, &vmax);
                                                if (ok) {
-                                                       p->part.range.minvalue 
= sa_alloc(sql->session->tr->sa, vmin.len);
-                                                       p->part.range.maxvalue 
= sa_alloc(sql->session->tr->sa, vmax.len);
+                                                       p->part.range.minvalue 
= sa_alloc(tr->sa, vmin.len);
+                                                       p->part.range.maxvalue 
= sa_alloc(tr->sa, vmax.len);
                                                        
memcpy(p->part.range.minvalue, VALget(&vmin), vmin.len);
                                                        
memcpy(p->part.range.maxvalue, VALget(&vmax), vmax.len);
                                                        p->part.range.minlength 
= vmin.len;
@@ -438,17 +397,11 @@ initialize_sql_parts(mvc* sql, sql_table
                        list_append(new, p);
                        list_append(old, next);
                }
-               for (node *n = old->h; n; n = n->next) { //remove the old
-                       sql_part* next = (sql_part*) n->data;
-                       sql_table* pt = find_sql_table(mt->s, next->base.name);
-
-                       pt->p = NULL;
-                       cs_del(&mt->members, n, next->base.flags);
-                       sql_trans_drop_dependency(sql->session->tr, 
next->base.id, mt->base.id, TABLE_DEPENDENCY);
-               }
+               for (node *n = old->h; n; n = n->next) /* remove the old */
+                       cs_del(&mt->members, n, 0);
                for (node *n = new->h; n; n = n->next) {
-                       sql_part* next = (sql_part*) n->data;
-                       sql_table* pt = find_sql_table(mt->s, next->base.name);
+                       sql_part *next = (sql_part*) n->data;
+                       sql_table *pt = find_sql_table(mt->s, next->base.name);
                        sql_part *err = NULL;
 
                        pt->p = mt;
@@ -465,11 +418,14 @@ initialize_sql_parts(mvc* sql, sql_table
                                                                          
SQLSTATE(42000) "Internal error while bootstrapping partitioned tables");
                                goto finish;
                        }
-                       pt->s->base.wtime = pt->base.wtime = 
sql->session->tr->wtime = sql->session->tr->wstime;
-                       sql_trans_create_dependency(sql->session->tr, 
pt->base.id, mt->base.id, TABLE_DEPENDENCY);
+                       pt->s->base.wtime = pt->base.wtime = tr->wtime = 
tr->wstime;
+                       if (isGlobal(pt))
+                               tr->schema_updates++;
                }
-               mt->s->base.wtime = mt->base.wtime = sql->session->tr->wtime = 
sql->session->tr->wstime;
        }
+       mt->s->base.wtime = mt->base.wtime = tr->wtime = tr->wstime;
+       if (isGlobal(mt))
+               tr->schema_updates++;
 finish:
        return res;
 }
diff --git a/sql/server/sql_semantic.c b/sql/server/sql_semantic.c
--- a/sql/server/sql_semantic.c
+++ b/sql/server/sql_semantic.c
@@ -466,13 +466,12 @@ symbol2string(mvc *sql, symbol *se, int 
                _DELETE(tpe);
                return res;
        }
-       case SQL_AGGR:
-       case SQL_SELECT:
-       case SQL_CASE:
-       case SQL_COALESCE:
-       case SQL_NULLIF:
-       default:
-               return NULL;
+       default: {
+               const char *msg = "SQL feature not yet available for 
expressions and default values: ";
+               char *tok_str = token2string(se->token);
+               if ((*err = NEW_ARRAY(char, strlen(msg) + strlen(tok_str) + 1)))
+                       stpcpy(stpcpy(*err, msg), tok_str);
+       }
        }
        return NULL;
 }
diff --git a/sql/storage/bat/bat_storage.c b/sql/storage/bat/bat_storage.c
--- a/sql/storage/bat/bat_storage.c
+++ b/sql/storage/bat/bat_storage.c
@@ -2788,7 +2788,6 @@ update_table(sql_trans *tr, sql_table *f
                        }
                }
 
-               dup_sql_type(tr, ft->s, &(cc->type), &(oc->type));
                oc->colnr = cc->colnr;
                oc->null = cc->null;
                oc->unique = cc->unique;
diff --git a/sql/storage/sql_storage.h b/sql/storage/sql_storage.h
--- a/sql/storage/sql_storage.h
+++ b/sql/storage/sql_storage.h
@@ -474,6 +474,4 @@ extern sql_part *sql_trans_copy_part(sql
 extern void sql_trans_drop_any_comment(sql_trans *tr, sqlid id);
 extern void sql_trans_drop_obj_priv(sql_trans *tr, sqlid obj_id);
 
-extern void dup_sql_type(sql_trans *tr, sql_schema *os, sql_subtype *oc, 
sql_subtype *nc);
-
 #endif /*SQL_STORAGE_H */
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -1633,16 +1633,16 @@ create_sql_table(sql_allocator *sa, cons
        return create_sql_table_with_id(sa, next_oid(), name, type, system, 
persistence, commit_action, properties);
 }
 
-void
-dup_sql_type(sql_trans *tr, sql_schema *os, sql_subtype *oc, sql_subtype *nc)
+static void
+dup_sql_type(sql_trans *tr, sql_schema *s, sql_subtype *oc, sql_subtype *nc)
 {
        *nc = *oc;
-       if (nc->type->s) { /* user type */
+       if (s && nc->type->s) { /* user type */
                sql_type *lt = NULL;
 
-               if (os->base.id == nc->type->s->base.id) {
+               if (s->base.id == nc->type->s->base.id) {
                        /* Current user type belongs to current schema. So 
search there for current user type. */
-                       lt = find_sql_type(os, nc->type->base.name);
+                       lt = find_sql_type(s, nc->type->base.name);
                } else {
                        /* Current user type belongs to another schema in the 
current transaction. Search there for current user type. */
                        lt = sql_trans_bind_type(tr, NULL, nc->type->base.name);
@@ -3852,6 +3852,7 @@ rollforward_update_part(sql_trans *tr, s
                sql_part *pt = (sql_part *) tpt;
                sql_part *opt = (sql_part *) fpt;
 
+               pt->with_nills = opt->with_nills;
                if (isRangePartitionTable(opt->t)) {
                        pt->part.range.minvalue = sa_alloc(tr->sa, 
opt->part.range.minlength);
                        pt->part.range.maxvalue = sa_alloc(tr->sa, 
opt->part.range.maxlength);
@@ -3870,12 +3871,6 @@ rollforward_update_part(sql_trans *tr, s
                                list_append(pt->part.values, nextv);
                        }
                }
-
-               if (tpt->rtime < fpt->rtime)
-                       tpt->rtime = fpt->rtime;
-               if (tpt->wtime < fpt->wtime)
-                       tpt->wtime = fpt->wtime;
-               fpt->rtime = fpt->wtime = 0;
        }
        return LOG_OK;
 }
@@ -4204,7 +4199,6 @@ reset_column(sql_trans *tr, sql_column *
                                return LOG_ERR;
                }
 
-               dup_sql_type(tr, pfc->t->s, &(pfc->type), &(fc->type));
                fc->null = pfc->null;
                fc->unique = pfc->unique;
                fc->colnr = pfc->colnr;
@@ -4260,8 +4254,6 @@ reset_part(sql_trans *tr, sql_part *ft, 
                } else if (pft->t && isListPartitionTable(pft->t)) {
                        ft->part.values = pft->part.values;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to