Changeset: 2111997f78f0 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2111997f78f0 Modified Files: clients/Tests/MAL-signatures.stable.out clients/Tests/MAL-signatures.stable.out.int128 sql/backends/monet5/rel_bin.c sql/backends/monet5/sql.c sql/backends/monet5/sql.h sql/backends/monet5/sql.mal sql/backends/monet5/sql_cat.c sql/server/rel_sequence.c sql/storage/sql_catalog.c sql/storage/sql_storage.h sql/storage/store.c sql/storage/store_sequence.c sql/storage/store_sequence.h sql/test/Tests/alter-sequence.sql sql/test/Tests/alter-sequence.stable.err Branch: default Log Message:
Merge with Nov2019 diffs (truncated from 620 to 300 lines): diff --git a/clients/Tests/MAL-signatures.stable.out b/clients/Tests/MAL-signatures.stable.out --- a/clients/Tests/MAL-signatures.stable.out +++ b/clients/Tests/MAL-signatures.stable.out @@ -9010,6 +9010,13 @@ stdout of test 'MAL-signatures` in direc [ "batsql", "prod", "pattern batsql.prod(b:bat[:lng], s:bat[:lng], e:bat[:lng]):bat[:lng] ", "SQLprod;", "return the product of groups" ] [ "batsql", "prod", "pattern batsql.prod(b:bat[:sht], s:bat[:lng], e:bat[:lng]):bat[:lng] ", "SQLprod;", "return the product of groups" ] [ "batsql", "rank", "pattern batsql.rank(b:bat[:any_1], p:any_2, o:any_3):bat[:int] ", "SQLrank;", "return the ranked groups" ] +[ "batsql", "restart", "unsafe pattern batsql.restart(sname:bat[:str], sequence:bat[:str], start:bat[:lng]):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] +[ "batsql", "restart", "unsafe pattern batsql.restart(sname:bat[:str], sequence:bat[:str], start:lng):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] +[ "batsql", "restart", "unsafe pattern batsql.restart(sname:bat[:str], sequence:str, start:bat[:lng]):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] +[ "batsql", "restart", "unsafe pattern batsql.restart(sname:bat[:str], sequence:str, start:lng):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] +[ "batsql", "restart", "unsafe pattern batsql.restart(sname:str, sequence:bat[:str], start:bat[:lng]):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] +[ "batsql", "restart", "unsafe pattern batsql.restart(sname:str, sequence:bat[:str], start:lng):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] +[ "batsql", "restart", "unsafe pattern batsql.restart(sname:str, sequence:str, start:bat[:lng]):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] [ "batsql", "round", "command batsql.round(v:bat[:bte], d:int, s:int, r:bte):bat[:bte] ", "bte_bat_round_wrap;", "round off the decimal v(d,s) to r digits behind the dot (if r < 0, before the dot)" ] [ "batsql", "round", "command batsql.round(v:bat[:dbl], r:bte):bat[:dbl] ", "dbl_bat_round_wrap;", "round off the floating point v to r digits behind the dot (if r < 0, before the dot)" ] [ "batsql", "round", "command batsql.round(v:bat[:flt], r:bte):bat[:flt] ", "flt_bat_round_wrap;", "round off the floating point v to r digits behind the dot (if r < 0, before the dot)" ] diff --git a/clients/Tests/MAL-signatures.stable.out.int128 b/clients/Tests/MAL-signatures.stable.out.int128 --- a/clients/Tests/MAL-signatures.stable.out.int128 +++ b/clients/Tests/MAL-signatures.stable.out.int128 @@ -12737,6 +12737,13 @@ stdout of test 'MAL-signatures` in direc [ "batsql", "prod", "pattern batsql.prod(b:bat[:sht], s:bat[:lng], e:bat[:lng]):bat[:hge] ", "SQLprod;", "return the product of groups" ] [ "batsql", "prod", "pattern batsql.prod(b:bat[:sht], s:bat[:lng], e:bat[:lng]):bat[:lng] ", "SQLprod;", "return the product of groups" ] [ "batsql", "rank", "pattern batsql.rank(b:bat[:any_1], p:any_2, o:any_3):bat[:int] ", "SQLrank;", "return the ranked groups" ] +[ "batsql", "restart", "unsafe pattern batsql.restart(sname:bat[:str], sequence:bat[:str], start:bat[:lng]):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] +[ "batsql", "restart", "unsafe pattern batsql.restart(sname:bat[:str], sequence:bat[:str], start:lng):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] +[ "batsql", "restart", "unsafe pattern batsql.restart(sname:bat[:str], sequence:str, start:bat[:lng]):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] +[ "batsql", "restart", "unsafe pattern batsql.restart(sname:bat[:str], sequence:str, start:lng):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] +[ "batsql", "restart", "unsafe pattern batsql.restart(sname:str, sequence:bat[:str], start:bat[:lng]):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] +[ "batsql", "restart", "unsafe pattern batsql.restart(sname:str, sequence:bat[:str], start:lng):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] +[ "batsql", "restart", "unsafe pattern batsql.restart(sname:str, sequence:str, start:bat[:lng]):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] [ "batsql", "round", "command batsql.round(v:bat[:bte], d:int, s:int, r:bte):bat[:bte] ", "bte_bat_round_wrap;", "round off the decimal v(d,s) to r digits behind the dot (if r < 0, before the dot)" ] [ "batsql", "round", "command batsql.round(v:bat[:dbl], r:bte):bat[:dbl] ", "dbl_bat_round_wrap;", "round off the floating point v to r digits behind the dot (if r < 0, before the dot)" ] [ "batsql", "round", "command batsql.round(v:bat[:flt], r:bte):bat[:flt] ", "flt_bat_round_wrap;", "round off the floating point v to r digits behind the dot (if r < 0, before the dot)" ] 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 @@ -5001,7 +5001,7 @@ check_for_foreign_key_references(mvc *sq int found; struct tablelist* new_node, *node_check; - if(*error) + if (*error) return; if (t->keys.set) { /* Check for foreign key references */ @@ -5028,14 +5028,14 @@ check_for_foreign_key_references(mvc *sq *error = 1; return; } - } else if(k->t != t) { + } else if (k->t != t) { found = 0; for (node_check = list; node_check; node_check = node_check->next) { - if(node_check->table == k->t) + if (node_check->table == k->t) found = 1; } - if(!found) { - if((new_node = MNEW(struct tablelist)) == NULL) { + if (!found) { + if ((new_node = MNEW(struct tablelist)) == NULL) { sql_error(sql, 02, SQLSTATE(HY001) MAL_MALLOC_FAIL); *error = 1; return; @@ -5071,7 +5071,7 @@ sql_truncate(backend *be, sql_table *t, int error = 0; struct tablelist* new_list = MNEW(struct tablelist), *list_node, *aux; - if(!new_list) { + if (!new_list) { sql_error(sql, 02, SQLSTATE(HY001) MAL_MALLOC_FAIL); error = 1; goto finalize; @@ -5080,19 +5080,19 @@ sql_truncate(backend *be, sql_table *t, new_list->table = t; new_list->next = NULL; check_for_foreign_key_references(sql, new_list, new_list, t, cascade, &error); - if(error) + if (error) goto finalize; for (list_node = new_list; list_node; list_node = list_node->next) { next = list_node->table; sche = next->s; - if(restart_sequences) { /* restart the sequences if it's the case */ + if (restart_sequences) { /* restart the sequences if it's the case */ for (n = next->columns.set->h; n; n = n->next) { col = n->data; if (col->def && (seq_pos = strstr(col->def, next_value_for))) { seq_name = _STRDUP(seq_pos + (strlen(next_value_for) - strlen("seq_"))); - if(!seq_name) { + if (!seq_name) { sql_error(sql, 02, SQLSTATE(HY001) MAL_MALLOC_FAIL); error = 1; goto finalize; @@ -5100,7 +5100,11 @@ sql_truncate(backend *be, sql_table *t, seq_name[strlen(seq_name)-1] = '\0'; seq = find_sql_sequence(sche, seq_name); if (seq) { - sql_trans_sequence_restart(tr, seq, seq->start); + if (!sql_trans_sequence_restart(tr, seq, seq->start)) { + sql_error(sql, 02, SQLSTATE(HY005) "Could not restart sequence %s.%s", sche->base.name, seq_name); + error = 1; + goto finalize; + } seq->base.wtime = sche->base.wtime = tr->wtime = tr->wstime; tr->schema_updates++; } @@ -5112,8 +5116,8 @@ sql_truncate(backend *be, sql_table *t, v = stmt_tid(be, next, 0); /* before */ - if(be->cur_append && !be->first_statement_generated) { - for(sql_table *up = t->p ; up ; up = up->p) { + if (be->cur_append && !be->first_statement_generated) { + for (sql_table *up = t->p ; up ; up = up->p) { if (!sql_delete_triggers(be, up, v, 0, 3, 4)) { sql_error(sql, 02, SQLSTATE(27000) "TRUNCATE: triggers failed for table '%s'", up->base.name); error = 1; @@ -5135,12 +5139,12 @@ sql_truncate(backend *be, sql_table *t, other = stmt_table_clear(be, next); list_append(l, other); - if(next == t) + if (next == t) ret = other; /* after */ - if(be->cur_append && !be->first_statement_generated) { - for(sql_table *up = t->p ; up ; up = up->p) { + if (be->cur_append && !be->first_statement_generated) { + for (sql_table *up = t->p ; up ; up = up->p) { if (!sql_delete_triggers(be, up, v, 1, 3, 4)) { sql_error(sql, 02, SQLSTATE(27000) "TRUNCATE: triggers failed for table '%s'", up->base.name); error = 1; @@ -5154,7 +5158,7 @@ sql_truncate(backend *be, sql_table *t, goto finalize; } - if(be->cur_append) //building the total number of rows affected across all tables + if (be->cur_append) //building the total number of rows affected across all tables other->nr = add_to_merge_partitions_accumulator(be, other->nr); } @@ -5165,7 +5169,7 @@ finalize: list_node = aux; } - if(error) + if (error) return NULL; return ret; } 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 @@ -958,8 +958,148 @@ mvc_restart_seq(Client cntxt, MalBlkPtr throw(SQL, "sql.restart", SQLSTATE(HY050) "Failed to fetch sequence %s.%s", sname, seqname); if (is_lng_nil(start)) throw(SQL, "sql.restart", SQLSTATE(HY050) "Cannot (re)start sequence %s.%s with NULL", sname, seqname); - *res = sql_trans_sequence_restart(m->session->tr, seq, start); - return MAL_SUCCEED; + if (seq->minvalue && start < seq->minvalue) + throw(SQL, "sql.restart", SQLSTATE(HY050) "Cannot set sequence %s.%s start to a value lesser than the minimum ("LLFMT" < "LLFMT")", sname, seqname, start, seq->minvalue); + if (seq->maxvalue && start > seq->maxvalue) + throw(SQL, "sql.restart", SQLSTATE(HY050) "Cannot set sequence %s.%s start to a value higher than the maximum ("LLFMT" > "LLFMT")", sname, seqname, start, seq->maxvalue); + if (sql_trans_sequence_restart(m->session->tr, seq, start)) { + *res = start; + return MAL_SUCCEED; + } + throw(SQL, "sql.restart", SQLSTATE(HY050) "Cannot (re)start sequence %s.%s", sname, seqname); +} + +str +mvc_bat_restart_seq(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) +{ + mvc *m = NULL; + str msg = MAL_SUCCEED, sname = NULL, seqname = NULL; + BAT *b = NULL, *c = NULL, *d = NULL, *r = NULL, *it; + BUN p, q; + sql_schema *s = NULL; + sql_sequence *seq = NULL; + seqbulk *sb = NULL; + BATiter bi, ci; + bat *res = getArgReference_bat(stk, pci, 0); + bat schid = 0, seqid = 0, startid = 0; + lng start = 0, *di = NULL; + + if (isaBatType(getArgType(mb, pci, 1))) + schid = *getArgReference_bat(stk, pci, 1); + else + sname = *getArgReference_str(stk, pci, 1); + if (isaBatType(getArgType(mb, pci, 2))) + seqid = *getArgReference_bat(stk, pci, 2); + else + seqname = *getArgReference_str(stk, pci, 2); + if (isaBatType(getArgType(mb, pci, 3))) + startid = *getArgReference_bat(stk, pci, 3); + else + start = *getArgReference_lng(stk, pci, 3); + + if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL) + return msg; + if ((msg = checkSQLContext(cntxt)) != NULL) + return msg; + + if (schid && !(b = BATdescriptor(schid))) { + msg = createException(SQL, "sql.restart", SQLSTATE(HY005) "Cannot access column descriptor"); + goto bailout; + } + if (seqid && !(c = BATdescriptor(seqid))) { + msg = createException(SQL, "sql.restart", SQLSTATE(HY005) "Cannot access column descriptor"); + goto bailout; + } + if (startid && !(d = BATdescriptor(startid))) { + msg = createException(SQL, "sql.restart", SQLSTATE(HY005) "Cannot access column descriptor"); + goto bailout; + } + assert(b || c || d); + it = b ? b : c ? c : d; /* Either b, c or d must be set */ + + if (!(r = COLnew(it->hseqbase, TYPE_lng, BATcount(it), TRANSIENT))) { + msg = createException(SQL, "sql.restart", SQLSTATE(HY001) MAL_MALLOC_FAIL); + goto bailout; + } + + if (!BATcount(it)) + goto bailout; /* Success case */ + + if (b) + bi = bat_iterator(b); + if (c) + ci = bat_iterator(c); + if (d) + di = (lng *) Tloc(d, 0); + + BATloop(it, p, q) { + str nsname, nseqname; + lng nstart; + + if (b) + nsname = BUNtvar(bi, p); + else + nsname = sname; + if (c) + nseqname = BUNtvar(ci, p); + else + nseqname = seqname; + if (di) + nstart = di[p]; + else + nstart = start; + + if (!s || strcmp(s->base.name, nsname) != 0 || !seq || strcmp(seq->base.name, nseqname) != 0) { + if (sb) { + seqbulk_destroy(sb); + sb = NULL; + } + seq = NULL; + if ((!s || strcmp(s->base.name, nsname) != 0) && !(s = mvc_bind_schema(m, nsname))) { + msg = createException(SQL, "sql.restart", SQLSTATE(3F000) "Cannot find the schema %s", nsname); + goto bailout; + } + if (!(seq = find_sql_sequence(s, nseqname)) || !(sb = seqbulk_create(seq, BATcount(it)))) { + msg = createException(SQL, "sql.restart", SQLSTATE(HY050) "Cannot find the sequence %s.%s", nsname, nseqname); + goto bailout; + } + } + if (is_lng_nil(nstart)) { + msg = createException(SQL, "sql.restart", SQLSTATE(HY050) "Cannot (re)start sequence %s.%s with NULL", sname, seqname); + goto bailout; + } + if (seq->minvalue && nstart < seq->minvalue) { + msg = createException(SQL, "sql.restart", SQLSTATE(HY050) "Cannot set sequence %s.%s start to a value lesser than the minimum ("LLFMT" < "LLFMT")", sname, seqname, start, seq->minvalue); + goto bailout; + } + if (seq->maxvalue && nstart > seq->maxvalue) { + msg = createException(SQL, "sql.restart", SQLSTATE(HY050) "Cannot set sequence %s.%s start to a value higher than the maximum ("LLFMT" > "LLFMT")", sname, seqname, start, seq->maxvalue); + goto bailout; + } + if (!sql_trans_seqbulk_restart(m->session->tr, sb, nstart)) { + msg = createException(SQL, "sql.restart", SQLSTATE(HY050) "Cannot restart sequence %s.%s", nsname, nseqname); + goto bailout; + } + if (BUNappend(r, &nstart, false) != GDK_SUCCEED) { + msg = createException(SQL, "sql.restart", SQLSTATE(HY001) MAL_MALLOC_FAIL); + goto bailout; + } + } + +bailout: + if (sb) + seqbulk_destroy(sb); + if (b) + BBPunfix(b->batCacheid); + if (c) + BBPunfix(c->batCacheid); + if (d) _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list