Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion LiteDB/Engine/Services/IndexService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public IndexNode Find(CollectionIndex index, BsonValue value, bool sibling, int

for (int i = index.MaxLevel - 1; i >= 0; i--)
{
for (; cur.GetNextPrev((byte)i, order).IsEmpty == false; cur = this.GetNode(cur.GetNextPrev((byte)i, order)))
for (; NextPrevContaintsData(cur, (byte)i, order); cur = this.GetNode(cur.GetNextPrev((byte)i, order)))
{
var next = this.GetNode(cur.GetNextPrev((byte)i, order));
var diff = next.Key.CompareTo(value, _collation);
Expand All @@ -368,6 +368,21 @@ public IndexNode Find(CollectionIndex index, BsonValue value, bool sibling, int
}

return null;

bool NextPrevContaintsData(IndexNode current, byte level, int orderValue)
{
var nextPrevLength = orderValue == Query.Ascending
? current.Next.Length
: current.Prev.Length;

// TODO need to check why some index node stored at this level does not have expected Next and Prev items
if (nextPrevLength <= level)
{
return false;
}

return current.GetNextPrev(level, order).IsEmpty == false;
}
}

#endregion
Expand Down