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

Consider {a: 1, b: 1} index to satisfy sort on {a: 1, b: -1}

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

      There are two kinds of query plans we may consider here other than a full blocking sort:

      1. For each distinct value of a (in order ascending), scan the entire b sub-range in the reverse direction. This would be a streaming plan.
      2. For each distinct value of a (in order ascending), scan the entire b sub-range in order but put them into a blocking sort for just that sub-range. This should reverse them all but keep the disk accesses sequential. This is semi-streaming in that it doesn't need to block for all results, but will stop and start blocking for each "a" value.

      Either of these plans will involve a high number of seek calls if "a" is high cardinality, which could make them not worth it compared to a blocking sort plan. The first plan would be better for very low "a" cardinality, and the second would be better for when there are very few number of "b" values per value of "a". So such plans would need to be considered with the query planner, ideally in a cost-based manner since our current cost model doesn't seem like it would take into account that the non-linear data accesses would be more expensive.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            charlie.swanson@mongodb.com Charlie Swanson
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated: