mbdavid / LiteDB

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

[SUGGESTION] maybe do not store FiledName into data? #2117

Closed sgf closed 2 years ago

sgf commented 2 years ago

Is your feature request related to a problem? Please describe. i make a test store 1-million data in 2 files. one is CTS,one is CodeTask.


    public class CTS {
        public CTS(string code, int taskId) {
            id = code;
            d = taskId;
        }
        [LiteDB.BsonId]
        public string id;
        public int d;
    }

       public class CodeTask {

            public CodeTask(string code, int taskId) {
                Code = code;
                TaskId = taskId;
            }

            [LiteDB.BsonId]
            public string Code;

            public int TaskId;
        }

im got 2 files. image

theres about 7mb size different.

if litedb make a field map(hold),maybe will be better ?

sgf commented 2 years ago

another problem is when im query some field not in the data,it seems LiteDB will do full table scan ? emm.

kcsombrio commented 2 years ago

Hi @sgf, the size difference is due to the indexing system. LiteDB uses SkippedLists as the indexing system, which generates a random sized linked pointer array. So if you recreate these same databases again with the same amount of records, you should get different sized datafiles

sgf commented 2 years ago

Hi @sgf, the size difference is due to the indexing system. LiteDB uses SkippedLists as the indexing system, which generates a random sized linked pointer array. So if you recreate these same databases again with the same amount of records, you should get different sized datafiles

im just want to say,im open the db file by notepad++ ,and its store the Field Name in there(every recored).

kcsombrio commented 2 years ago

Ok, yes, this is by design. The object is serialized into a document on Bson format, which records the name of each property. This is a feature so you have the flexibility to store a modified object within the same collection without having to change its structure.