1

See code:

var lines = new List<PosLine>(){
    new PosLine{Name="John", Address="dummy1", Tstamp=DateTime.Now},
    new PosLine{Name="Jane", Address="dummy2", Tstamp=DateTime.Now}
};

using(var db = new LiteDatabase(@"test.db"))
{
    var posLines = db.GetCollection<PosLine>("POS");
    foreach(var line in lines)
    {
        var id = posLines.Insert(line);
        Console.WriteLine("id=" + id.ToString());
    }

    var names = posLines.FindAll().Select(p => p.Name).ToList();
    foreach(var name in names)
    {
        Console.WriteLine("name=" + name);
    }
}

The line var names = posLines.FindAll().Select(p => p.Name).ToList(); tries to get a list of "Name", but in this case, it's a full table scan. Is there a way to avoid full table scan, like if I create an index on "Name" property, and then fetch all names from that index?

sstan
  • 35,425
  • 6
  • 48
  • 66
neolei
  • 1,798
  • 2
  • 18
  • 32

1 Answers1

0

If you are reading all documents you will never avoid full scan. Using an index in Name you can do full index scan (avoiding full "table" scan). The diference between this two full scan is deserialization time and amount data read (index full scan is much more cheap) .

Unfortunately, in current version of LiteDB you have no options to get index key only. It´s quite easy to implement that, so open an issue on github that could be implemented in next version.

mbdavid
  • 1,076
  • 7
  • 8
  • That's exactly what I want. Opened issue here: https://github.com/mbdavid/LiteDB/issues/269. Thanks! – neolei Aug 12 '16 at 02:48