Lab 3.1: need to improve course lessons

Hi guys, especially course owners/creators!
It’s quite hard to get correct answer at Lab 3.1 I found it only based on
“nReturned”: 3335,
“totalKeysExamined”: 3335

what I did?, I have created all indexes that Lab 3.1 contains and then, ran explain query (with hint) few times and only then found correct answer.

IMO it’s kinda of cheating, I want to understand explain output without this kind of “testing”. I have found WHY this happens at this topic:


Reason was “The fact that a range query is involved additional sorting”

What I want? Could you please add explanation and/or video that “The fact that a range query is involved additional sorting” despite index prefix 100% match query.

find({ “address.state”: “NY”, stars: { $gt: 3, $lt: 4 } }).sort({ name: 1 })
VS
find({ “address.state”: “NY”, stars: 4 }).sort({ name: 1 })

plain stars condition and ranged condition dramatically change query plan.

PS
this query stage “SORT_KEY_GENERATOR” not covered in video :slight_smile:

3 Likes

Are you confessing to “cheating” @cystbear? :wink:
However, I think this was the intention of the Curriculum Engineers. They wanted students to be familiar with reading Explain Plans by creating and executing all the indexes, hence the title of the lab.

If you knew the Equality, Sort, Range rule, then it would have been a lot easier to answer without needing to create all the indexes. But this rule was explained in Chapter 4 instead, therefore reinforcing the fact that this lab requires students to create and read all the explain plans.

It was briefly covered here.

3 Likes

Hell yeah, I have found answer for my “Hard Question” exactly at next video “Equality, Sort, Range”.

Thanks for link to SORT_KEY_GENERATOR explanation.

1 Like