Unverified Commit 21891003 authored by Oran Agra's avatar Oran Agra Committed by GitHub
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.
parent 8ef4f1db
...@@ -2952,8 +2952,10 @@ static void zrangeResultFinalizeClient(zrange_result_handler *handler, ...@@ -2952,8 +2952,10 @@ static void zrangeResultFinalizeClient(zrange_result_handler *handler,
/* Result handler methods for storing the ZRANGESTORE to a zset. */ /* Result handler methods for storing the ZRANGESTORE to a zset. */
static void zrangeResultBeginStore(zrange_result_handler *handler, long length) static void zrangeResultBeginStore(zrange_result_handler *handler, long length)
{ {
UNUSED(length); if (length > (long)server.zset_max_listpack_entries)
handler->dstobj = createZsetListpackObject(); handler->dstobj = createZsetObject();
else
handler->dstobj = createZsetListpackObject();
} }
static void zrangeResultEmitCBufferForStore(zrange_result_handler *handler, static void zrangeResultEmitCBufferForStore(zrange_result_handler *handler,
......
...@@ -2208,7 +2208,7 @@ start_server {tags {"zset"}} { ...@@ -2208,7 +2208,7 @@ start_server {tags {"zset"}} {
assert_match "*syntax*" $err assert_match "*syntax*" $err
} }
test {ZRANGESTORE with zset-max-listpack-entries 0 dst key should use skiplist encoding} { test {ZRANGESTORE with zset-max-listpack-entries 0 #10767 case} {
set original_max [lindex [r config get zset-max-listpack-entries] 1] set original_max [lindex [r config get zset-max-listpack-entries] 1]
r config set zset-max-listpack-entries 0 r config set zset-max-listpack-entries 0
r del z1{t} z2{t} r del z1{t} z2{t}
...@@ -2217,6 +2217,18 @@ start_server {tags {"zset"}} { ...@@ -2217,6 +2217,18 @@ start_server {tags {"zset"}} {
r config set zset-max-listpack-entries $original_max r config set zset-max-listpack-entries $original_max
} }
test {ZRANGESTORE with zset-max-listpack-entries 1 dst key should use skiplist encoding} {
set original_max [lindex [r config get zset-max-listpack-entries] 1]
r config set zset-max-listpack-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 listpack z2{t}
assert_equal 2 [r zrangestore z3{t} z1{t} 0 1]
assert_encoding skiplist z3{t}
r config set zset-max-listpack-entries $original_max
}
test {ZRANGE invalid syntax} { test {ZRANGE invalid syntax} {
catch {r zrange z1{t} 0 -1 limit 1 2} err catch {r zrange z1{t} 0 -1 limit 1 2} err
assert_match "*syntax*" $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