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

Stage builder helpers for creating Let expression is too restrictive

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • ALL
    • 161

      The stage builder can create multiple local variables in the same variable frame, even if the SBE engine creates multiple single-variable frames when lowering the tree of instructions.

      For instance, 

       

      optimizer::ABT makeLet(sbe::FrameId frameId, optimizer::ABTVector bindExprs, optimizer::ABT expr) {
          for (size_t idx = bindExprs.size(); idx > 0;) {
              --idx;
              expr = optimizer::make<optimizer::Let>(
                  getABTLocalVariableName(frameId, idx), std::move(bindExprs[idx]), std::move(expr));
          }
          return expr;
      }
      

       

      but when the Let instruction is built around a variable name, it asserts if there is a non-0 index

       

      optimizer::ABT makeLet(const optimizer::ProjectionName& name,
                             optimizer::ABT bindExpr,
                             optimizer::ABT expr) {
          // Verify that 'name' was generated by calling 'getABTLocalVariableName(N, 0)' for some
          // frame ID 'N'.
          auto localVarInfo = getSbeLocalVariableInfo(name);
          tassert(7654322, "", localVarInfo.has_value() && localVarInfo->second == 0);
          return optimizer::make<optimizer::Let>(name, std::move(bindExpr), std::move(expr));
      }
      

       

      Given that SERVER-88687 changed the generation of Compare expressions to use non-0 indexes, either the restriction is lifted, or 0-based variable indexes are restored

       

       
       SbExpr generateExpressionCompare(StageBuilderState& state,
                                        ExpressionCompare::CmpOp op,
                                        SbExpr lhs,
                                        SbExpr rhs) {
           SbExprBuilder b(state);
      
           auto frameId = state.frameIdGenerator->generate();
           auto lhsVar = SbLocalVar{frameId, 0};
           auto rhsVar = SbLocalVar{frameId, 1};
      

       

      The failure can be reproduced by adding this entry in jstests/libs/block_processing_test_cases.js

               {
                   name: "GroupByWithComplexIdExpr",
                   pipeline: [
                       {$match: {[timeFieldName]: {$lt: dateMidPoint}}},
                       {
                           $group: {
                               _id: {
                                   $lt: [
                                       29336,
                                       {$mod: ["$b", 1.0]}
                                   ]
                               },
                           }
                       }
                   ],
                   usesBlockProcessing: featureFlagsAllowBlockHashAgg
               },
      

       

            Assignee:
            andrew.paroski@mongodb.com Drew Paroski
            Reporter:
            alberto.massari@mongodb.com Alberto Massari
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: