How is the secondary index data stored in the B-tree with wiredtiger

Skip to first unread message

Moditha Hewasinghage

Jul 11, 2019, 10:37:58 AM7/11/19
to mongodb-dev

I am interested in checking how the secondary index B-tree data is stored with wiredtiger. I created a sample collection as follows and used wiredtiger page dump to see the content. However, I cannot seem to see the connection from the index B-tree to the data B-tree. (i have attached the dump as well)

I have an index on the ran field.

Data B-tree leaf

        K {1}

        V {\17\00\00\00\10_id\00\01\00\00\00\10ran\00\05\00\00\00\00}

        K {2}

        V {\17\00\00\00\10_id\00\02\00\00\00\10ran\00\0a\00\00\00\00}

        K {3}

        V {\17\00\00\00\10_id\00\03\00\00\00\10ran\00\0a\00\00\00\00}

        K {4}

        V {\17\00\00\00\10_id\00\04\00\00\00\10ran\00\05\00\00\00\00}

        K {5}

        V {\17\00\00\00\10_id\00\05\00\00\00\10ran\00\05\00\00\00\00}


Index B-tree leaf


        K {+\02\04}

        V {\00\08}

        K {+\04\04}

        V {\00\10}

        K {+\06\04}

        V {\00\18}

        K {+\08\04}

        V {\00 }

        K {+\0a\04}

        V {\00(}


Secondary index B-tree leaf

        K {+\0a\04\00\08}

        V {}

        K {+\0a\04\00 }

        V {}

        K {+\0a\04\00(}

        V {}

        K {+\14\04\00\10}

        V {}

        K {+\14\04\00\18}

        V {}

As you can see i see some mapping from the primary index B-tree to the secondary index. However,

  1. What is the relationship from these indexes to the data B-tree ? is there a different encoding ?
  2. Why is the secondary index  B-tree values are empty ?

Geert Bosch

Jul 11, 2019, 2:34:01 PM7/11/19
to mongodb-dev
For non-unique secondary indexes, as well as newly created unique secondary index entries with v4.2, the index key is in KeyString format. This format encodes both the field values of the key as well as the RecordId that indexes into the RecordStore that contains the collection data. The optional value part of the index entries contains TypeBits for the key. These bits allow recovering the exact representation of a value for situations where multiple values compare equal. For example, a document with { x : NumberLong(1) }, { x : 1.0 }, { x : NumberDecimal("1") } and { x : NumberDecimal("1.00") } all compare equal and would result in the same key. The TypeBits encode the extra information to tell them apart and reconstruct the exact BSON value of the key.
Reply all
Reply to author
0 new messages