Reputation: 507
I have the following Schema:
{
A: String,
B: String,
C: String,
D: String,
}
If I have a where filter with A, B, C, and A, B, D, should I:
index (A, B, C) and (A, B, D)
index (A, B), and separately (C) and (D)?
index (A, B, C, D)?
Upvotes: 0
Views: 17
Reputation: 37038
index (A, B, C) and (A, B, D)
index (A, B), and separately (C) and (D) requires index intersection which has so many conditions to meet that it almost never happens in the wild.
index (A, B, C, D) will work perfectly for (A, B, C) queries and only as good as index (A, B) alone for (A, B, D) queries.
It's very well documented in https://docs.mongodb.com/manual/core/index-compound/#prefixes
Upvotes: 2