Skip to content

Update query-optimization.txt #2162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

kerneljake
Copy link
Contributor

The word "returned" implies that you can workaround this limitation using a projection, but in fact you cannot (per SERVER-2104).

The word "returned" implies that you can workaround this limitation using a projection, but in fact you cannot (per SERVER-2104).
@kay-kim
Copy link
Contributor

kay-kim commented Feb 24, 2015

Hi -- isn't the current page and the SERVER-2104 stating that if you have an index
db.foo.ensureIndex( { a: 1, "b.x": 1 } )
then
db.foo.find( { a: { $lt: 1 } }, { a: 1, _id: 0 } ) will be covered
whereas
db.foo.find( { a: { $lt: 1} }, { a: 1, "b.x": 1, _id: 0 } ) will not be covered

@kerneljake
Copy link
Contributor Author

I agree with the above example, buy my example is different.
Below is an example of a literal interpretation of the sentence in an attempt to get around this limitation, but it doesn't work.

{code}

db.foo.insert({ tenant:1, user:{ name:"tester", password:"secret"}})

db.foo.ensureIndex({tenant:1, "user.name":1})

db.foo.find({tenant:1, "user.name":"tester"}, {user:0, _id:0}).explain(true).executionStats.totalDocsExamined
1
{code}

Since the indexed field in the subdocument is not returned, I would expect the query to be covered, but it is not covered. The phrase "any of the returned index fields are fields in subdocuments" implies that you can project away a subdocument containing an indexed field and still achieve a covered query.

@kay-kim
Copy link
Contributor

kay-kim commented Feb 24, 2015

ah -- I see. How about "If any of the indexed field in the query predicate or returned in the projection ..."
to cover both examples.

@kerneljake
Copy link
Contributor Author

Yes, that sounds good!

@kay-kim
Copy link
Contributor

kay-kim commented Feb 24, 2015

merged with changes as discussed. thank you!

@kay-kim kay-kim closed this Feb 24, 2015
mongo-cr-bot pushed a commit that referenced this pull request Nov 18, 2022
mongodb-server-docs-sync-bot bot pushed a commit that referenced this pull request Jun 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants