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

Deduping in OR, SORT_MERGE, and IXSCAN (multikey case) uses unbounded memory

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: 3.0.12
    • Fix Version/s: Backlog
    • Component/s: Querying
    • Operating System:
      ALL

      Description

      Each of the stages listed in the title keeps a set of RecordIds; these are used to identify seen documents in order to ensure that we do not return the same document twice to the user. However, this requires memory proportional to the number of documents processed, and nothing is in place to ensure that we do not consume too much. One example of how to reproduce this unbounded memory growth is given below.

      • 40 M documents of the form {x:0, y:0}
      • index on {y:1}
      • query of the following form (full repro script attached)

              q = {$or: [{x: 0, y: 0}, {x: 0, y: 0}]}
              db.c.find(q).hint({y: 1}).sort({z: -1}).limit(30).itcount()
      

      Heap profile call tree shows memory usage by OrStage::work grow to about 1.5 GB as it scans the collection, then drop back to 0 at conclusion of query. Graph in each row shows memory usage for that node and its descendants; second number in each row is max memory in MB for that node.

        Attachments

        1. heap-profile.png
          heap-profile.png
          229 kB
        2. memory-growth-calltree.png
          memory-growth-calltree.png
          170 kB
        3. repro.sh
          1 kB

          Issue Links

            Activity

              People

              • Votes:
                2 Vote for this issue
                Watchers:
                25 Start watching this issue

                Dates

                • Created:
                  Updated: