views:

35

answers:

1

By default MongoDB creates index on _id key in document. But when I ensure additional index (secondary like in InnoDB from MySQL?) and query it after, engine scans it and then selective scan _id index to get documments offsets?

I'm confused because when sharding comes it I'm right every chunk have own indexes and there will be many random reads per query?

+2  A: 

Every shard will have its own index (containing just the documents in this shard), they will be accessed in parallel (every shard reads its own local index shard) and the results merged. This is not random reads, but multiple parallel index reads. From the perspective of a single shard, this looks just like a normal index access.

This index sharding is also the reason why secondary indexes cannot be unique in a sharding environment (there is no single global index that could ensure uniqueness).

Thilo
shard consists of chunks, that mean every chunk will have its own indexes too and parallel shard index read use parallel chunk indexes?
inquisitor
@inquisitor: Not sure. Having the indexes of all chunks on the same shard integrated into just one index seems to make more sense. But you should ask that on the MongoDB mailing list (and then report back here).
Thilo
@Thilo as you say, all chunks on the same shard share the same index structure (confirmed by mailing list).
inquisitor