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

$or query can trigger an infinite loop during plan enumeration

    • Fully Compatible
    • ALL
    • v7.2, v7.0, v6.0, v5.0
    • QO 2023-11-13, QO 2023-11-27, QO 2023-12-11
    • 14

      Certain $or queries can trigger an infinite loop in the PlanEnumerator. While the plan space can be quite large for indexed $or queries, we have logic which is supposed to bail out of plan enumeration once a certain number of alternatives have been generated. This logic is not kicking in correctly.

      Note that this only affects the so-called "lockstep $or" enumeration order which was first implemented in SERVER-50291. Lockstep $or enumeration is intended to make it more likely that the system generates and scores interesting indexed $or plans, in the end resulting in better access paths for indexed $or predicates. It was enabled by default in SERVER-74893 for versions 7.1.0-rc0 and 7.0.2. Many customers are first getting exposed to this new default $or plan enumeration logic as they upgrade to 7.0.2 which made us aware of the bug. The issue can be worked around safely by disabling lockstep $or enumeration. This can be done on the command line, in a config file, or with a shell command such as the following:

      db.adminCommand({setParameter: 1, internalQueryEnumerationPreferLockstepOrEnumeration: false});
      

      Note that the infinite loop does not include any interrupt points, so the affected queries are impossible to kill and can block the server from shutting down. It may also manifest as increased CPU activity, since the thread is spinning busily rather than deadlocked.

      As of this writing, I've confirmed that 7.0.2 is affected, but I plan to double-check whether more recent versions are affected by the bug as well.

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            23 Start watching this issue

              Created:
              Updated:
              Resolved: