Badger: Key Not Showing Up in Prefix Scan

Created on 8 Jun 2018  路  3Comments  路  Source: dgraph-io/badger

Doing a prefix scan for a prefix like ^d91c3bef076f8580<^g includes a key such as ^d91c3bef076f8580<^golang.

But a prefix like ^d91c3bef076f8580<^n does not include a key like ^d91c3bef076f8580<^nosql.

Why is that so?

Code: I was playing around implement a generic way for secondary indexes and here is the code that shows this behavior.

kinquestion

Most helpful comment

Badger is doing the right thing. You have two keys, you seek to the first one, which fails ValidForPrefix; so the iteration stops. The same happens twice. And then you seek to the keys specifically, with the same prefix as the key has, so it works.

I think you might be confusing ValidForPrefix functionality. It would stop on the first encounter with a key which doesn't have that prefix. It won't just skip over those records.

All 3 comments

Can you create a minimal working example and ascertain that that's, in fact, the case, and not some issue in the bigger code?

@manishrjain Thanks for the follow up!

Here is the code and the badger commit is cdf9ffb40fde980875360cf2b1f7d66946fdc769.

Badger is doing the right thing. You have two keys, you seek to the first one, which fails ValidForPrefix; so the iteration stops. The same happens twice. And then you seek to the keys specifically, with the same prefix as the key has, so it works.

I think you might be confusing ValidForPrefix functionality. It would stop on the first encounter with a key which doesn't have that prefix. It won't just skip over those records.

Was this page helpful?
0 / 5 - 0 ratings