Changeset: f599ecbbbc59 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/f599ecbbbc59
Modified Files:
sql/storage/store_sequence.c
Branch: Jan2022
Log Message:
Improve store lock contention.
diffs (104 lines):
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
@@ -169,48 +169,75 @@ seqbulk_next_value(sql_store store, sql_
lng min = seq->minvalue;
lng max = seq->maxvalue;
+ lng cur = s->cur;
+ 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);
+ lng old_cached = s->cached;
+ s->cached = calculate_new_cached_value(s->cur,
seq->increment, seq->cacheinc, min, max);
+
+ if (old_cached != s->cached)
+ sql_update_sequence_cache(store, seq,
s->cached);
+ store_unlock(store);
+ store_unlocked = true;
+ }
+ else {
+ store_unlock(store);
+ return 0;
+ }
+ }
for(lng i = start_index; i < cnt; i++) {
- if ((GDK_lng_max - inc < s->cur) || ((s->cur += inc) >
max)) {
- // overflow
- if (seq->cycle) {
- s->cur = min;
- }
- else {
- store_unlock(store);
- return 0;
- }
+ if ((GDK_lng_max - inc < cur) || ((cur += inc) > max)) {
+ // overrflow
+ assert(seq->cycle);
+ cur = min;
}
- dest[i] = s->cur;
+ dest[i] = cur;
}
}
else { // seq->increment < 0
lng inc = -seq->increment; // new value = old value - inc;
+
+ if (start_index < cnt && !seq->cycle && !(min < 0 && s->cur >
0)) {
+ if ((s->cur - min) / (cnt - start_index) >= inc) {
+ s->cur -= inc * (cnt - start_index);
+ lng old_cached = s->cached;
+ s->cached = calculate_new_cached_value(s->cur,
seq->increment, seq->cacheinc, min, max);
+
+ if (old_cached != s->cached)
+ sql_update_sequence_cache(store, seq,
s->cached);
+ store_unlock(store);
+ store_unlocked = true;
+ }
+ else {
+ store_unlock(store);
+ return 0;
+ }
+ }
for(lng i = start_index; i < cnt; i++) {
- if ((-GDK_lng_max + inc > s->cur) || ((s->cur -= inc)
< min)) {
+ if ((-GDK_lng_max + inc > cur) || ((cur -= inc) <
min)) {
// underflow
- if (seq->cycle) {
- s->cur = max;
- }
- else {
- store_unlock(store);
- return 0;
- }
+ assert(seq->cycle);
+ cur = max;
}
- dest[i] = s->cur;
+ dest[i] = cur;
}
}
- lng old_cached = s->cached;
- s->cached = calculate_new_cached_value(s->cur, seq->increment,
seq->cacheinc, min, max);
+ if (!store_unlocked) {
+ s->cur = cur;
+ lng old_cached = s->cached;
+ s->cached = calculate_new_cached_value(s->cur, seq->increment,
seq->cacheinc, min, max);
- if (old_cached != s->cached) {
- sql_update_sequence_cache(store, seq, s->cached);
+ if (old_cached != s->cached)
+ sql_update_sequence_cache(store, seq, s->cached);
+ store_unlock(store);
}
-
- store_unlock(store);
return 1;
}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list