Changeset: 546979bd7d07 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/546979bd7d07
Modified Files:
clients/Tests/MAL-signatures.stable.out
clients/Tests/MAL-signatures.stable.out.int128
sql/backends/monet5/sql.c
sql/backends/monet5/sql_upgrades.c
sql/scripts/52_describe.sql
sql/storage/store_sequence.c
sql/storage/store_sequence.h
sql/test/BugTracker-2018/Tests/alter-sequence-subquery.Bug-6657.test
sql/test/BugTracker-2018/Tests/negative-sequences.Bug-6665.test
sql/test/BugTracker-2019/Tests/next-get-value-bulk.Bug-6766.test
sql/test/BugTracker-2019/Tests/sequence-first-next-value.Bug-6743.test
sql/test/emptydb-previous-upgrade-chain-hge/Tests/upgrade.stable.out.int128
sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.stable.out.int128
sql/test/emptydb-previous-upgrade-hge/Tests/upgrade.stable.out.int128
sql/test/emptydb-previous-upgrade/Tests/upgrade.stable.out.int128
sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.int128
sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.ppc64.int128
sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out
sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.32bit
sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.int128
sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.ppc64
sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.ppc64.int128
sql/test/emptydb-upgrade-hge/Tests/upgrade.stable.out.int128
sql/test/emptydb-upgrade/Tests/upgrade.stable.out
sql/test/emptydb-upgrade/Tests/upgrade.stable.out.32bit
sql/test/emptydb-upgrade/Tests/upgrade.stable.out.int128
sql/test/emptydb/Tests/check.stable.out
sql/test/emptydb/Tests/check.stable.out.int128
sql/test/sys-schema/Tests/webExamplesMathematicalFunctionsOperators.test
sql/test/testdb-previous-upgrade-chain-hge/Tests/upgrade.stable.out.int128
sql/test/testdb-previous-upgrade-chain/Tests/upgrade.stable.out.int128
sql/test/testdb-previous-upgrade-hge/Tests/upgrade.stable.out.int128
sql/test/testdb-previous-upgrade/Tests/upgrade.stable.out.int128
sql/test/testdb-upgrade-chain-hge/Tests/upgrade.stable.out.int128
sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out
sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out.32bit
sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out.int128
sql/test/testdb-upgrade-hge/Tests/upgrade.stable.out.int128
sql/test/testdb-upgrade/Tests/upgrade.stable.out
sql/test/testdb-upgrade/Tests/upgrade.stable.out.32bit
sql/test/testdb-upgrade/Tests/upgrade.stable.out.int128
Branch: Jan2022
Log Message:
To fix upgrade of sequence numbers we store always the last not used (next)
sequence number is the log, ie lg->seqs_id/val bats.
The store_sequence always computes up until (including) the next value (or nil).
This removes the need for the peak function.
diffs (truncated from 1109 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
@@ -6350,6 +6350,8 @@
[ "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_get_value_bulk;", "return the current
value of the sequence (ie the next to be used value)" ]
+[ "batsql", "get_value", "pattern batsql.get_value(X_0:bat[:str],
X_1:bat[:str], X_2:bat[:oid], X_3:bat[:oid]):bat[:lng] ",
"mvc_get_value_bulk;", "return the current value of the sequence (ie the next
to be used value)"
[ "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" ]
@@ -6386,8 +6388,6 @@
[ "batsql", "ntile", "pattern batsql.ntile(X_0:bat[:any], X_1:any_1,
X_2:any_2, X_3:any_3):bat[:any_1] ", "SQLntile;", "return the groups
divided as equally as possible" ]
[ "batsql", "ntile", "pattern batsql.ntile(X_0:bat[:any],
X_1:bat[:any_1], X_2:any_2, X_3:any_3):bat[:any_1] ", "SQLntile;",
"return the groups divided as equally as possible" ]
[ "batsql", "password", "pattern
batsql.password(X_0:bat[:str]):bat[:str] ", "db_password_wrap;", "Return
password hash of user" ]
-[ "batsql", "peak_next_value", "pattern
batsql.peak_next_value(X_0:bat[:str], X_1:bat[:str]):bat[:lng] ",
"mvc_peak_next_value_bulk;", "Peaks at the next value of the sequence"
]
-[ "batsql", "peak_next_value", "pattern
batsql.peak_next_value(X_0:bat[:str], X_1:bat[:str], X_2:bat[:oid],
X_3:bat[:oid]):bat[:lng] ", "mvc_peak_next_value_bulk;", "Peaks at
the next value of the sequence" ]
[ "batsql", "percent_rank", "pattern batsql.percent_rank(X_0:bat[:any_1],
X_1:any_2, X_2:any_3):bat[:dbl] ", "SQLpercent_rank;", "return the
percentage into the total number of groups for each row" ]
[ "batsql", "prod", "pattern batsql.prod(X_0:bat[:bte], 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[:dbl], X_1:any, X_2:any,
X_3:int, X_4:any, X_5:any):bat[:dbl] ", "SQLprod;", "return the product
of groups" ]
@@ -9361,7 +9361,7 @@
[ "sql", "first_value", "pattern sql.first_value(X_0:any_1, X_1:bit,
X_2:bit, X_3:int, X_4:oid, X_5:oid):any_1 ", "SQLfirst_value;",
"return the first value of groups" ]
[ "sql", "getVariable", "pattern sql.getVariable(X_0:int, X_1:str,
X_2:str):any_1 ", "getVariable;", "Get the value of a session variable" ]
[ "sql", "getVersion", "command sql.getVersion(X_0:int):lng ",
"mvc_getVersion;", "Return the database version identifier for a client."
]
-[ "sql", "get_value", "pattern sql.get_value(X_0:str, X_1:str):lng ",
"mvc_get_value;", "return the current value of the sequence" ]
+[ "sql", "get_value", "pattern sql.get_value(X_0:str, X_1:str):lng ",
"mvc_get_value;", "return the current value of the sequence (ie the next
to be used value)" ]
[ "sql", "grow", "pattern sql.grow(X_0:bat[:oid], X_1:any_1):int ",
"mvc_grow_wrap;", "Resize the tid column of a declared table." ]
[ "sql", "hot_snapshot", "unsafe pattern sql.hot_snapshot(X_0:str):void
", "SQLhot_snapshot;", "Write db snapshot to the given tar(.gz) file"
]
[ "sql", "hot_snapshot", "unsafe pattern sql.hot_snapshot(X_0:str,
X_1:bit):void ", "SQLhot_snapshot_wrap;", "Write db snapshot to the
given tar(.gz/.lz4/.bz/.xz) file on either server or client" ]
@@ -9390,7 +9390,6 @@
[ "sql", "optimizer_updates", "pattern sql.optimizer_updates():void
", "SQLoptimizersUpdate;", "" ]
[ "sql", "optimizers", "command sql.optimizers() (X_0:bat[:str],
X_1:bat[:str], X_2:bat[:str]) ", "getPipeCatalog;", "" ]
[ "sql", "password", "pattern sql.password(X_0:str):str ",
"db_password_wrap;", "Return password hash of user" ]
-[ "sql", "peak_next_value", "pattern sql.peak_next_value(X_0:str,
X_1:str):lng ", "mvc_peak_next_value;", "Peaks at the next value of the
sequence" ]
[ "sql", "percent_rank", "pattern sql.percent_rank(X_0:any_1, X_1:bit,
X_2:bit):dbl ", "SQLpercent_rank;", "return the percentage into the total
number of groups for each row" ]
[ "sql", "prelude", "pattern sql.prelude():void ", "SQLprelude;",
"" ]
[ "sql", "prepared_statements", "pattern sql.prepared_statements()
(X_0:bat[:int], X_1:bat[:str], X_2:bat[:int], X_3:bat[:str],
X_4:bat[:timestamp]) ", "SQLsession_prepared_statements;", "Available
prepared statements in the current session" ]
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
@@ -8891,6 +8891,8 @@
[ "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_get_value_bulk;", "return the current
value of the sequence (ie the next to be used value)" ]
+[ "batsql", "get_value", "pattern batsql.get_value(X_0:bat[:str],
X_1:bat[:str], X_2:bat[:oid], X_3:bat[:oid]):bat[:lng] ",
"mvc_get_value_bulk;", "return the current value of the sequence (ie the next
to be used value)" ]
[ "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" ]
@@ -8927,8 +8929,6 @@
[ "batsql", "ntile", "pattern batsql.ntile(X_0:bat[:any], X_1:any_1,
X_2:any_2, X_3:any_3):bat[:any_1] ", "SQLntile;", "return the groups
divided as equally as possible" ]
[ "batsql", "ntile", "pattern batsql.ntile(X_0:bat[:any],
X_1:bat[:any_1], X_2:any_2, X_3:any_3):bat[:any_1] ", "SQLntile;",
"return the groups divided as equally as possible" ]
[ "batsql", "password", "pattern
batsql.password(X_0:bat[:str]):bat[:str] ", "db_password_wrap;", "Return
password hash of user" ]
-[ "batsql", "peak_next_value", "pattern
batsql.peak_next_value(X_0:bat[:str], X_1:bat[:str]):bat[:lng] ",
"mvc_peak_next_value_bulk;", "Peaks at the next value of the sequence"
]
-[ "batsql", "peak_next_value", "pattern
batsql.peak_next_value(X_0:bat[:str], X_1:bat[:str], X_2:bat[:oid],
X_3:bat[:oid]):bat[:lng] ", "mvc_peak_next_value_bulk;", "Peaks at
the next value of the sequence" ]
[ "batsql", "percent_rank", "pattern batsql.percent_rank(X_0:bat[:any_1],
X_1:any_2, X_2:any_3):bat[:dbl] ", "SQLpercent_rank;", "return the
percentage into the total number of groups for each row" ]
[ "batsql", "prod", "pattern batsql.prod(X_0:bat[:bte], 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[:bte], X_1:any, X_2:any,
X_3:int, X_4:any, X_5:any):bat[:lng] ", "SQLprod;", "return the product
of groups" ]
@@ -12666,7 +12666,7 @@
[ "sql", "first_value", "pattern sql.first_value(X_0:any_1, X_1:bit,
X_2:bit, X_3:int, X_4:oid, X_5:oid):any_1 ", "SQLfirst_value;",
"return the first value of groups" ]
[ "sql", "getVariable", "pattern sql.getVariable(X_0:int, X_1:str,
X_2:str):any_1 ", "getVariable;", "Get the value of a session variable" ]
[ "sql", "getVersion", "command sql.getVersion(X_0:int):lng ",
"mvc_getVersion;", "Return the database version identifier for a client."
]
-[ "sql", "get_value", "pattern sql.get_value(X_0:str, X_1:str):lng ",
"mvc_get_value;", "return the current value of the sequence" ]
+[ "sql", "get_value", "pattern sql.get_value(X_0:str, X_1:str):lng ",
"mvc_get_value;", "return the current value of the sequence (ie the next
to be used value)" ]
[ "sql", "grow", "pattern sql.grow(X_0:bat[:oid], X_1:any_1):int ",
"mvc_grow_wrap;", "Resize the tid column of a declared table." ]
[ "sql", "hot_snapshot", "unsafe pattern sql.hot_snapshot(X_0:str):void
", "SQLhot_snapshot;", "Write db snapshot to the given tar(.gz) file"
]
[ "sql", "hot_snapshot", "unsafe pattern sql.hot_snapshot(X_0:str,
X_1:bit):void ", "SQLhot_snapshot_wrap;", "Write db snapshot to the
given tar(.gz/.lz4/.bz/.xz) file on either server or client" ]
@@ -12695,7 +12695,6 @@
[ "sql", "optimizer_updates", "pattern sql.optimizer_updates():void
", "SQLoptimizersUpdate;", "" ]
[ "sql", "optimizers", "command sql.optimizers() (X_0:bat[:str],
X_1:bat[:str], X_2:bat[:str]) ", "getPipeCatalog;", "" ]
[ "sql", "password", "pattern sql.password(X_0:str):str ",
"db_password_wrap;", "Return password hash of user" ]
-[ "sql", "peak_next_value", "pattern sql.peak_next_value(X_0:str,
X_1:str):lng ", "mvc_peak_next_value;", "Peaks at the next value of the
sequence" ]
[ "sql", "percent_rank", "pattern sql.percent_rank(X_0:any_1, X_1:bit,
X_2:bit):dbl ", "SQLpercent_rank;", "return the percentage into the total
number of groups for each row" ]
[ "sql", "prelude", "pattern sql.prelude():void ", "SQLprelude;",
"" ]
[ "sql", "prepared_statements", "pattern sql.prepared_statements()
(X_0:bat[:int], X_1:bat[:str], X_2:bat[:int], X_3:bat[:str],
X_4:bat[:timestamp]) ", "SQLsession_prepared_statements;", "Available
prepared statements in the current session" ]
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,36 +958,9 @@ mvc_get_value(Client cntxt, MalBlkPtr mb
throw(SQL, "sql.get_value", SQLSTATE(HY050) "Cannot get sequence value
%s.%s", sname, seqname);
}
-/* str mvc_peak_next_value(lng *res, str *sname, str *seqname); */
-str
-mvc_peak_next_value(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
-{
- mvc *m = NULL;
- str msg;
- sql_schema *s;
- sql_sequence *seq;
- lng *res = getArgReference_lng(stk, pci, 0);
- const char *sname = *getArgReference_str(stk, pci, 1);
- const char *seqname = *getArgReference_str(stk, pci, 2);
-
- if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL)
- return msg;
- if ((msg = checkSQLContext(cntxt)) != NULL)
- return msg;
- if (!(s = mvc_bind_schema(m, sname)))
- throw(SQL, "sql.peak_next_value", SQLSTATE(3F000) "Cannot find
the schema %s", sname);
- if (!(seq = find_sql_sequence(m->session->tr, s, seqname)))
- throw(SQL, "sql.peak_next_value", SQLSTATE(HY050) "Cannot find
the sequence %s.%s", sname, seqname);
-
- if (seq_peak_next_value(m->session->tr->store, seq, res))
- return MAL_SUCCEED;
-
- throw(SQL, "sql.peak_next_value", SQLSTATE(HY050) "Cannot peak at next
sequence value %s.%s", sname, seqname);
-}
-
/* needed for msqldump and describe_sequences view */
static str
-mvc_peak_next_value_bulk(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr
pci)
+mvc_get_value_bulk(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
mvc *m = NULL;
sql_schema *s;
@@ -1008,20 +981,20 @@ mvc_peak_next_value_bulk(Client cntxt, M
if ((msg = checkSQLContext(cntxt)) != NULL)
return msg;
if (!(scheb = BATdescriptor(*l)) || !(seqb = BATdescriptor(*r))) {
- msg = createException(SQL, "sql.peak_next_value",
SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
+ msg = createException(SQL, "sql.get_value", SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
goto bailout;
}
if ((sid1 && !is_bat_nil(*sid1) && !(sches = BATdescriptor(*sid1))) ||
(sid2 && !is_bat_nil(*sid2) && !(seqs = BATdescriptor(*sid2)))) {
- msg = createException(SQL, "sql.peak_next_value",
SQLSTATE(HY002) RUNTIME_OBJECT_MISSING);
+ msg = createException(SQL, "sql.get_value", SQLSTATE(HY002)
RUNTIME_OBJECT_MISSING);
goto bailout;
}
q = canditer_init(&ci1, scheb, sches);
if (canditer_init(&ci2, seqb, seqs) != q || ci1.hseq != ci2.hseq) {
- msg = createException(SQL, "sql.peak_next_value",
ILLEGAL_ARGUMENT " Requires bats of identical size");
+ msg = createException(SQL, "sql.get_value", ILLEGAL_ARGUMENT "
Requires bats of identical size");
goto bailout;
}
if (!(bn = COLnew(ci1.hseq, TYPE_lng, q, TRANSIENT))) {
- msg = createException(SQL, "sql.peak_next_value",
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ msg = createException(SQL, "sql.get_value", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
goto bailout;
}
@@ -1040,15 +1013,15 @@ mvc_peak_next_value_bulk(Client cntxt, M
nils = true;
} else {
if (!(s = mvc_bind_schema(m, sname))) {
- msg = createException(SQL,
"sql.peak_next_value", SQLSTATE(3F000) "Cannot find the schema %s", sname);
+ msg = createException(SQL, "sql.get_value",
SQLSTATE(3F000) "Cannot find the schema %s", sname);
goto bailout1;
}
if (!(seq = find_sql_sequence(m->session->tr, s,
seqname))) {
- msg = createException(SQL,
"sql.peak_next_value", SQLSTATE(HY050) "Cannot find the sequence %s.%s", sname,
seqname);
+ msg = createException(SQL, "sql.get_value",
SQLSTATE(HY050) "Cannot find the sequence %s.%s", sname, seqname);
goto bailout1;
}
- if (!seq_peak_next_value(m->session->tr->store, seq,
&(vals[i]))) {
- msg = createException(SQL,
"sql.peak_next_value", SQLSTATE(HY050) "Cannot peak at next sequence value
%s.%s", sname, seqname);
+ if (!seq_get_value(m->session->tr->store, seq,
&(vals[i]))) {
+ msg = createException(SQL, "sql.get_value",
SQLSTATE(HY050) "Cannot get the next sequence value %s.%s", sname, seqname);
goto bailout1;
}
}
@@ -5204,10 +5177,9 @@ static mel_func sql_init_funcs[] = {
pattern("sql", "logfile", mvc_logfile, true, "Enable/disable saving the sql
statement traces", args(1,2, arg("",void),arg("filename",str))),
pattern("sql", "next_value", mvc_next_value, true, "return the next value of
the sequence", args(1,3, arg("",lng),arg("sname",str),arg("sequence",str))),
pattern("batsql", "next_value", mvc_next_value_bulk, true, "return the next
value of the sequence", args(1,4, batarg("",lng),arg("card",lng),
arg("sname",str),arg("sequence",str))),
- pattern("sql", "get_value", mvc_get_value, false, "return the current value
of the sequence", args(1,3, arg("",lng),arg("sname",str),arg("sequence",str))),
- pattern("sql", "peak_next_value", mvc_peak_next_value, false, "Peaks at the
next value of the sequence", args(1,3,
arg("",lng),arg("sname",str),arg("sequence",str))),
- pattern("batsql", "peak_next_value", mvc_peak_next_value_bulk, false, "Peaks
at the next value of the sequence", args(1,3,
batarg("",lng),batarg("sname",str),batarg("sequence",str))),
- pattern("batsql", "peak_next_value", mvc_peak_next_value_bulk, false, "Peaks
at the next value of the sequence", args(1,5,
batarg("",lng),batarg("sname",str),batarg("sequence",str),batarg("s1",oid),batarg("s2",oid))),
+ pattern("sql", "get_value", mvc_get_value, false, "return the current value
of the sequence (ie the next to be used value)", args(1,3,
arg("",lng),arg("sname",str),arg("sequence",str))),
+ pattern("batsql", "get_value", mvc_get_value_bulk, false, "return the current
value of the sequence (ie the next to be used value)", args(1,3,
batarg("",lng),batarg("sname",str),batarg("sequence",str))),
+ pattern("batsql", "get_value", mvc_get_value_bulk, false, "return the current
value of the sequence (ie the next to be used value)", args(1,5,
batarg("",lng),batarg("sname",str),batarg("sequence",str),batarg("s1",oid),batarg("s2",oid))),
pattern("sql", "restart", mvc_restart_seq, true, "restart the sequence with
value start", args(1,4,
arg("",lng),arg("sname",str),arg("sequence",str),arg("start",lng))),
pattern("sql", "deltas", mvc_delta_values, false, "Return the delta values
sizes of all columns of the schema's tables, plus the current transaction
level", args(7,8,
batarg("ids",int),batarg("segments",lng),batarg("all",lng),batarg("inserted",lng),batarg("updated",lng),batarg("deleted",lng),batarg("tr_level",int),arg("schema",str))),
pattern("sql", "deltas", mvc_delta_values, false, "Return the delta values
sizes from the table's columns, plus the current transaction level", args(7,9,
batarg("ids",int),batarg("segments",lng),batarg("all",lng),batarg("inserted",lng),batarg("updated",lng),batarg("deleted",lng),batarg("tr_level",int),arg("schema",str),arg("table",str))),
diff --git a/sql/backends/monet5/sql_upgrades.c
b/sql/backends/monet5/sql_upgrades.c
--- a/sql/backends/monet5/sql_upgrades.c
+++ b/sql/backends/monet5/sql_upgrades.c
@@ -3754,7 +3754,7 @@ sql_update_jan2022(Client c, mvc *sql, c
" s.name sch,\n"
" seq.name seq,\n"
" seq.\"start\" s,\n"
- "
peak_next_value_for(s.name, seq.name) rs,\n"
+ " get_value_for(s.name,
seq.name) rs,\n"
" seq.\"minvalue\" mi,\n"
" seq.\"maxvalue\" ma,\n"
" seq.\"increment\"
inc,\n"
diff --git a/sql/scripts/52_describe.sql b/sql/scripts/52_describe.sql
--- a/sql/scripts/52_describe.sql
+++ b/sql/scripts/52_describe.sql
@@ -491,7 +491,7 @@ CREATE VIEW sys.describe_sequences AS
s.name sch,
seq.name seq,
seq."start" s,
- peak_next_value_for(s.name, seq.name) rs,
+ get_value_for(s.name, seq.name) rs,
seq."minvalue" mi,
seq."maxvalue" ma,
seq."increment" inc,
diff --git a/sql/storage/store_sequence.c b/sql/storage/store_sequence.c
--- a/sql/storage/store_sequence.c
+++ b/sql/storage/store_sequence.c
@@ -27,7 +27,6 @@ sequences_unlock(sql_store Store)
typedef struct store_sequence {
sqlid seqid;
lng cur;
- bool called;
bool intrans;
} store_sequence;
@@ -36,7 +35,7 @@ log_store_sequence(sql_store Store, void
{
sqlstore *store = Store;
store_sequence *seq = s;
- store->logger_api.log_sequence(store, seq->seqid,
(seq->called)?seq->cur:lng_nil);
+ store->logger_api.log_sequence(store, seq->seqid, seq->cur);
seq->intrans = false;
}
@@ -113,11 +112,8 @@ sequence_create(sqlstore *store, sql_seq
.cur = seq->start,
};
- if (!isNew(seq) && store->logger_api.get_sequence(store, seq->base.id,
&val )) {
+ if (!isNew(seq) && store->logger_api.get_sequence(store, seq->base.id,
&val ))
s->cur = val;
- if (val != lng_nil)
- s->called = 1; /* val is last used value */
- }
hash_add(store->sequences, seq_hash(s), s);
return s;
}
@@ -147,7 +143,6 @@ seq_restart(sql_store Store, sql_sequenc
}
}
s->cur = start;
- s->called = 0;
update_sequence(store, s);
sequences_unlock(store);
return 1;
@@ -173,71 +168,61 @@ seqbulk_next_value(sql_store Store, sql_
}
}
- lng start_index = 0;
- bool initial = false;
-
- if (!s->called) {
- s->cur = seq->start;
- *dest = s->cur;
- start_index = 1;
- s->called = 1;
- initial = 1;
- }
-
lng min = seq->minvalue;
lng max = seq->maxvalue;
lng cur = s->cur;
+ if (!seq->cycle) {
+ if ((seq->increment > 0 && s->cur > max) ||
+ (seq->increment < 0 && s->cur < min)) {
+ sequences_unlock(store);
+ return 0;
+ }
+ }
bool store_unlocked = false;
if (seq->increment > 0) {
lng inc = seq->increment; // new value = old value + inc;
- if (start_index < cnt && !seq->cycle && !(max > 0 && s->cur <
0)) {
- if ((max -s->cur) / (cnt - start_index) >= inc) {
- s->cur += inc * (cnt - start_index);
+ if (0 < cnt && !seq->cycle && !(max > 0 && s->cur < 0)) {
+ if ((max - s->cur) >= ((cnt-1) * inc)) {
+ s->cur += inc * cnt;
update_sequence(store, s);
sequences_unlock(store);
store_unlocked = true;
} else {
- if (initial)
- s->called = 0;
sequences_unlock(store);
return 0;
}
}
- for(lng i = start_index; i < cnt; i++) {
+ for(lng i = 0; i < cnt; i++) {
+ dest[i] = cur;
if ((GDK_lng_max - inc < cur) || ((cur += inc) > max)) {
// overflow
- assert(seq->cycle);
- cur = min;
+ cur = (seq->cycle)?min:lng_nil;
}
- dest[i] = cur;
}
} else { // seq->increment < 0
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list