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

Do not add $in length to plan cache key if there is no sort

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.1.0-rc0, 8.0.0-rc1, 7.3.3, 7.0.12
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • Fully Compatible
    • v8.0, v7.3, v7.0
    • QE 2023-12-11, QE 2023-12-25, QE 2024-01-08, QE 2024-04-15
    • 3

      In SBE plan cache key, we encode the number of elements in $in in it:

      https://github.com/mongodb/mongo/blob/66d182d1e50b7bfa8866ca2c44917638a3758d79/src/mongo/db/query/canonical_query_encoder.cpp#L744

      This is done because of explode for sort SBE plan will have the number of branches equal to the number of elements in $in.

      However, this will lead to worse plan caching even for queries, where is no plan caching.

      It is a fact that we have users that use $in's with arbitrary amount of elements from 1 to thousands.

      Also, if a query have multiple $ins, it may lead to exponential growth.

      One suggestion is instead of generating a unique plan for every $in size when exploding for sort, we can generate plans for all powers of 2 (or 4) and use the smallest plan that can fit all $in values.

            Assignee:
            adi.agrawal@mongodb.com Adi Agrawal
            Reporter:
            ivan.fefer@mongodb.com Ivan Fefer
            Votes:
            2 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              Resolved: