Skip to content

Equality query on an indexed string property returns prefix matches #206

Closed

Description

@CaffeinatedCoder

On main (efacaf4): with a B-Tree index on a string property, an equality lookup also returns documents whose value starts with the searched string.

// 100 docs: Name = "p0" .. "p99"
db.PeopleV2.AsQueryable().Where(p => p.Name == "p7").ToList().Count;               // 1 (no index)
await db.PeopleV2.CreateIndexAsync(p => p.Name, "idx_Name", unique: false);         // same with unique: true
db.PeopleV2.AsQueryable().Where(p => p.Name == "p7").ToList().Count;               // 11: p7, p70..p79
(await db.PeopleV2.QueryIndexAsync("idx_Name", "p7", "p7").ToListAsync()).Count;   // 11

The unique-constraint check is not affected: inserting "p7" after "p70" into a unique index is accepted. The bug seems to be in the range scan's end-bound comparison for string keys (a prefix compare instead of an exact one). The indexed LINQ path also returns these matches without re-checking the predicate.

Found while working on #175.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions