Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-21915

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

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • 3.0.0
    • Querying
    • Query Optimization

    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.

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            jared.wadsworth Jared Wadsworth
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated: