symisc / unqlite

An Embedded NoSQL, Transactional Database Engine
https://unqlite.symisc.net
Other
2.11k stars 164 forks source link

Question: Cursor seek UNQLITE_CURSOR_MATCH_LE/GE with partial key unusable ? #89

Closed Zener131 closed 5 years ago

Zener131 commented 5 years ago

Hello. Using unqlite_kv_cursor_seek() with a partial so unexisting key but matching part of existing ones, and using UNQLITE_CURSOR_MATCH_LE (or _GE) should lead to find one, as the doc says. It fails. Actually, tracing shows that the method xSeek() used is the lhCursorSeek(), which does a "exact" search and just ignores the argument 'iPos'. Yes it looks logical for a hash-based storage, but as the doc says, the tree-based alternatives available are restricted to memory-only databases. What appears to mean that there is no solution for a database stored in a file and using ordered keys ??? This would dramatically reduce the interest of using it, I really hope the doc is out of date on this point... Can you please clarify ? Thank you, best regards.

symisc commented 5 years ago

Hello, As you have concluded, this depends on the underlying storage engine. Since the default is hash based, it support only exact O(1) lookup. Other storage engine were ordered traversal are supported like B+Tree, R+Tree should implement LE, GE search!

Zener131 commented 5 years ago

Yes I had read, and yes they really should, but they don't if the database is not memory-only, the doc says (last paragraph there: features). Since I need a file, I'm afraid I will use another database engine...