Changeset: e2de7eaa38dc for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e2de7eaa38dc Modified Files: sql/backends/monet5/sql.c sql/backends/monet5/sql_upgrades.c sql/server/sql_mvc.c sql/storage/store.c Branch: merge-partitions Log Message:
Added upgrade code and checks for expressions' length diffs (134 lines): 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 @@ -286,6 +286,7 @@ create_table_or_view(mvc *sql, char *sna sql_schema *s = mvc_bind_schema(sql, sname); sql_table *nt = NULL; node *n; + int check = 0; (void)tname; if (STORE_READONLY) @@ -356,7 +357,10 @@ create_table_or_view(mvc *sql, char *sna if(err) return err; } - if(sql_trans_set_partition_table(sql->session->tr, nt)) + check = sql_trans_set_partition_table(sql->session->tr, nt); + if(check == -1) + throw(SQL, "sql.catalog", SQLSTATE(42000) "CREATE TABLE: %s_%s: the partition's expression is too long", s->base.name, t->base.name); + else if(check) throw(SQL, "sql.catalog", SQLSTATE(42000) "CREATE TABLE: %s_%s: an internal error occurred", s->base.name, t->base.name); if (t->idxs.set) { 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 @@ -1622,6 +1622,40 @@ sql_update_remote_tables(Client c, mvc * } static str +sql_update_merge_partitions(Client c, mvc *sql) +{ + int i; + size_t bufsize = 2048, pos = 0; + char *buf = GDKmalloc(bufsize), *err = NULL; + char *schema = stack_get_string(sql, "current_schema"); + char *schemas_to_set[2] = {"sys", "tmp"}; + + if( buf== NULL) + throw(SQL, "sql_update_merge_partitions", SQLSTATE(HY001) MAL_MALLOC_FAIL); + + for(i = 0; i < 2; i++) { + pos += snprintf(buf + pos, bufsize - pos, "set schema \"%s\";\n", schemas_to_set[i]); + pos += snprintf(buf + pos, bufsize - pos, + "create table _table_partitions (id int, table_id int, column_id int, expression varchar(%d));\n", + STORAGE_MAX_VALUE_LENGTH); + pos += snprintf(buf + pos, bufsize - pos, + "create table _range_partitions (id int, partition_id int, minimum varchar(%d)," + "maximum varchar(%d), with_nulls boolean);\n", STORAGE_MAX_VALUE_LENGTH, STORAGE_MAX_VALUE_LENGTH); + pos += snprintf(buf + pos, bufsize - pos, + "create table _value_partitions (id int, partition_id int, value varchar(%d));\n", + STORAGE_MAX_VALUE_LENGTH); + } + if (schema) + pos += snprintf(buf + pos, bufsize - pos, "set schema \"%s\";\n", schema); + + assert(pos < bufsize); + printf("Running database upgrade commands:\n%s\n", buf); + err = SQLstatementIntern(c, &buf, "create partition system tables", 1, 0, NULL); + GDKfree(buf); + return err; /* usually MAL_SUCCEED */ +} + +static str sql_replace_Mar2018_ids_view(Client c, mvc *sql) { size_t bufsize = 4400, pos = 0; @@ -1927,4 +1961,11 @@ SQLupgrades(Client c, mvc *m) freeException(err); } } + + if (mvc_bind_table(m, s, "_table_partitions") == NULL) { + if ((err = sql_update_merge_partitions(c, m)) != NULL) { + fprintf(stderr, "!%s\n", err); + freeException(err); + } + } } 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 @@ -1314,6 +1314,7 @@ mvc_create_table(mvc *m, sql_schema *s, { sql_table *t = NULL; char *err = NULL; + int check = 0; if (mvc_debug) fprintf(stderr, "#mvc_create_table %s %s %d %d %d %d\n", s->base.name, name, tt, system, persistence, commit_action); @@ -1325,10 +1326,16 @@ mvc_create_table(mvc *m, sql_schema *s, t = sql_trans_create_table(m->session->tr, s, name, NULL, tt, system, persistence, commit_action, sz); if(t && isPartitionedByExpressionTable(t) && (err = bootstrap_partition_expression(m, t, 1))) { (void) sql_error(m, 02, "%s", err); - return SQL_ERR; + return NULL; } - if(sql_trans_set_partition_table(m->session->tr, t)) + check = sql_trans_set_partition_table(m->session->tr, t); + if(check == -1) { + (void) sql_error(m, 02, SQLSTATE(42000) "CREATE TABLE: %s_%s: the partition's expression is too long", s->base.name, t->base.name); return NULL; + } else if (check) { + (void) sql_error(m, 02, SQLSTATE(42000) "CREATE TABLE: %s_%s: an internal error occurred", s->base.name, t->base.name); + return NULL; + } } return t; } diff --git a/sql/storage/store.c b/sql/storage/store.c --- a/sql/storage/store.c +++ b/sql/storage/store.c @@ -1754,7 +1754,7 @@ store_load(void) { bootstrap_create_column(tr, t, "id", "int", 32); bootstrap_create_column(tr, t, "table_id", "int", 32); bootstrap_create_column(tr, t, "column_id", "int", 32); - bootstrap_create_column(tr, t, "expression", "varchar", 2048); + bootstrap_create_column(tr, t, "expression", "varchar", STORAGE_MAX_VALUE_LENGTH); t = bootstrap_create_table(tr, s, "_range_partitions"); bootstrap_create_column(tr, t, "id", "int", 32); @@ -4972,8 +4972,12 @@ sql_trans_set_partition_table(sql_trans sql_table *partitions = find_sql_table(syss, "_table_partitions"); oid next = next_oid(); if(isPartitionedByColumnTable(t)) { + assert(t->part.pcol); table_funcs.table_insert(tr, partitions, &next, &t->base.id, &t->part.pcol->base.id, ATOMnilptr(TYPE_str)); } else if(isPartitionedByExpressionTable(t)) { + assert(t->part.pexp->exp); + if(strlen(t->part.pexp->exp) > STORAGE_MAX_VALUE_LENGTH) + return -1; table_funcs.table_insert(tr, partitions, &next, &t->base.id, ATOMnilptr(TYPE_int), t->part.pexp->exp); } else { assert(0); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list