In Mongo 3.4 explain("executionStats").distinct(...)
, for some queries
the winning plan contains an IXSCAN
step, and for other queries it contains an DISTINCT_SCAN
step.
What is the difference between the two? Is one of them faster than the other?
Best Answer
They are different stages for different purposes. I believe
DISTINCT_SCAN
is only present when there is an index in the field. AnIXSCAN
stage basically means that the query planner scans an index as one of the stages.For example:
Doing
find()
on an indexed field will trigger the presence of anIXSCAN
stage:While doing
distinct()
on the indexed field will trigger theDISTINCT_SCAN
stage:Note that in both cases, the index
{a: 1}
is used. Without the presence of the index, you will see aCOLLSCAN
stage instead.One is not "faster" than the other. They're different stages serving different purposes.