Unverified Commit 39f716a1 authored by thomaston's avatar thomaston Committed by GitHub
Browse files

ZREVRANGEBYSCORE Optimization for out of range offset (#5773)



ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]
When the offset is too large, the query is very slow. Especially when the offset is greater than the length of zset it is easy to determine whether the offset is greater than the length of zset at first, and If it exceed the length of zset, then return directly.
Co-authored-by: default avatarOran Agra <oran@redislabs.com>
parent d638b058
......@@ -2906,6 +2906,12 @@ void genericZrangebyscoreCommand(client *c, int reverse) {
if ((zobj = lookupKeyReadOrReply(c,key,shared.emptyarray)) == NULL ||
checkType(c,zobj,OBJ_ZSET)) return;
/* For invalid offset, return directly. */
if (offset > 0 && offset >= (long)zsetLength(zobj)) {
addReply(c,shared.emptyarray);
return;
}
if (zobj->encoding == OBJ_ENCODING_ZIPLIST) {
unsigned char *zl = zobj->ptr;
unsigned char *eptr, *sptr;
......
......@@ -432,6 +432,7 @@ start_server {tags {"zset"}} {
create_default_zset
assert_equal {e 4 f 5} [r zrangebyscore zset 2 5 LIMIT 2 3 WITHSCORES]
assert_equal {d 3 c 2} [r zrevrangebyscore zset 5 2 LIMIT 2 3 WITHSCORES]
assert_equal {} [r zrangebyscore zset 2 5 LIMIT 12 13 WITHSCORES]
}
test "ZRANGEBYSCORE with non-value min or max" {
......
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