Commit 70aaf500 authored by Oran Agra's avatar Oran Agra
Browse files

optimize zset conversion on large ZRANGESTORE (#10789)

when we know the size of the zset we're gonna store in advance,
we can check if it's greater than the listpack encoding threshold,
in which case we can create a skiplist from the get go, and avoid
converting the listpack to skiplist later after it was already populated.

(cherry picked from commit 21891003)
parent 66472a5e
......@@ -2965,7 +2965,9 @@ static void zrangeResultFinalizeClient(zrange_result_handler *handler,
/* Result handler methods for storing the ZRANGESTORE to a zset. */
static void zrangeResultBeginStore(zrange_result_handler *handler, long length)
{
UNUSED(length);
if (length > (long)server.zset_max_ziplist_entries)
handler->dstobj = createZsetObject();
else
handler->dstobj = createZsetZiplistObject();
}
......
......@@ -1643,7 +1643,7 @@ start_server {tags {"zset"}} {
assert_match "*syntax*" $err
}
test {ZRANGESTORE with zset-max-listpack-entries 0 dst key should use skiplist encoding} {
test {ZRANGESTORE with zset-max-ziplist-entries 0 #10767 case} {
set original_max [lindex [r config get zset-max-ziplist-entries] 1]
r config set zset-max-ziplist-entries 0
r del z1{t} z2{t}
......@@ -1652,6 +1652,18 @@ start_server {tags {"zset"}} {
r config set zset-max-ziplist-entries $original_max
}
test {ZRANGESTORE with zset-max-ziplist-entries 1 dst key should use skiplist encoding} {
set original_max [lindex [r config get zset-max-ziplist-entries] 1]
r config set zset-max-ziplist-entries 1
r del z1{t} z2{t} z3{t}
r zadd z1{t} 1 a 2 b
assert_equal 1 [r zrangestore z2{t} z1{t} 0 0]
assert_encoding ziplist z2{t}
assert_equal 2 [r zrangestore z3{t} z1{t} 0 1]
assert_encoding skiplist z3{t}
r config set zset-max-ziplist-entries $original_max
}
test {ZRANGE invalid syntax} {
catch {r zrange z1 0 -1 limit 1 2} err
assert_match "*syntax*" $err
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment