Litedb: Binary indices appear bugged

Created on 22 Mar 2016  路  5Comments  路  Source: mbdavid/LiteDB

I created an array of 12 bytes, and used that as the _id value for entries in a collection.

It would semi-consistently fail to find, delete, etc. operations on the entries.

I swapped that for a string of the same data, and it works perfectly.

So...

bug

Most helpful comment

Hi, found the problem! .NET gives me crazy!!

int a = 1;
int b = 10;
var r = a.CompareTo(b); // -1

byte a = 1;
byte b = 10;
var r = a.CompareTo(b); // -9  WTF???

To byte, char, Int16 and UInt16 CompareTo returns difference between values. All others datatypes returns -1, 0 or 1. Thanks for find this!

All 5 comments

It's an ObjectId? Can you write small unit test code to test this?

I made a proof-of-error miniapp rather than a unit test for now.
This code: http://pastebin.com/HHPEv8HN
returned this result:

When  using OIDs, found 105 values, of which 105 were correct, out of a total possible 1331
When NOT  using OIDs, found 716 values, of which 716 were correct, out of a total possible 1331

The exact numbers seem to vary every time I run it too, which is rather odd.

EDIT: Worth noting: The version I used for this test is compiled straight off GitHub's latest code.

Hi @mcmonkey4eva, I'm still looking your code and don't undersand this error.

Vary each time is an indicator because skip list use statistic balanced order - so, each execution generate different levels.

My first try was in compare binary arrays. But looks ok to me and in my tests. No I'm testing how LiteDB are storing this values in index key pages.

Hi, found the problem! .NET gives me crazy!!

int a = 1;
int b = 10;
var r = a.CompareTo(b); // -1

byte a = 1;
byte b = 10;
var r = a.CompareTo(b); // -9  WTF???

To byte, char, Int16 and UInt16 CompareTo returns difference between values. All others datatypes returns -1, 0 or 1. Thanks for find this!

Confirmed this is fixed and functional in latest :) Great work!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RealBlazeIt picture RealBlazeIt  路  3Comments

onurhkb picture onurhkb  路  4Comments

josephinenewbie picture josephinenewbie  路  3Comments

ghiboz picture ghiboz  路  4Comments

sandolkakos picture sandolkakos  路  3Comments