Changeset: 1048381a5a37 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1048381a5a37
Modified Files:
sql/server/rel_schema.c
sql/server/sql_mvc.c
sql/server/sql_partition.c
sql/storage/store.c
Branch: Jun2020
Log Message:
Propagate sql expression type to outer transaction table and use dup_sql_type.
diffs (263 lines):
diff --git a/sql/server/rel_schema.c b/sql/server/rel_schema.c
--- a/sql/server/rel_schema.c
+++ b/sql/server/rel_schema.c
@@ -955,27 +955,27 @@ create_partition_definition(mvc *sql, sq
{
char *err = NULL;
- if(partition_def) {
+ if (partition_def) {
dlist *list = partition_def->data.lval;
symbol *type = list->h->next->data.sym;
dlist *list2 = type->data.lval;
- if(isPartitionedByColumnTable(t)) {
+ if (isPartitionedByColumnTable(t)) {
str colname = list2->h->data.sval;
node *n;
sql_class sql_ec;
for (n = t->columns.set->h; n ; n = n->next) {
sql_column *col = n->data;
- if(!strcmp(col->base.name, colname)) {
+ if (!strcmp(col->base.name, colname)) {
t->part.pcol = col;
break;
}
}
- if(!t->part.pcol) {
+ if (!t->part.pcol) {
sql_error(sql, 02, SQLSTATE(42000) "CREATE
MERGE TABLE: the partition column '%s' is not part of the table", colname);
return SQL_ERR;
}
sql_ec = t->part.pcol->type.type->eclass;
- if(!(sql_ec == EC_BIT || EC_VARCHAR(sql_ec) ||
EC_TEMP(sql_ec) || sql_ec == EC_POS || sql_ec == EC_NUM ||
+ 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)) {
err = sql_subtype_string(&(t->part.pcol->type));
if (!err) {
@@ -986,8 +986,7 @@ create_partition_definition(mvc *sql, sq
}
return SQL_ERR;
}
- } else if(isPartitionedByExpressionTable(t)) {
- sql_subtype *empty = sql_bind_localtype("void");
+ } else if (isPartitionedByExpressionTable(t)) {
char *query = symbol2string(sql, list2->h->data.sym, 1,
&err);
if (!query) {
(void) sql_error(sql, 02, SQLSTATE(42000)
"CREATE MERGE TABLE: error compiling expression '%s'", err?err:"");
@@ -996,7 +995,7 @@ create_partition_definition(mvc *sql, sq
}
t->part.pexp = SA_ZNEW(sql->sa, sql_expression);
t->part.pexp->exp = sa_strdup(sql->sa, query);
- t->part.pexp->type = *empty;
+ t->part.pexp->type = *sql_bind_localtype("void");
_DELETE(query);
}
}
@@ -1091,7 +1090,7 @@ rel_create_table(sql_query *query, sql_s
return NULL;
}
- if(create_partition_definition(sql, t, partition_def) != SQL_OK)
+ if (create_partition_definition(sql, t, partition_def) !=
SQL_OK)
return NULL;
temp = (tt == tt_table)?temp:SQL_PERSIST;
diff --git a/sql/server/sql_mvc.c b/sql/server/sql_mvc.c
--- a/sql/server/sql_mvc.c
+++ b/sql/server/sql_mvc.c
@@ -369,7 +369,7 @@ mvc_init(int debug, store_type store, in
}
}
- if(mvc_trans(m) < 0) {
+ if (mvc_trans(m) < 0) {
mvc_destroy(m);
TRC_CRITICAL(SQL_TRANS, "Failed to start transaction\n");
return -1;
@@ -378,12 +378,12 @@ mvc_init(int debug, store_type store, in
//as the sql_parser is not yet initialized in the storage, we determine
the sql type of the sql_parts here
for (node *n = m->session->tr->schemas.set->h; n; n = n->next) {
sql_schema *ss = (sql_schema*) n->data;
- if(ss->tables.set) {
+ if (ss->tables.set) {
for (node *nn = ss->tables.set->h; nn; nn = nn->next) {
sql_table *tt = (sql_table*) nn->data;
- if(isPartitionedByColumnTable(tt) ||
isPartitionedByExpressionTable(tt)) {
+ if (isPartitionedByColumnTable(tt) ||
isPartitionedByExpressionTable(tt)) {
char *err;
- if((err = initialize_sql_parts(m, tt))
!= NULL) {
+ if ((err = initialize_sql_parts(m, tt))
!= NULL) {
TRC_CRITICAL(SQL_TRANS, "Unable
to start partitioned table: %s.%s: %s\n", ss->base.name, tt->base.name, err);
freeException(err);
return -1;
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
@@ -219,7 +219,7 @@ exp_find_table_columns(mvc *sql, sql_exp
}
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;
@@ -295,45 +295,49 @@ find_partition_type(sql_subtype *tpe, sq
}
str
-initialize_sql_parts(mvc* sql, sql_table *mt)
+initialize_sql_parts(mvc *sql, sql_table *mt)
{
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 */
+ dup_sql_type(tr, mt->s, &(mt->part.pexp->type),
&(mt->po->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_table* pt = find_sql_table(mt->s, next->base.name);
+ 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));
+ dup_sql_type(tr, mt->s, &found, &(p->tpe));
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));
+ dup_sql_type(tr, mt->s, &found,
&(nv->tpe));
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;
}
@@ -360,8 +364,8 @@ initialize_sql_parts(mvc* sql, sql_table
const void *nil_ptr =
ATOMnilptr(tpe);
size_t nil_len = ATOMlen(tpe,
nil_ptr);
- 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;
@@ -371,8 +375,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;
@@ -391,17 +395,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;
@@ -418,11 +416,12 @@ 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;
+ 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;
+ tr->schema_updates++;
finish:
return res;
}
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -895,10 +895,9 @@ load_table(sql_trans *tr, sql_schema *s,
assert((!isRangePartitionTable(t) && !isListPartitionTable(t)) || (!exp
&& !is_int_nil(pcolid)) || (exp && is_int_nil(pcolid)));
if (isPartitionedByExpressionTable(t)) {
- sql_subtype *empty = sql_bind_localtype("void");
t->part.pexp = SA_ZNEW(tr->sa, sql_expression);
t->part.pexp->exp = exp;
- t->part.pexp->type = *empty;
+ t->part.pexp->type = *sql_bind_localtype("void"); /*
initialized at initialize_sql_parts */
t->part.pexp->cols = sa_list(tr->sa);
}
for (rid = table_funcs.subrids_next(nrs); !is_oid_nil(rid); rid =
table_funcs.subrids_next(nrs)) {
@@ -3472,10 +3471,9 @@ table_dup(sql_trans *tr, int flags, sql_
t->cleared = 0;
if (isPartitionedByExpressionTable(ot)) {
- sql_subtype *empty = sql_bind_localtype("void");
t->part.pexp = SA_ZNEW(sa, sql_expression);
t->part.pexp->exp = sa_strdup(sa, ot->part.pexp->exp);
- t->part.pexp->type = *empty;
+ dup_sql_type((newFlagSet(flags))?tr->parent:tr, t->s,
&(ot->part.pexp->type), &(t->part.pexp->type));
t->part.pexp->cols = sa_list(sa);
for (n = ot->part.pexp->cols->h; n; n = n->next) {
int *nid = sa_alloc(sa, sizeof(int));
@@ -6214,9 +6212,8 @@ sql_trans_create_table(sql_trans *tr, sq
}
}
if (isPartitionedByExpressionTable(t)) {
- sql_subtype *empty = sql_bind_localtype("void");
t->part.pexp = SA_ZNEW(tr->sa, sql_expression);
- t->part.pexp->type = *empty;
+ t->part.pexp->type = *sql_bind_localtype("void"); /* leave it
non-initialized, at the backend the copy of this table will get the type */
}
ca = t->commit_action;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list