litedb-org / LiteDB

LiteDB - A .NET NoSQL Document Store in a single data file
http://www.litedb.org
MIT License
8.66k stars 1.25k forks source link

[BUG] Unable to Retrieve Values with Index #2473

Open Joebu opened 7 months ago

Joebu commented 7 months ago

Version LiteDB 5.0.19 Windows 10 0 19045 0 .net 8.0

I'm encountering a strange problem with LiteDB where querying with an index does not return any values, while querying without the index works fine.

Code to Reproduce this is my index SELECT $ FROM $indexes WHERE collection = "Product";

{ "collection": "Product", "name": "_id", "expression": "$._id", "unique": true, "maxLevel": 1 } /* 2 */ { "collection": "Product", "name": "Code", "expression": "$.Code", "unique": false, "maxLevel": 1 }

when I execute the condition using $.Code it uses the index

EXPLAIN SELECT $ FROM Product Where $.Code = "021200000003";

{ "collection": "Product", "snaphost": "read", "pipe": "queryPipe", "index": { "name": "Code", "expr": "$.Code", "order": 1, "mode": "INDEX SEEK(Code = \"021200000003\")", "cost": 10 }, "lookup": { "loader": "document", "fields": "$" }, "select": { "expr": "$", "all": false } } and when it execute the condition using code it does not

EXPLAIN SELECT $ FROM Product Where code = "021200000003"; { "collection": "Product", "snaphost": "read", "pipe": "queryPipe", "index": { "name": "_id", "expr": "$._id", "order": 1, "mode": "FULL INDEX SCAN(_id)", "cost": 100 }, "lookup": { "loader": "document", "fields": "$" }, "filters": [ "$.code=\"021200000003\"" ], "select": { "expr": "$", "all": false } } now when I execute the statement using the index I don't get any result only when not using the index