[SERVER-21915] Index not used for regular expression query containing literal '|' (vertical bar) character Created: 15/Dec/15  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Querying
Affects Version/s: 3.0.0
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Jared Wadsworth Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: query-44-grooming
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Assigned Teams:
Query Optimization
Participants:
Case:

 Description   

This is a special case of the more general SERVER-16622. That ticket requests general support for using an index with a regular expression query with the OR operator. In this case, an index is also not used when the regular expression query contains a literal '|' which is escaped through use of the \Q ... \E escape mechanism:

db.collection.find({_id: {$regex: /^\Qfoo|bar\E/}})

Prior to the fix for SERVER-15235, (i.e., 2.6) this query would use an index; after this fix (3.0 and later), it does not.

Since this query does not use an OR operator, it would be good if it was not subject to the limitations imposed by the fix for SERVER-15235.


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