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

Improve VM logicAnd/Or compileDirect to avoid quadratic behavior

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.2.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • Fully Compatible
    • QE 2023-08-07, QE 2023-08-21, QE 2023-09-04, QE 2023-09-18, QE 2023-10-02
    • 35

      For large $match queries of the form {$match: {a: 1, b: 1, ... }}, we have quadratic time behavior on the number of predicates in two places during compilation: #1 #2

      The issue is in appending the code fragments for each clause. LHS appends "code", resizing the LHS vector. Then we assign LHS to "code", and get the next LHS. This LHS appends the new code, resizing once again, but to a larger size. The number of allocations is about the same as the number of clauses, but each allocation will be the size of the code we have so far. This results in an n^2 behavior on the number of clauses.

      For the largest $match I can possibly make, compiling takes 30+ minutes. With a proof of concept to only append to one code fragment and allow a single vector to resize in the expected way (doubling each time), it takes a minute or less.

            Assignee:
            matt.boros@mongodb.com Matt Boros
            Reporter:
            matt.boros@mongodb.com Matt Boros
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: