[SERVER-11852] some regex queries have an unnecessary fetch Created: 25/Nov/13  Updated: 11/Jul/16  Resolved: 02/Dec/13

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.5.4
Fix Version/s: 2.5.5

Type: Bug Priority: Minor - P4
Reporter: David Storch Assignee: David Storch
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-6353 minimize disk fetches for $mod indexe... Closed
is related to SERVER-11817 refactor IndexBoundsBuilder to use an... Closed
Operating System: ALL
Participants:

 Description   

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.



 Comments   
Comment by Githook User [ 02/Dec/13 ]

Author:

{u'username': u'dstorch', u'name': u'David Storch', u'email': u'david.storch@10gen.com'}

Message: SERVER-11852 fix query planning for inexact regexes

Signed-off-by: Matt Kangas <matt.kangas@mongodb.com>
Branch: master
https://github.com/mongodb/mongo/commit/bcfc8f0ae35fe08c5336c21cfd9752c06b089956

Generated at Thu Feb 08 03:26:55 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.