Changeset: 63185d4f377e for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=63185d4f377e Modified Files: sql/include/sql_catalog.h sql/storage/store.c Branch: Feb2013 Log Message:
correctly handle all kinds of tables diffs (232 lines): 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 @@ -440,6 +440,7 @@ typedef enum table_types { #define isStream(x) (x->type==tt_stream) #define isRemote(x) (x->type==tt_remote) #define isReplicaTable(x) (x->type==tt_replica_table) +#define isKindOfTable(x) (isTable(x) || isMergeTable(x) || isRemote(x) || isReplicaTable(x)) typedef struct sql_table { sql_base base; diff --git a/sql/storage/store.c b/sql/storage/store.c --- a/sql/storage/store.c +++ b/sql/storage/store.c @@ -596,7 +596,7 @@ load_table(sql_trans *tr, sql_schema *s, cs_add(&t->columns, load_column(tr, t, rid), TR_OLD); table_funcs.rids_destroy(rs); - if (!isTable(t) && !isMergeTable(t) && !isReplicaTable(t) && !isRemote(t)) + if (!isKindOfTable(t)) return t; /* load idx's first as the may be needed by the keys */ @@ -2476,18 +2476,20 @@ rollforward_create_table(sql_trans *tr, if (bs_debug) fprintf(stderr, "#create table %s\n", t->base.name); - if (isTable(t) && isGlobal(t)) { + if (isKindOfTable(t) && isGlobal(t)) { int p = (tr->parent == gtrans && !isTempTable(t)); /* only register columns without commit action tables */ ok = rollforward_changeset_creates(tr, &t->columns, (rfcfunc) &rollforward_create_column, mode); - if (p && mode == R_SNAPSHOT) - store_funcs.snapshot_create_del(tr, t); - else if (p && mode == R_LOG) - store_funcs.log_create_del(tr, t); - else if (mode == R_APPLY) - store_funcs.create_del(tr, t); + if (isTable(t)) { + if (p && mode == R_SNAPSHOT) + store_funcs.snapshot_create_del(tr, t); + else if (p && mode == R_LOG) + store_funcs.log_create_del(tr, t); + else if (mode == R_APPLY) + store_funcs.create_del(tr, t); + } if (ok == LOG_OK) ok = rollforward_changeset_creates(tr, &t->tables, (rfcfunc) &rollforward_add_table, mode); @@ -2608,7 +2610,7 @@ rollforward_drop_table(sql_trans *tr, sq if (ok == LOG_OK) ok = rollforward_changeset_deletes(tr, &t->columns, (rfdfunc) &rollforward_drop_column, mode); if (ok == LOG_OK) - ok = rollforward_changeset_deletes(tr, &t->tables, (rfdfunc) NULL, mode); + ok = rollforward_changeset_deletes(tr, &t->tables, (rfdfunc) &rollforward_del_table, mode); if (ok == LOG_OK) ok = rollforward_changeset_deletes(tr, &t->idxs, (rfdfunc) &rollforward_drop_idx, mode); if (ok == LOG_OK) @@ -2644,7 +2646,7 @@ rollforward_update_table(sql_trans *tr, int ok = LOG_OK; /* cannot update views and temporary tables */ - if (!isTable(ft) || isTempTable(ft)) + if (isView(ft) || isTempTable(ft)) return ok; ok = rollforward_changeset_updates(tr, &ft->columns, &tt->columns, &tt->base, (rfufunc) NULL, (rfcfunc) &rollforward_create_column, (rfdfunc) &rollforward_drop_column, (dupfunc) &column_dup, mode); @@ -2660,17 +2662,19 @@ rollforward_update_table(sql_trans *tr, if (ok != LOG_OK) return LOG_ERR; - if (p && mode == R_SNAPSHOT) { - ok = store_funcs.snapshot_table(tr, ft, tt); - } else if (p && mode == R_LOG) { - ok = store_funcs.log_table(tr, ft, tt); - } else if (mode == R_APPLY) { - assert(cs_size(&tt->columns) == cs_size(&ft->columns)); - if (bs_debug) - fprintf(stderr, "#update table %s\n", tt->base.name); - ok = store_funcs.update_table(tr, ft, tt); - ft->cleared = 0; - ft->base.rtime = ft->base.wtime = 0; + if (isTable(ft)) { + if (p && mode == R_SNAPSHOT) { + ok = store_funcs.snapshot_table(tr, ft, tt); + } else if (p && mode == R_LOG) { + ok = store_funcs.log_table(tr, ft, tt); + } else if (mode == R_APPLY) { + assert(cs_size(&tt->columns) == cs_size(&ft->columns)); + if (bs_debug) + fprintf(stderr, "#update table %s\n", tt->base.name); + ok = store_funcs.update_table(tr, ft, tt); + ft->cleared = 0; + ft->base.rtime = ft->base.wtime = 0; + } } return ok; } @@ -2796,7 +2800,7 @@ validate_tables(sql_schema *s, sql_schem continue; ot = find_sql_table(os, t->base.name); - if (ot && isTable(ot) && isTable(t)) { + if (ot && isKindOfTable(ot) && isKindOfTable(t)) { if ((t->base.wtime && (t->base.wtime < ot->base.rtime || t->base.wtime < ot->base.wtime)) || (t->base.rtime && (t->base.rtime < ot->base.wtime))) return 0; @@ -2936,18 +2940,18 @@ reset_column(sql_trans *tr, sql_column * if (isTable(fc->t)) { store_funcs.destroy_col(NULL, fc); store_funcs.dup_col(tr, pfc, fc); - - fc->null = pfc->null; - fc->unique = pfc->unique; - fc->storage_type = NULL; - if (pfc->storage_type) - fc->storage_type = sa_strdup(tr->sa, pfc->storage_type); - if (fc->def) - sa_strdup(tr->sa, fc->def); - fc->def = NULL; - if (pfc->def) - fc->def = sa_strdup(tr->sa, pfc->def); } + + fc->null = pfc->null; + fc->unique = pfc->unique; + fc->storage_type = NULL; + if (pfc->storage_type) + fc->storage_type = sa_strdup(tr->sa, pfc->storage_type); + if (fc->def) + sa_strdup(tr->sa, fc->def); + fc->def = NULL; + if (pfc->def) + fc->def = sa_strdup(tr->sa, pfc->def); fc->base.wtime = fc->base.rtime = 0; } return LOG_OK; @@ -2970,7 +2974,7 @@ reset_seq(sql_trans *tr, sql_sequence *f static int reset_table(sql_trans *tr, sql_table *ft, sql_table *pft) { - if (!isTable(ft) || isTempTable(ft)) + if (isView(ft) || isTempTable(ft)) return LOG_OK; /* did we make changes or is the global changed after we started */ @@ -2985,6 +2989,8 @@ reset_table(sql_trans *tr, sql_table *ft ft->base.wtime = ft->base.rtime = 0; ok = reset_changeset( tr, &ft->columns, &pft->columns, &ft->base, (resetf) &reset_column, (dupfunc) &column_dup); if (ok == LOG_OK) + ok = reset_changeset( tr, &ft->tables, &pft->tables, &ft->base, (resetf) NULL, (dupfunc) &table_find); + if (ok == LOG_OK) ok = reset_changeset( tr, &ft->idxs, &pft->idxs, &ft->base, (resetf) &reset_idx, (dupfunc) &idx_dup); if (ok == LOG_OK) ok = reset_changeset( tr, &ft->keys, &pft->keys, &ft->base, (resetf) NULL, (dupfunc) &key_dup); @@ -2995,6 +3001,23 @@ reset_table(sql_trans *tr, sql_table *ft return LOG_OK; } +static void +reset_table_of_tables_dup(sql_table *omt, sql_schema *s, int flag) +{ + node *n; + sql_table *mt = schema_table_find(s, omt); + + if (omt->tables.set && !mt->tables.set) { + for (n = omt->tables.set->h; n; n = n->next) { + sql_table *pt = n->data; + sql_table *npt = schema_table_find(s, pt); + cs_add(&mt->tables, npt, tr_flag(&pt->base, flag)); + npt->p = mt; + } + mt->tables.nelm = NULL; + } +} + static int reset_schema(sql_trans *tr, sql_schema *fs, sql_schema *pfs) { @@ -3043,6 +3066,15 @@ reset_schema(sql_trans *tr, sql_schema * if (ok == LOG_OK) return reset_changeset(tr, &fs->tables, &pfs->tables, &fs->base, (resetf) &reset_table, (dupfunc) &table_dup); + if (ok == LOG_OK) { + node *n; + for (n = pfs->tables.set->h; n; n = n->next) { + sql_table *ot = n->data; + + if (ot->persistence != SQL_LOCAL_TEMP && (isMergeTable(ot) || isReplicaTable(ot))) + reset_table_of_tables_dup(ot, fs, ot->base.flag); + } + } } return ok; } @@ -3470,14 +3502,14 @@ sys_drop_table(sql_trans *tr, sql_table sql_trans_drop_dependencies(tr, t->base.id); - if (isTable(t)) + if (isKindOfTable(t)) sys_drop_columns(tr, t, drop_action); if (isGlobal(t)) tr->schema_updates ++; if (drop_action) - sql_trans_drop_all_dependencies(tr, t->s, t->base.id, isTable(t) ? TABLE_DEPENDENCY : VIEW_DEPENDENCY); + sql_trans_drop_all_dependencies(tr, t->s, t->base.id, !isView(t) ? TABLE_DEPENDENCY : VIEW_DEPENDENCY); } static void @@ -4121,7 +4153,7 @@ sql_trans_drop_column(sql_trans *tr, sql list_append(tr->dropped, local_id); } - if (isTable(t)) + if (isKindOfTable(t)) sys_drop_column(tr, col, drop_action); col->base.wtime = t->base.wtime = t->s->base.wtime = tr->wtime = tr->wstime; @@ -4834,7 +4866,7 @@ sql_session_reset(sql_session *s, int ac for (n = tmp->tables.set->h; n; n = n->next) { sql_table *t = n->data; - if (isGlobal(t) && isTable(t)) + if (isGlobal(t) && isKindOfTable(t)) sql_trans_clear_table(s->tr, t); } } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list