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

Refactor getMinMaxBoundForSBEType as it may or may not return values in the same type

    • Query Optimization
    • Fully Compatible
    • 200

      getMinMaxBoundForSBEType may be a wrong abstraction and may need to further breakdown, especially for calculating maximum values. This behavior comes from the idea of appendMaxForType in BSONObjBuilder.

      It has two outcomes:

      1. If there is a viable max value for a type, returns it.
      2. If no, returns the min value for the next type.

      This makes isFullBracketInterval hard to implement to address an interval with two viable representation. For example, an interval $gte: 100 may be represented as

      1. [100, Inf.0]
      2. [100, "")

      Proposal

      Breakdown by introducing more functions:

      1. Add utility function hasMaxValue(TypeTag)
        1. It returns true for numbers, dates, timestamps, null, undefined, etc.
        2. Otherwise false.
      2. Add utility function getNextType(TypeTag)
        1. e.g. getNextType(NumberInt32) -> StringSmall
        2. e.g. getNextType(StringSmall) -> Object
      3. Reconstruct getMinMaxBoundForSBEType with above methods
      std::pair<> getMinMaxBoundForSBEType(type) {
        // if asking for max value
        if (!hasMaxValue(type)) return getMinMaxBoundForSBEType(getNextType(type), true /*isMin*/);
        // Otherwise, a max value is available. It should be a shorter switch-case
        switch(type){
          case NumberInt32: return infinity();
          case Date: return Date_t::max();
          ...
        }
        tasserted("should not reach here");
      }
      
      1. Reconstruct isFullBracketInterval with above methods.
      // Now isFullBracketInterval covers both same-type and mixed-type full bracket intervals.
      bool isFullBracketInterval(...) {
        if (startTag == endTag) {
           if (!hasMaxValue(startTag)) return false; // no chance this is full bracket. 
           min = getMinMaxBoundForSBEType(...);
           max = getMinMaxBoundForSBEType(...);
           return start == min && end == max;
        }
        min = getMinMaxBoundForSBEType(...);
        max = getMinMaxBoundForSBEType(...);
        return start == min && end == max && !endInclusive;
      }
      

            Assignee:
            chii.huang@mongodb.com Chi-I Huang
            Reporter:
            chii.huang@mongodb.com Chi-I Huang
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: