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

Indices in MatchExpressions should be cached in a position-independent manner

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      As a result of SERVER-97662 (https://github.com/mongodb/mongo/commit/d2cff6b001c838531921917653c72528cfe01ca2#diff-50b7dd2ce8ee719a74d5badf8d2dd01c45342c9fc4e43d27d5e97e5bd3faa75d note: because the patch is long the link doesn't work thanks github we're talking about the file `index_tag.h`) , MatchExpression s in the classic plan cache have their index choices cached as positional values (the n th index in the index list), but this positional value can affect the taggedMatchExpressionHash because the position is not stable. 

      We should instead represent index choices in a more stable manner to avoid otherwise-identical MatchExpression s from hashing to different values solely because the index position is different.

      For example: https://github.com/10gen/mongo/pull/33328/files#r1988069769

      index_x_1: {x: 1}
      index_y_1: {y: 1}
      query: find({x: 5, y:1})
      
      Cached plan:
      $and || Selected Index #1 pos 0 combine 1
      x $eq 5
      y $eq 1 || Selected Index #1 pos 0 combine 1
      
      Plan retrieved from cache:
      $and || Selected Index #2 pos 0 combine 1
      x $eq 5
      y $eq 1 || Selected Index #2 pos 0 combine 1
      

            Assignee:
            henri.nikku@mongodb.com Henri Nikku
            Reporter:
            william.qian@mongodb.com William Qian
            Votes:
            0 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated: