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

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Trivial - P5 Trivial - P5
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • None
    • Query Optimization
    • Fully Compatible

      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]/});
      

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            richard.kreuter Richard Kreuter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: