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

#2146 Add check for Next/Prev length for IndexNode when searching for index in IndexService.Find #2398

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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