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

Left-anchored regular expressions all of whose characters are non-special don't need to run the regex engine

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Trivial - P5 Trivial - P5
    • None
    • None
    • Querying
    • None
    • Query Optimization
    • Fully Compatible

    Description

      Left-anchored regular expressions all of whose characters are non-special don't need to run the regex engine, but can just do the appropriate range query upfrom the prefix upto the prefix plus 1 (so to speak).

      IndexBoundsBuilder already includes code to find the longest non-special prefix of an anchored regular expression. Seems like it ought to be straightforward to check if the index bounds string is the same length as the regex string plus 1 (for the caret) somewhere downstream in query.

      No idea if this will make any use case appreciably faster, but it's an obvious "missing" optimization that should be easy to implement and maintain.

      Presumably one way to test for the existence of (and so regressions in) this improvement would be to compare the explain() plans for these two queries:

      db.foo.find({s:/^abc/});
      db.foo.find({s:/^abc[qz]/});

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            richard.kreuter Richard Kreuter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated: