Index not used for regular expression query containing literal '|' (vertical bar) character

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: 3.0.0
    • Component/s: Querying
    • Query Optimization
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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.

            Assignee:
            [DO NOT USE] Backlog - Query Optimization
            Reporter:
            Jared Wadsworth (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated: