Skip to content
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

Add GetNearest method to the DB interface #79

Open
babadro opened this issue Apr 23, 2023 · 3 comments
Open

Add GetNearest method to the DB interface #79

babadro opened this issue Apr 23, 2023 · 3 comments

Comments

@babadro
Copy link

babadro commented Apr 23, 2023

Summary

There is an issue in cosmos-sdk: Make KVStore interface have methods to getNearest entry.

To address this issue, we can add a new method, GetNearest to the DB interface and implement it for all supported storage engines. This method should have a similar cost to the Get operation and provide a more efficient alternative to iterators for finding the nearest key.

// GetNearest retrieves the nearest key to the given key.
// If 'ascending' is true, the method returns the smallest key greater than the given key.
// If 'ascending' is false, the method returns the largest key smaller than the given key.
// In case there is no key in the desired direction, the method returns nil.
// CONTRACT: key, value read-only []byte
GetNearest(key []byte, ascending bool) ([]byte, error)

Once implemented, the method can be used in the cosmos-sdk repo to add a GetNearest function to the KVStore interface, as described in the original issue.

@elias-orijtech
Copy link

@babadro are you actively working on this?

@babadro
Copy link
Author

babadro commented May 13, 2023

@elias-orijtech
Not yet.
I was uncertain whether I correctly understood the concept and if the problem is still relevant considering the age of the original issue.
Hence, I decided to verify it by opening this discussion first.

@ValarDragon
Copy link
Contributor

ValarDragon commented May 13, 2023

I still believe that this would be valuable.

A very significant percentage of iterator usage in Osmosis is this use case. (And suffers kind of insane overheads)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants