Changeset: 885491efa3d2 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/885491efa3d2 Modified Files: clients/Tests/MAL-signatures.stable.out clients/Tests/MAL-signatures.stable.out.int128 sql/backends/monet5/sql.c sql/backends/monet5/sql.h sql/storage/sql_storage.h sql/storage/store.c sql/storage/store_sequence.c sql/storage/store_sequence.h Branch: sequences_7184 Log Message:
cleanup of too complex seqbulk_* interface added simplified single seqbulk operator. diffs (truncated from 705 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 @@ -6347,9 +6347,6 @@ [ "batsql", "diff", "pattern batsql.diff(X_0:bat[:bit], X_1:bat[:any_1]):bat[:bit] ", "SQLdiff;", "return true if cur != prev row" ] [ "batsql", "diff", "pattern batsql.diff(X_0:bit, X_1:bat[:any_1]):bat[:bit] ", "SQLdiff;", "return true if cur != prev row" ] [ "batsql", "first_value", "pattern batsql.first_value(X_0:bat[:any_1], X_1:any, X_2:any, X_3:int, X_4:any, X_5:any):bat[:any_1] ", "SQLfirst_value;", "return the first value of groups" ] -[ "batsql", "get_value", "pattern batsql.get_value(X_0:bat[:str], X_1:bat[:str]):bat[:lng] ", "mvc_bat_get_value;", "return the current value of sequences" ] -[ "batsql", "get_value", "pattern batsql.get_value(X_0:bat[:str], X_1:str):bat[:lng] ", "mvc_bat_get_value;", "return the current value of the sequence" ] -[ "batsql", "get_value", "pattern batsql.get_value(X_0:str, X_1:bat[:str]):bat[:lng] ", "mvc_bat_get_value;", "return the current value of sequences" ] [ "batsql", "index", "command batsql.index(X_0:bat[:str], X_1:bit):bat[:bte] ", "BATSTRindex_bte;", "Return the offsets as an index bat" ] [ "batsql", "index", "command batsql.index(X_0:bat[:str], X_1:bit):bat[:int] ", "BATSTRindex_int;", "Return the offsets as an index bat" ] [ "batsql", "index", "command batsql.index(X_0:bat[:str], X_1:bit):bat[:sht] ", "BATSTRindex_sht;", "Return the offsets as an index bat" ] @@ -6378,9 +6375,7 @@ [ "batsql", "lead", "pattern batsql.lead(X_0:bat[:any_1], X_1:bat[:any], X_2:bat[:any_1], X_3:any_2, X_4:any_3):bat[:any_1] ", "SQLlead;", "return the value in the next 'l' row in the partition or 'd' if non existent" ] [ "batsql", "max", "pattern batsql.max(X_0:bat[:any_1], X_1:any, X_2:any, X_3:int, X_4:any, X_5:any):bat[:any_1] ", "SQLmax;", "return the maximum of groups" ] [ "batsql", "min", "pattern batsql.min(X_0:bat[:any_1], X_1:any, X_2:any, X_3:int, X_4:any, X_5:any):bat[:any_1] ", "SQLmin;", "return the minimum of groups" ] -[ "batsql", "next_value", "pattern batsql.next_value(X_0:bat[:str], X_1:bat[:str]):bat[:lng] ", "mvc_bat_next_value;", "return the next value of sequences" ] -[ "batsql", "next_value", "pattern batsql.next_value(X_0:bat[:str], X_1:str):bat[:lng] ", "mvc_bat_next_value;", "return the next value of the sequence" ] -[ "batsql", "next_value", "pattern batsql.next_value(X_0:str, X_1:bat[:str]):bat[:lng] ", "mvc_bat_next_value;", "return the next value of sequences" ] +[ "batsql", "next_value", "pattern batsql.next_value(X_0:lng, X_1:str, X_2:str):bat[:lng] ", "mvc_next_value_bulk;", "return the next value of the sequence" [ "batsql", "nth_value", "pattern batsql.nth_value(X_0:any_1, X_1:bat[:lng], X_2:any, X_3:any, X_4:int, X_5:any, X_6:any):bat[:any_1] ", "SQLnth_value;", "return the nth value of each group" ] [ "batsql", "nth_value", "pattern batsql.nth_value(X_0:bat[:any_1], X_1:bat[:lng], X_2:any, X_3:any, X_4:int, X_5:any, X_6:any):bat[:any_1] ", "SQLnth_value;", "return the nth value of each group" ] [ "batsql", "nth_value", "pattern batsql.nth_value(X_0:bat[:any_1], X_1:lng, X_2:any, X_3:any, X_4:int, X_5:any, X_6:any):bat[:any_1] ", "SQLnth_value;", "return the nth value of each group" ] @@ -6397,13 +6392,6 @@ [ "batsql", "prod", "pattern batsql.prod(X_0:bat[:lng], X_1:any, X_2:any, X_3:int, X_4:any, X_5:any):bat[:lng] ", "SQLprod;", "return the product of groups" ] [ "batsql", "prod", "pattern batsql.prod(X_0:bat[:sht], X_1:any, X_2:any, X_3:int, X_4:any, X_5:any):bat[:lng] ", "SQLprod;", "return the product of groups" ] [ "batsql", "rank", "pattern batsql.rank(X_0:bat[:any_1], X_1:any_2, X_2:any_3):bat[:int] ", "SQLrank;", "return the ranked groups" ] -[ "batsql", "restart", "unsafe pattern batsql.restart(X_0:bat[:str], X_1:bat[:str], X_2:bat[:lng]):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] -[ "batsql", "restart", "unsafe pattern batsql.restart(X_0:bat[:str], X_1:bat[:str], X_2:lng):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] -[ "batsql", "restart", "unsafe pattern batsql.restart(X_0:bat[:str], X_1:str, X_2:bat[:lng]):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] -[ "batsql", "restart", "unsafe pattern batsql.restart(X_0:bat[:str], X_1:str, X_2:lng):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] -[ "batsql", "restart", "unsafe pattern batsql.restart(X_0:str, X_1:bat[:str], X_2:bat[:lng]):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] -[ "batsql", "restart", "unsafe pattern batsql.restart(X_0:str, X_1:bat[:str], X_2:lng):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] -[ "batsql", "restart", "unsafe pattern batsql.restart(X_0:str, X_1:str, X_2:bat[:lng]):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] [ "batsql", "row_number", "pattern batsql.row_number(X_0:bat[:any_1], X_1:any_2, X_2:any_3):bat[:int] ", "SQLrow_number;", "return the row_numer-ed groups" ] [ "batsql", "stdev", "pattern batsql.stdev(X_0:bat[:bte], X_1:any, X_2:any, X_3:int, X_4:any, X_5:any):bat[:dbl] ", "SQLstddev_samp;", "return the standard deviation sample of groups" ] [ "batsql", "stdev", "pattern batsql.stdev(X_0:bat[:dbl], X_1:any, X_2:any, X_3:int, X_4:any, X_5:any):bat[:dbl] ", "SQLstddev_samp;", "return the standard deviation sample of groups" ] 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 @@ -8888,9 +8888,6 @@ [ "batsql", "diff", "pattern batsql.diff(X_0:bat[:bit], X_1:bat[:any_1]):bat[:bit] ", "SQLdiff;", "return true if cur != prev row" ] [ "batsql", "diff", "pattern batsql.diff(X_0:bit, X_1:bat[:any_1]):bat[:bit] ", "SQLdiff;", "return true if cur != prev row" ] [ "batsql", "first_value", "pattern batsql.first_value(X_0:bat[:any_1], X_1:any, X_2:any, X_3:int, X_4:any, X_5:any):bat[:any_1] ", "SQLfirst_value;", "return the first value of groups" ] -[ "batsql", "get_value", "pattern batsql.get_value(X_0:bat[:str], X_1:bat[:str]):bat[:lng] ", "mvc_bat_get_value;", "return the current value of sequences" ] -[ "batsql", "get_value", "pattern batsql.get_value(X_0:bat[:str], X_1:str):bat[:lng] ", "mvc_bat_get_value;", "return the current value of the sequence" ] -[ "batsql", "get_value", "pattern batsql.get_value(X_0:str, X_1:bat[:str]):bat[:lng] ", "mvc_bat_get_value;", "return the current value of sequences" ] [ "batsql", "index", "command batsql.index(X_0:bat[:str], X_1:bit):bat[:bte] ", "BATSTRindex_bte;", "Return the offsets as an index bat" ] [ "batsql", "index", "command batsql.index(X_0:bat[:str], X_1:bit):bat[:int] ", "BATSTRindex_int;", "Return the offsets as an index bat" ] [ "batsql", "index", "command batsql.index(X_0:bat[:str], X_1:bit):bat[:sht] ", "BATSTRindex_sht;", "Return the offsets as an index bat" ] @@ -8919,9 +8916,7 @@ [ "batsql", "lead", "pattern batsql.lead(X_0:bat[:any_1], X_1:bat[:any], X_2:bat[:any_1], X_3:any_2, X_4:any_3):bat[:any_1] ", "SQLlead;", "return the value in the next 'l' row in the partition or 'd' if non existent" ] [ "batsql", "max", "pattern batsql.max(X_0:bat[:any_1], X_1:any, X_2:any, X_3:int, X_4:any, X_5:any):bat[:any_1] ", "SQLmax;", "return the maximum of groups" ] [ "batsql", "min", "pattern batsql.min(X_0:bat[:any_1], X_1:any, X_2:any, X_3:int, X_4:any, X_5:any):bat[:any_1] ", "SQLmin;", "return the minimum of groups" ] -[ "batsql", "next_value", "pattern batsql.next_value(X_0:bat[:str], X_1:bat[:str]):bat[:lng] ", "mvc_bat_next_value;", "return the next value of sequences" ] -[ "batsql", "next_value", "pattern batsql.next_value(X_0:bat[:str], X_1:str):bat[:lng] ", "mvc_bat_next_value;", "return the next value of the sequence" ] -[ "batsql", "next_value", "pattern batsql.next_value(X_0:str, X_1:bat[:str]):bat[:lng] ", "mvc_bat_next_value;", "return the next value of sequences" ] +[ "batsql", "next_value", "pattern batsql.next_value(X_0:lng, X_1:str, X_2:str):bat[:lng] ", "mvc_next_value_bulk;", "return the next value of the sequence" [ "batsql", "nth_value", "pattern batsql.nth_value(X_0:any_1, X_1:bat[:lng], X_2:any, X_3:any, X_4:int, X_5:any, X_6:any):bat[:any_1] ", "SQLnth_value;", "return the nth value of each group" ] [ "batsql", "nth_value", "pattern batsql.nth_value(X_0:bat[:any_1], X_1:bat[:lng], X_2:any, X_3:any, X_4:int, X_5:any, X_6:any):bat[:any_1] ", "SQLnth_value;", "return the nth value of each group" ] [ "batsql", "nth_value", "pattern batsql.nth_value(X_0:bat[:any_1], X_1:lng, X_2:any, X_3:any, X_4:int, X_5:any, X_6:any):bat[:any_1] ", "SQLnth_value;", "return the nth value of each group" ] @@ -8943,13 +8938,6 @@ [ "batsql", "prod", "pattern batsql.prod(X_0:bat[:sht], X_1:any, X_2:any, X_3:int, X_4:any, X_5:any):bat[:hge] ", "SQLprod;", "return the product of groups" ] [ "batsql", "prod", "pattern batsql.prod(X_0:bat[:sht], X_1:any, X_2:any, X_3:int, X_4:any, X_5:any):bat[:lng] ", "SQLprod;", "return the product of groups" ] [ "batsql", "rank", "pattern batsql.rank(X_0:bat[:any_1], X_1:any_2, X_2:any_3):bat[:int] ", "SQLrank;", "return the ranked groups" ] -[ "batsql", "restart", "unsafe pattern batsql.restart(X_0:bat[:str], X_1:bat[:str], X_2:bat[:lng]):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] -[ "batsql", "restart", "unsafe pattern batsql.restart(X_0:bat[:str], X_1:bat[:str], X_2:lng):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] -[ "batsql", "restart", "unsafe pattern batsql.restart(X_0:bat[:str], X_1:str, X_2:bat[:lng]):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] -[ "batsql", "restart", "unsafe pattern batsql.restart(X_0:bat[:str], X_1:str, X_2:lng):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] -[ "batsql", "restart", "unsafe pattern batsql.restart(X_0:str, X_1:bat[:str], X_2:bat[:lng]):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] -[ "batsql", "restart", "unsafe pattern batsql.restart(X_0:str, X_1:bat[:str], X_2:lng):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] -[ "batsql", "restart", "unsafe pattern batsql.restart(X_0:str, X_1:str, X_2:bat[:lng]):bat[:lng] ", "mvc_bat_restart_seq;", "restart the sequence with value start" ] [ "batsql", "row_number", "pattern batsql.row_number(X_0:bat[:any_1], X_1:any_2, X_2:any_3):bat[:int] ", "SQLrow_number;", "return the row_numer-ed groups" ] [ "batsql", "stdev", "pattern batsql.stdev(X_0:bat[:bte], X_1:any, X_2:any, X_3:int, X_4:any, X_5:any):bat[:dbl] ", "SQLstddev_samp;", "return the standard deviation sample of groups" ] [ "batsql", "stdev", "pattern batsql.stdev(X_0:bat[:dbl], X_1:any, X_2:any, X_3:int, X_4:any, X_5:any):bat[:dbl] ", "SQLstddev_samp;", "return the standard deviation sample of groups" ] 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 @@ -924,6 +924,57 @@ mvc_next_value(Client cntxt, MalBlkPtr m throw(SQL, "sql.next_value", SQLSTATE(HY050) "Cannot generate next sequence value %s.%s", sname, seqname); } +str +mvc_next_value_bulk(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) +{ + backend *be = NULL; + str msg; + sql_schema *s; + sql_sequence *seq; + bat *res = getArgReference_bat(stk, pci, 0); + BUN card = *(BUN*)getArgReference_lng(stk, pci, 1); + const char *sname = *getArgReference_str(stk, pci, 2); + const char *seqname = *getArgReference_str(stk, pci, 3); + BAT *r = NULL; + + (void)mb; + if ((msg = getBackendContext(cntxt, &be)) != NULL) + return msg; + if (!(s = mvc_bind_schema(be->mvc, sname))) + throw(SQL, "sql.next_value", SQLSTATE(3F000) "Cannot find the schema %s", sname); + if (!mvc_schema_privs(be->mvc, s)) + throw(SQL, "sql.next_value", SQLSTATE(42000) "Access denied for %s to schema '%s'", get_string_global_var(be->mvc, "current_user"), s->base.name); + if (!(seq = find_sql_sequence(be->mvc->session->tr, s, seqname))) + throw(SQL, "sql.next_value", SQLSTATE(HY050) "Cannot find the sequence %s.%s", sname, seqname); + if (!(r = COLnew(0, TYPE_lng, card, TRANSIENT))) + throw(SQL, "sql.next_value", SQLSTATE(HY013) MAL_MALLOC_FAIL); + + lng start, inc, minv, maxv, end; + + if (seqbulk_next_value(be->mvc->session->tr->store, seq, card, &start, &inc, &minv, &maxv, &end)) { + be->last_id = end; + sqlvar_set_number(find_global_var(be->mvc, mvc_bind_schema(be->mvc, "sys"), "last_id"), be->last_id); + lng c = start; + for(BUN i = 0; i<card; i++) { + if (c > maxv && minv && maxv) + c = minv; + if (c > maxv && !minv) + break; + if (BUNappend(r, &c, false) != GDK_SUCCEED) { + BBPreclaim(r); + throw(SQL, "sql.next_value", SQLSTATE(HY013) MAL_MALLOC_FAIL); + } + if ((i+1) < card) + c += inc; + } + (void)end; + assert(c == end); + BBPkeepref( *res = r->batCacheid ); + return MAL_SUCCEED; + } + throw(SQL, "sql.next_value", SQLSTATE(HY050) "Cannot generate next sequence value %s.%s", sname, seqname); +} + /* str mvc_get_value(lng *res, str *sname, str *seqname); */ str mvc_get_value(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) @@ -947,131 +998,10 @@ mvc_get_value(Client cntxt, MalBlkPtr mb if (seq_get_value(m->session->tr->store, seq, res)) return MAL_SUCCEED; + throw(SQL, "sql.get_value", SQLSTATE(HY050) "Cannot get sequence value %s.%s", sname, seqname); } -static str -mvc_bat_next_get_value(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, int (*bulk_func)(seqbulk *, lng *), const char *call, const char *action) -{ - mvc *m = NULL; - str msg = MAL_SUCCEED, sname = NULL, seqname = NULL; - BAT *b = NULL, *c = NULL, *r = NULL, *it; - BUN p, q; - sql_schema *s = NULL; - sql_sequence *seq = NULL; - seqbulk *sb = NULL; - BATiter bi = (BATiter) { .b = NULL }, ci = (BATiter) { .b = NULL }; - bat *res = getArgReference_bat(stk, pci, 0); - bat schid = 0, seqid = 0; - - 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 ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL) - return msg; - if ((msg = checkSQLContext(cntxt)) != NULL) - return msg; - sqlstore *store = m->session->tr->store; - - if (schid && !(b = BATdescriptor(schid))) { - msg = createException(SQL, call, SQLSTATE(HY005) "Cannot access column descriptor"); - goto bailout; - } - if (seqid && !(c = BATdescriptor(seqid))) { - msg = createException(SQL, call, SQLSTATE(HY005) "Cannot access column descriptor"); - goto bailout; - } - assert(b || c); - it = b ? b : c; /* Either b or c must be set */ - - if (!(r = COLnew(it->hseqbase, TYPE_lng, BATcount(it), TRANSIENT))) { - msg = createException(SQL, call, SQLSTATE(HY013) MAL_MALLOC_FAIL); - goto bailout; - } - - if (!BATcount(it)) - goto bailout; /* Success case */ - - bi = bat_iterator(b); - ci = bat_iterator(c); - - BATloop(it, p, q) { - str nsname, nseqname; - lng l; - - if (b) - nsname = BUNtvar(bi, p); - else - nsname = sname; - if (c) - nseqname = BUNtvar(ci, p); - else - nseqname = seqname; - - if (!s || strcmp(s->base.name, nsname) != 0 || !seq || strcmp(seq->base.name, nseqname) != 0) { - if (sb) { - seqbulk_destroy(store, sb); - sb = NULL; - } - seq = NULL; - if ((!s || strcmp(s->base.name, nsname) != 0) && !(s = mvc_bind_schema(m, nsname))) { - msg = createException(SQL, call, SQLSTATE(3F000) "Cannot find the schema %s", nsname); - goto bailout1; - } - if (bulk_func == seqbulk_next_value && !mvc_schema_privs(m, s)) { - msg = createException(SQL, call, SQLSTATE(42000) "Access denied for %s to schema '%s'", get_string_global_var(m, "current_user"), s->base.name); - goto bailout1; - } - if (!(seq = find_sql_sequence(m->session->tr, s, nseqname)) || !(sb = seqbulk_create(store, seq, BATcount(it)))) { - msg = createException(SQL, call, SQLSTATE(HY050) "Cannot find the sequence %s.%s", nsname, nseqname); - goto bailout1; - } - } - if (!bulk_func(sb, &l)) { - msg = createException(SQL, call, SQLSTATE(HY050) "Cannot %s sequence value %s.%s", action, nsname, nseqname); - goto bailout1; - } - if (BUNappend(r, &l, false) != GDK_SUCCEED) { - msg = createException(SQL, call, SQLSTATE(HY013) MAL_MALLOC_FAIL); - goto bailout1; - } - } -bailout1: - bat_iterator_end(&bi); - bat_iterator_end(&ci); - -bailout: - if (sb) - seqbulk_destroy(store, sb); - if (b) - BBPunfix(b->batCacheid); - if (c) - BBPunfix(c->batCacheid); - if (msg) - BBPreclaim(r); - else - BBPkeepref(*res = r->batCacheid); - return msg; -} - -str -mvc_bat_next_value(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) -{ - return mvc_bat_next_get_value(cntxt, mb, stk, pci, seqbulk_next_value, "sql.next_value", "generate next"); -} - -str -mvc_bat_get_value(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) -{ - return mvc_bat_next_get_value(cntxt, mb, stk, pci, seqbulk_get_value, "sql.get_value", "get"); -} - str mvc_getVersion(lng *version, const int *clientid) { @@ -1132,157 +1062,6 @@ mvc_restart_seq(Client cntxt, MalBlkPtr return MAL_SUCCEED; } -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, di; - bat *res = getArgReference_bat(stk, pci, 0); - bat schid = 0, seqid = 0, startid = 0; - lng start = 0, *dptr = 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 _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list