Hi, while I could answer the question, I have the following query:
If we have two queries:
Q1 = db.people.find({“address.state”: “Nebraska”,“last_name”: /^G/,“job”: “Police officer”})
Q2 = db.people.find({“job”: /^P/, “first_name”: /^C/, “address.state”: “Indiana”}).sort({ “last_name”: 1 })
There are two indexes:
I1 = { “address.state”: 1, “last_name”: 1, “job”: 1 }
I2 = { “address.state”: 1, “job”: 1 }
And if the selectivity of address.state and job is low and that of address.state and last_name is high, would it not be better to have an index as I2 instead of I1? While I1 would assist sorting, it would happen post filter and hence, should be faster compared to I1. Please share your expert advise.
Thanks,
Sam