[CHAP2] With or without index performance comparison

Hi all,

I have a question regarding chapter 2 “sorting with indexes”. I would like to know, in this particular case, why MongoDB performs slower sorting with the ssn field which is indexed than the first_name field which is not ?

Is this because in-memory sorting performs better than in-disk index sorting ?

Thanks !

@ Joris_SAIDANI_37802

I’m not exactly clear on what you’re asking here, but if you want make a comparision, make the two examples exactly the same, but with and without an index. As it stands, you’re comparing apples to oranges.

Thanks for answering @DHz

Sorry that wasn’t clear because I sorted on 2 differents fields (only one was indexed).

Let’s do a better comparison as you recommend. I’m just wondering why, in these particular cases with really simple queries which return a lot of results, MongoDB performs better without indexes ?

In other words, is asking “When should I index my data?” is a true database designer question ?

1 Like

@ Joris_SAIDANI_37802

That’s a perfectly reasonable question and, I think, a good one for a DBA to think about. However, it’s a bit premature in this course. We cover a lot of these issues in Chapters 3 & 4, particularly the lectures on Resource Allocation and on CRUD optimization. Work through those and, if you still have any questions that you can’t answer for yourself, post back here and we can have a more nuanced discussion on this. :wink: Good luck.