Changeset: f54b972373b5 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f54b972373b5 Modified Files: sql/backends/monet5/sql_cat.c sql/server/rel_propagate.c sql/server/sql_mvc.c sql/server/sql_partition.c sql/server/sql_partition.h sql/storage/sql_storage.h sql/storage/store.c sql/test/merge-partitions/Tests/mergepart20.sql Branch: merge-partitions Log Message:
Delay the initialization of sql_parts to mvc_init But there are still many bugs :( diffs (truncated from 756 to 300 lines): diff --git a/sql/backends/monet5/sql_cat.c b/sql/backends/monet5/sql_cat.c --- a/sql/backends/monet5/sql_cat.c +++ b/sql/backends/monet5/sql_cat.c @@ -193,7 +193,6 @@ alter_table_add_range_partition(mvc *sql ptr pmin = NULL, pmax = NULL; size_t smin = 0, smax = 0, serr_min = 0, serr_max = 0; ssize_t (*atomtostr)(str *, size_t *, const void *); - int free_pmin = 1, free_pmax = 1; sql_subtype tpe; if((msg = validate_alter_table_add_table(sql, "sql.alter_table_add_range_partition", msname, mtname, psname, ptname, &mt, &pt, update))) { @@ -265,18 +264,7 @@ alter_table_add_range_partition(mvc *sql goto finish; } - if(!pmin) { - pmin = (ptr) ATOMnilptr(tp1); - smin = ATOMsize(tp1); - free_pmin = 0; - } - if(!pmax) { - pmax = (ptr) ATOMnilptr(tp1); - smax = ATOMsize(tp1); - free_pmax = 0; - } - - errcode = sql_trans_add_range_partition(sql->session->tr, mt, pt, tpe, pmin, smin, pmax, smax, with_nills, update, &err); + errcode = sql_trans_add_range_partition(sql->session->tr, mt, pt, tpe, pmin, pmax, with_nills, update, &err); switch(errcode) { case 0: break; @@ -322,9 +310,9 @@ finish: GDKfree(escaped_min); if(escaped_max) GDKfree(escaped_max); - if(pmin && free_pmin) + if(pmin) GDKfree(pmin); - if(pmax && free_pmax) + if(pmax) GDKfree(pmax); if(msg != MAL_SUCCEED) pt->p = NULL; diff --git a/sql/server/rel_propagate.c b/sql/server/rel_propagate.c --- a/sql/server/rel_propagate.c +++ b/sql/server/rel_propagate.c @@ -383,8 +383,6 @@ rel_generate_subdeletes(mvc *sql, sql_re sql_rel *s1, *dup = NULL; if(rel->r) { - /* if (frame_find_var(sql, sub->base.name)) TODO ask Niels about this - return sql_error(sql, 01, SQLSTATE(42000) "The name '%s' is already declared", sub->base.name);*/ dup = rel_copy(sql->sa, rel->r, 1); dup = rel_change_base_table(sql, dup, t, sub); } 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 @@ -22,6 +22,8 @@ #include "gdk_logger.h" #include "wlc.h" +extern str initialize_sql_parts(mvc* sql, sql_table *mt); + static int mvc_debug = 0; static void @@ -45,6 +47,10 @@ int mvc_init(int debug, store_type store, int ro, int su, backend_stack stk) { int first = 0; + sql_schema *s; + sql_table *t; + sqlid tid = 0, ntid, cid = 0, ncid, pid, rrid, lid, dpid, drid, dlid; + mvc *m; logger_settings log_settings; /* Set the default WAL directory. "sql_logs" by default */ @@ -82,34 +88,33 @@ mvc_init(int debug, store_type store, in fprintf(stderr, "!mvc_init: unable to create system tables\n"); return -1; } - if (first || catalog_version) { - sql_schema *s; - sql_table *t; - sqlid tid = 0, ntid, cid = 0, ncid, pid, rrid, lid, dpid, drid, dlid; - mvc *m = mvc_create(0, stk, 0, NULL, NULL); - if (!m) { - fprintf(stderr, "!mvc_init: malloc failure\n"); - return -1; - } + + m = mvc_create(0, stk, 0, NULL, NULL); + if (!m) { + fprintf(stderr, "!mvc_init: malloc failure\n"); + return -1; + } + + m->sa = sa_create(); + if (!m->sa) { + mvc_destroy(m); + fprintf(stderr, "!mvc_init: malloc failure\n"); + return -1; + } - m->sa = sa_create(); - if (!m->sa) { - mvc_destroy(m); - fprintf(stderr, "!mvc_init: malloc failure\n"); - return -1; - } + /* disable caching */ + m->caching = 0; + /* disable history */ + m->history = 0; + /* disable size header */ + m->sizeheader = 0; + if(mvc_trans(m) < 0) { + mvc_destroy(m); + fprintf(stderr, "!mvc_init: failed to start transaction\n"); + return -1; + } - /* disable caching */ - m->caching = 0; - /* disable history */ - m->history = 0; - /* disable size header */ - m->sizeheader = 0; - if(mvc_trans(m) < 0) { - mvc_destroy(m); - fprintf(stderr, "!mvc_init: failed to start transaction\n"); - return -1; - } + if (first || catalog_version) { s = m->session->schema = mvc_bind_schema(m, "sys"); assert(m->session->schema != NULL); @@ -261,17 +266,36 @@ mvc_init(int debug, store_type store, in sql_create_comments(m, s); sql_create_privileges(m, s); } - - s = m->session->schema = mvc_bind_schema(m, "tmp"); - assert(m->session->schema != NULL); + } - if (mvc_commit(m, 0, NULL) < 0) { - fprintf(stderr, "!mvc_init: unable to commit system tables\n"); - return -1; + //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) { + for (node *nn = ss->tables.set->h; nn; nn = nn->next) { + sql_table *tt = (sql_table*) nn->data; + if(isPartitionedByColumnTable(tt) || isPartitionedByExpressionTable(tt)) { + char *err; + if((err = initialize_sql_parts(m, tt)) != NULL) { + fprintf(stderr, "!mvc_init: unable to start partitioned table: %s.%s: %s\n", + ss->base.name, tt->base.name, err); + return -1; + } + } + } } + } - mvc_destroy(m); + s = m->session->schema = mvc_bind_schema(m, "tmp"); + assert(m->session->schema != NULL); + + if (mvc_commit(m, 0, NULL) < 0) { + fprintf(stderr, "!mvc_init: unable to commit system tables\n"); + return -1; } + + mvc_destroy(m); + return first; } 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 @@ -190,11 +190,12 @@ str find_partition_type(mvc* sql, sql_subtype *tpe, sql_table *mt) { str res = NULL; + sql_subtype *empty = sql_bind_localtype("void"); if(isPartitionedByColumnTable(mt)) { *tpe = mt->part.pcol->type; } else if(isPartitionedByExpressionTable(mt)) { - if(!mt->part.pexp->type.type && (res = bootstrap_partition_expression(sql, mt)) != NULL) + if(!strcmp(mt->part.pexp->type.type->base.name, empty->type->base.name) && (res = bootstrap_partition_expression(sql, mt)) != NULL) return res; *tpe = mt->part.pexp->type; } else { @@ -202,3 +203,73 @@ find_partition_type(mvc* sql, sql_subtyp } return res; } + +str +initialize_sql_parts(mvc* sql, sql_table *mt) +{ + str res = NULL; + sql_subtype found; + int localtype; + + if((res = find_partition_type(sql, &found, mt)) != NULL) + return res; + localtype = found.type->localtype; + for (node *n = mt->members.set->h; n; n = n->next) { + sql_part* next = (sql_part*) n->data; + next->tpe = found; + if(isListPartitionTable(mt)) { + for (node *m = next->part.values->h; m; m = m->next) { + sql_part_value* v = (sql_part_value*) m->data; + ValRecord vvalue; + ptr ok; + + v->tpe = found; + memset(&vvalue, 0, sizeof(ValRecord)); + ok = VALinit(&vvalue, TYPE_str, v->value); + if(ok) + ok = VALconvert(localtype, &vvalue); + if(ok) { + v->value = sa_alloc(sql->sa, vvalue.len); + memcpy(v->value, VALget(&vvalue), vvalue.len); + v->length = vvalue.len; + } + VALclear(&vvalue); + if(!ok) { + res = createException(SQL, "sql.partition", + SQLSTATE(42000) "Internal error while bootstrapping partitioned tables"); + goto finish; + } + } + } else if(isRangePartitionTable(mt)) { + ValRecord vmin, vmax; + ptr ok; + + memset(&vmin, 0, sizeof(ValRecord)); + memset(&vmax, 0, sizeof(ValRecord)); + ok = VALinit(&vmin, TYPE_str, next->part.range.minvalue); + if(ok) + ok = VALconvert(localtype, &vmin); + if(ok) + ok = VALinit(&vmax, TYPE_str, next->part.range.maxvalue); + if(ok) + ok = VALconvert(localtype, &vmax); + if(ok) { + next->part.range.minvalue = sa_alloc(sql->sa, vmin.len); + memcpy(next->part.range.minvalue, VALget(&vmin), vmin.len); + next->part.range.minlength = vmin.len; + next->part.range.maxvalue = sa_alloc(sql->sa, vmax.len); + memcpy(next->part.range.maxvalue, VALget(&vmax), vmax.len); + next->part.range.maxlength = vmax.len; + } + VALclear(&vmin); + VALclear(&vmax); + if(!ok) { + res = createException(SQL, "sql.partition", + SQLSTATE(42000) "Internal error while bootstrapping partitioned tables"); + goto finish; + } + } + } +finish: + return res; +} diff --git a/sql/server/sql_partition.h b/sql/server/sql_partition.h --- a/sql/server/sql_partition.h +++ b/sql/server/sql_partition.h @@ -13,5 +13,6 @@ #include "sql_catalog.h" extern str find_partition_type(mvc* sql, sql_subtype *tpe, sql_table *mt); +extern str initialize_sql_parts(mvc* sql, sql_table *mt); #endif //_SQL_PARTITION_H 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 @@ -360,7 +360,7 @@ extern int sql_trans_drop_schema(sql_tra extern sql_table *sql_trans_create_table(sql_trans *tr, sql_schema *s, const char *name, const char *sql, int tt, bit system, int persistence, int commit_action, int sz); extern int sql_trans_set_partition_table(sql_trans *tr, sql_table *t); extern sql_table *sql_trans_add_table(sql_trans *tr, sql_table *mt, sql_table *pt); -extern int sql_trans_add_range_partition(sql_trans *tr, sql_table *mt, sql_table *pt, sql_subtype tpe, ptr min, size_t smin, ptr max, size_t smax, int with_nills, int update, sql_part** err); +extern int sql_trans_add_range_partition(sql_trans *tr, sql_table *mt, sql_table *pt, sql_subtype tpe, ptr min, ptr max, int with_nills, int update, sql_part** err); extern int sql_trans_add_value_partition(sql_trans *tr, sql_table *mt, sql_table *pt, sql_subtype tpe, list* vals, int with_nills, int update, sql_part **err); extern sql_table *sql_trans_del_table(sql_trans *tr, sql_table *mt, sql_table *pt, int drop_action); diff --git a/sql/storage/store.c b/sql/storage/store.c --- a/sql/storage/store.c +++ b/sql/storage/store.c @@ -554,63 +554,63 @@ load_column(sql_trans *tr, sql_table *t, } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list