New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ZREVRANGEBYSCORE] When the offset is too large, the query is very slow. #5767

Open
fuxiaotong opened this Issue Jan 11, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@fuxiaotong
Copy link

fuxiaotong commented Jan 11, 2019

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. For this invalid query, I think it should determine whether the offset is greater than the length of zset at first, and If it exceed the length of zset, then return directly.

@itamarhaber

This comment has been minimized.

Copy link
Contributor

itamarhaber commented Jan 11, 2019

Hello @fuxiaotong

This is the expected behavior, see the docs for ZRANGEBYSCORE:

Keep in mind that if offset is large, the sorted set needs to be traversed for offset elements before getting to the elements to return, which can add up to O(N) time complexity.

The edge case, where the offset exceeds the length of the zset, could perhaps be optimized to break early, although it will have little impact overall.

@fuxiaotong

This comment has been minimized.

Copy link

fuxiaotong commented Jan 11, 2019

thanks for your reply @itamarhaber

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment