Changeset: c903ca929669 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c903ca929669 Modified Files: sql/backends/monet5/rel_bin.c sql/backends/monet5/sql.c sql/backends/monet5/sql_cat.c sql/include/sql_catalog.h sql/server/rel_schema.c sql/server/sql_mvc.c sql/storage/sql_catalog.c sql/storage/store.c Branch: default Log Message:
keys -> objlist diffs (truncated from 413 to 300 lines): diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c --- a/sql/backends/monet5/rel_bin.c +++ b/sql/backends/monet5/rel_bin.c @@ -5364,10 +5364,10 @@ sql_delete_keys(backend *be, sql_table * int res = 1; node *n; - if (!t->keys.set) + if (!ol_length(t->keys)) return res; - for (n = t->keys.set->h; n; n = n->next) { + for (n = ol_first_node(t->keys); n; n = n->next) { sql_key *k = n->data; if (k->type == pkey || k->type == ukey) { @@ -5506,8 +5506,8 @@ check_for_foreign_key_references(mvc *sq return; sqlstore *store = sql->session->tr->store; - if (t->keys.set) { /* Check for foreign key references */ - for (n = t->keys.set->h; n; n = n->next) { + if (t->keys) { /* Check for foreign key references */ + for (n = ol_first_node(t->keys); n; n = n->next) { sql_key *k = n->data; if (k->type == ukey || k->type == pkey) { 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 @@ -319,7 +319,7 @@ create_table_or_view(mvc *sql, char* sna return sql_message(SQLSTATE(42S01) "%s TABLE: name '%s' already in use", action, t->base.name); } else if (temp != SQL_DECLARED_TABLE && (!mvc_schema_privs(sql, s) && !(isTempSchema(s) && temp == SQL_LOCAL_TEMP))) { return sql_message(SQLSTATE(42000) "%s TABLE: insufficient privileges for user '%s' in schema '%s'", action, get_string_global_var(sql, "current_user"), s->base.name); - } else if (temp == SQL_DECLARED_TABLE && !list_empty(t->keys.set)) { + } else if (temp == SQL_DECLARED_TABLE && ol_length(t->keys)) { return sql_message(SQLSTATE(42000) "%s TABLE: '%s' cannot have constraints", action, t->base.name); } @@ -405,8 +405,8 @@ create_table_or_view(mvc *sql, char* sna } } } - if (t->keys.set) { - for (n = t->keys.set->h; n; n = n->next) { + if (t->keys) { + for (n = ol_first_node(t->keys); n; n = n->next) { sql_key *k = n->data; char *err = NULL; 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 @@ -103,10 +103,10 @@ rel_check_tables(mvc *sql, sql_table *nt throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER %s: to be added table index type doesn't match %s definition", errtable, errtable); } } else { //for partitioned tables we allow indexes but the key set must be exactly the same - if (cs_size(&nt->keys) != cs_size(&nnt->keys)) + if (ol_length(nt->keys) != ol_length(nnt->keys)) throw(SQL,"sql.rel_check_tables",SQLSTATE(3F000) "ALTER %s: to be added table key doesn't match %s definition", errtable, errtable); - if (cs_size(&nt->keys)) - for (n = nt->keys.set->h, m = nnt->keys.set->h; n && m; n = n->next, m = m->next) { + if (ol_length(nt->keys)) + for (n = ol_first_node(nt->keys), m = ol_first_node(nnt->keys); n && m; n = n->next, m = m->next) { sql_key *ni = n->data; sql_key *mi = m->data; @@ -550,8 +550,8 @@ drop_table(mvc *sql, char *sname, char * if (!mvc_schema_privs(sql, s) && !(isTempSchema(s) && t->persistence == SQL_LOCAL_TEMP)) throw(SQL,"sql.drop_table", SQLSTATE(42000) "DROP TABLE: access denied for %s to schema '%s'", get_string_global_var(sql, "current_user"), s->base.name); - if (!drop_action && t->keys.set) { - for (node *n = t->keys.set->h; n; n = n->next) { + if (!drop_action && t->keys) { + for (node *n = ol_first_node(t->keys); n; n = n->next) { sql_key *k = n->data; if (k->type == ukey || k->type == pkey) { @@ -619,7 +619,7 @@ drop_key(mvc *sql, char *sname, char *tn throw(SQL,"sql.drop_key", SQLSTATE(42000) "ALTER TABLE: access denied for %s to schema '%s'", get_string_global_var(sql, "current_user"), s->base.name); if (!(t = mvc_bind_table(sql, s, tname))) throw(SQL,"sql.drop_key", SQLSTATE(42S02) "ALTER TABLE: no such table '%s'", tname); - if (!(n = list_find_name(t->keys.set, kname))) + if (!(n = ol_find_name(t->keys, kname))) throw(SQL,"sql.drop_key", SQLSTATE(42000) "ALTER TABLE: no such constraint '%s'", kname); key = n->data; if (!drop_action && mvc_check_dependency(sql, key->base.id, KEY_DEPENDENCY, NULL)) @@ -990,24 +990,25 @@ alter_table(Client cntxt, mvc *sql, char throw(SQL,"sql.alter_table", SQLSTATE(40002) "ALTER TABLE: Failed to create index %s.%s", i->t->base.name, i->base.name); } } - if (t->keys.set) { + if (t->keys) { /* alter drop key */ - if (t->keys.dset) - for (n = t->keys.dset->h; n; n = n->next) { - sql_key *k = n->data; + for (n = ol_first_node(t->keys); n; n = n->next) { + sql_key *k = n->data; + + if ((!k->base.new && !k->base.deleted) || (k->base.new && k->base.deleted)) + continue; + if (k->base.deleted) { sql_key *nk = mvc_bind_key(sql, s, k->base.name); if (nk) { if (mvc_drop_key(sql, s, nk, k->drop_action)) throw(SQL,"sql.alter_table", SQLSTATE(HY013) MAL_MALLOC_FAIL); } + } else { /* new */ + str err; + if ((err = sql_partition_validate_key(sql, t, k, "ALTER"))) + return err; + mvc_copy_key(sql, nt, k); } - /* alter add key */ - for (n = t->keys.nelm; n; n = n->next) { - sql_key *k = n->data; - str err; - if ((err = sql_partition_validate_key(sql, t, k, "ALTER"))) - return err; - mvc_copy_key(sql, nt, k); } } return MAL_SUCCEED; 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 @@ -710,7 +710,7 @@ typedef struct sql_table { sql_ukey *pkey; objlist *columns; objlist *idxs; - changeset keys; + objlist *keys; changeset triggers; changeset members; /* member tables of merge/replica tables */ int drop_action; /* only needed for alter drop table */ 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 @@ -309,11 +309,12 @@ column_constraint_type(mvc *sql, const c (void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT PRIMARY KEY: a table can have only one PRIMARY KEY\n"); return res; } - if (name && (list_find_name(t->keys.set, name) || mvc_bind_key(sql, ss, name))) { + if (name && (ol_find_name(t->keys, name) || mvc_bind_key(sql, ss, name))) { (void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT %s: key %s already exists", (kt == pkey) ? "PRIMARY KEY" : "UNIQUE", name); return res; } k = (sql_key*)mvc_create_ukey(sql, t, name, kt); + k->base.new = 1; mvc_create_kc(sql, k, cs); mvc_create_ukey_done(sql, k); @@ -340,7 +341,7 @@ column_constraint_type(mvc *sql, const c } if (!rt) { return SQL_ERR; - } else if (name && (list_find_name(t->keys.set, name) || mvc_bind_key(sql, ss, name))) { + } else if (name && (ol_find_name(t->keys, name) || mvc_bind_key(sql, ss, name))) { (void) sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT FOREIGN KEY: key '%s' already exists", name); return res; } @@ -371,6 +372,7 @@ column_constraint_type(mvc *sql, const c return res; } fk = mvc_create_fkey(sql, t, name, fkey, rk, ref_actions & 255, (ref_actions>>8) & 255); + fk->k.base.new = 1; mvc_create_fkc(sql, fk, cs); res = SQL_OK; } break; @@ -504,7 +506,7 @@ table_foreign_key(mvc *sql, char *name, int ref_actions = n->next->next->next->next->data.i_val; assert(n->next->next->next->next->type == type_int); - if (name && (list_find_name(t->keys.set, name) || mvc_bind_key(sql, ss, name))) { + if (name && (ol_find_name(t->keys, name) || mvc_bind_key(sql, ss, name))) { sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT FOREIGN KEY: key '%s' already exists", name); return SQL_ERR; } @@ -526,6 +528,7 @@ table_foreign_key(mvc *sql, char *name, return SQL_ERR; } fk = mvc_create_fkey(sql, t, name, fkey, rk, ref_actions & 255, (ref_actions>>8) & 255); + fk->k.base.new = 1; for (fnms = rk->columns->h; nms && fnms; nms = nms->next, fnms = fnms->next) { char *nm = nms->data.sval; @@ -568,13 +571,14 @@ table_constraint_type(mvc *sql, char *na sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT PRIMARY KEY: a table can have only one PRIMARY KEY\n"); return SQL_ERR; } - if (name && (list_find_name(t->keys.set, name) || mvc_bind_key(sql, ss, name))) { + if (name && (ol_find_name(t->keys, name) || mvc_bind_key(sql, ss, name))) { sql_error(sql, 02, SQLSTATE(42000) "CONSTRAINT %s: key '%s' already exists", kt == pkey ? "PRIMARY KEY" : "UNIQUE", name); return SQL_ERR; } k = (sql_key*)mvc_create_ukey(sql, t, name, kt); + k->base.new = 1; for (; nms; nms = nms->next) { char *nm = nms->data.sval; sql_column *c = mvc_bind_column(sql, t, nm); @@ -859,10 +863,10 @@ table_element(sql_query *query, symbol * sql_error(sql, 02, SQLSTATE(2BM37) "%s: cannot drop column '%s': there are database objects which depend on it\n", action, cname); return SQL_ERR; } - if (!drop_action && t->keys.set) { + if (!drop_action && t->keys) { node *n, *m; - for (n = t->keys.set->h; n; n = n->next) { + for (n = ol_first_node(t->keys); n; n = n->next) { sql_key *k = n->data; for (m = k->columns->h; m; m = m->next) { sql_kc *kc = m->data; 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 @@ -1000,8 +1000,8 @@ mvc_bind_ukey(sql_table *t, list *colnam sql_key *res = NULL; int len = list_length(colnames); - if (cs_size(&t->keys)) - for (cur = t->keys.set->h; cur; cur = cur->next) { + if (ol_length(t->keys)) + for (cur = ol_first_node(t->keys); cur; cur = cur->next) { node *cc; sql_key *k = cur->data; diff --git a/sql/storage/sql_catalog.c b/sql/storage/sql_catalog.c --- a/sql/storage/sql_catalog.c +++ b/sql/storage/sql_catalog.c @@ -93,12 +93,6 @@ tr_version_of_parent(sql_trans *tr, ulng return 0; } -static void * -_cs_find_name(changeset * cs, const char *name) -{ - return _list_find_name(cs->set, name); -} - node * cs_find_name(changeset * cs, const char *name) { @@ -174,7 +168,10 @@ list_find_base_id(list *l, sqlid id) sql_key * find_sql_key(sql_table *t, const char *kname) { - return _cs_find_name(&t->keys, kname); + node *n = ol_find_name(t->keys, kname); + if (n) + return n->data; + return NULL; } sql_key * @@ -228,7 +225,7 @@ find_sql_table(sql_trans *tr, sql_schema { sql_table *t = (sql_table*)os_find_name(s->tables, tr, tname); if (!t && tr->tmp == s) - t = (sql_table*)_cs_find_name(&tr->localtmps, tname); + t = (sql_table*)_list_find_name(tr->localtmps.set, tname); return t; } diff --git a/sql/storage/store.c b/sql/storage/store.c --- a/sql/storage/store.c +++ b/sql/storage/store.c @@ -214,7 +214,7 @@ table_destroy(sqlstore *store, sql_table /* cleanup its parts */ cs_destroy(&t->members, store); ol_destroy(t->idxs, store); - cs_destroy(&t->keys, store); + ol_destroy(t->keys, store); cs_destroy(&t->triggers, store); ol_destroy(t->columns, store); if (isPartitionedByExpressionTable(t)) { @@ -676,7 +676,7 @@ load_table(sql_trans *tr, sql_schema *s, t->columns = ol_new(tr->sa, (destroy_fptr) &column_destroy); t->idxs = ol_new(tr->sa, (destroy_fptr) &idx_destroy); - cs_new(&t->keys, tr->sa, (fdestroy) &key_destroy); + t->keys = ol_new(tr->sa, (destroy_fptr) &key_destroy); cs_new(&t->triggers, tr->sa, (fdestroy) &trigger_destroy); if (isMergeTable(t) || isReplicaTable(t)) cs_new(&t->members, tr->sa, (fdestroy) &part_destroy); @@ -746,7 +746,7 @@ load_table(sql_trans *tr, sql_schema *s, for (rid = store->table_api.rids_next(rs); !is_oid_nil(rid); rid = store->table_api.rids_next(rs)) { sql_key *k = load_key(tr, t, rid); - cs_add(&t->keys, k, 0); + ol_add(t->keys, &k->base); if (os_add(s->keys, tr, k->base.name, dup_base(&k->base)) || os_add(tr->cat->objects, tr, k->base.name, dup_base(&k->base))) { key_destroy(store, k); @@ -1366,7 +1366,7 @@ create_sql_table_with_id(sql_allocator * t->access = 0; t->columns = ol_new(sa, (destroy_fptr) &column_destroy); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list