-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Query Planning
-
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:
- If there is a viable max value for a type, returns it.
- 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
- [100, Inf.0]
- [100, "")
Proposal
Breakdown by introducing more functions:
- Add utility function hasMaxValue(TypeTag)
- It returns true for numbers, dates, timestamps, null, undefined, etc.
- Otherwise false.
- Add utility function getNextType(TypeTag)
- e.g. getNextType(NumberInt32) -> StringSmall
- e.g. getNextType(StringSmall) -> Object
- 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"); }
- 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; }