some regex queries have an unnecessary fetch

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Minor - P4
    • 2.5.5
    • Affects Version/s: 2.5.4
    • Component/s: Querying
    • None
    • ALL
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      Suppose we have the index

      {a: 1}

      . Then the query

      {a: /foo/}

      with the projection {_id: 0, a: 1} should be covered by the index. The plan should be an index scan, filtering by the regex using the index key (without fetching).

      In 2.5.4, however, the indexed query solution tree looks like this:

      PROJ
      ---proj = { _id: 0, a: 1 }
      ---fetched = 1
      ---sortedByDiskLoc = 0
      ---getSort = []
      Child:
      ------FETCH
      ---------filter:
                      a regex /foo/  || Selected Index #0 pos 0
      ---------fetched = 1
      ---------sortedByDiskLoc = 0
      ---------getSort = [{ a: 1 }, ]
      ---------Child:
      ------------IXSCAN
      ---------------keyPattern = { a: 1 }
      ---------------direction = 1
      ---------------bounds = field #0['a']: ["", {}), [/foo/, /foo/]
      ---------------fetched = 0
      ---------------fetched = 0
      ---------------sortedByDiskLoc = 0
      ---------------getSort = [{ a: 1 }, ]
      

      The FETCH is unnecessary; instead, the filter should be moved to the index scan stage and the FETCH should be eliminated. This is a performance bug, as the extra FETCH slows down the query. In general, the filter can be moved into the index scan stage for regex queries like this.

            Assignee:
            David Storch
            Reporter:
            David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: