Suppose we have the index
{a: 1}. Then the query
{a: /foo/}with the projection {_id: 0, a: 1} should be covered by the index. The plan should be an index scan, filtering by the regex using the index key (without fetching).
In 2.5.4, however, the indexed query solution tree looks like this:
PROJ ---proj = { _id: 0, a: 1 } ---fetched = 1 ---sortedByDiskLoc = 0 ---getSort = [] Child: ------FETCH ---------filter: a regex /foo/ || Selected Index #0 pos 0 ---------fetched = 1 ---------sortedByDiskLoc = 0 ---------getSort = [{ a: 1 }, ] ---------Child: ------------IXSCAN ---------------keyPattern = { a: 1 } ---------------direction = 1 ---------------bounds = field #0['a']: ["", {}), [/foo/, /foo/] ---------------fetched = 0 ---------------fetched = 0 ---------------sortedByDiskLoc = 0 ---------------getSort = [{ a: 1 }, ]
The FETCH is unnecessary; instead, the filter should be moved to the index scan stage and the FETCH should be eliminated. This is a performance bug, as the extra FETCH slows down the query. In general, the filter can be moved into the index scan stage for regex queries like this.
- is related to
-
SERVER-11817 refactor IndexBoundsBuilder to use an enum for exact/inexact rather than boolean
- Closed
- related to
-
SERVER-6353 minimize disk fetches for $mod indexed query
- Closed