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

A $match and $group pipeline fails when $match has a $or expression

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 5.1.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • ALL
    • Hide

      1. execute mongod

      $ build/debug/install/bin/mongod --setParameter featureFlagSBEGroupPushdown=true --setParameter internalQueryEnableSlotBasedExecutionEngine=true
      

      2. run the following commands at shell

      var coll = db.getCollection("test");
      coll.insert({a: 1});
      coll.aggregate([{$match: {$or: [{"a": 1}, {"b": 10}]}}, {$group: {_id: "$a"}}]);
      
      Show
      1. execute mongod $ build/debug/install/bin/mongod --setParameter featureFlagSBEGroupPushdown= true --setParameter internalQueryEnableSlotBasedExecutionEngine= true 2. run the following commands at shell var coll = db.getCollection( "test" ); coll.insert({a: 1}); coll.aggregate([{$match: {$or: [{ "a" : 1}, { "b" : 10}]}}, {$group: {_id: "$a" }}]);
    • QE 2021-10-04

      pipeline:

      [\{$match: {$or: [{"obj.obj.date": {$not: {$gte: new Date("2019-07-18T22:53:48.097Z")}}}, \{"num": {$not: {$bitsAnyClear: NumberLong("10")}}}]}}, \{$sort: {_id: 1}}, \{$group: {_id: {$arrayElemAt: ["$obj.obj.obj.obj.array", 52943]}}}],
      

      error message:

      [js_test:agg_fuzzer-2ec3-1632415870555-0] Attempted to run the aggregate with explain(). There was an error running explain on version "5.1.0-alpha-1078-g92738c5-patch-614ca1de3e8e8641af400d28": [Error: command failed: {
      [js_test:agg_fuzzer-2ec3-1632415870555-0] "ok" : 0,
      [js_test:agg_fuzzer-2ec3-1632415870555-0] "errmsg" : "Cannot create a sub-query from an existing CanonicalQuery that carries a non-empty pipeline",
      [js_test:agg_fuzzer-2ec3-1632415870555-0] "code" : 5842500,
      [js_test:agg_fuzzer-2ec3-1632415870555-0] "codeName" : "Location5842500"
      

       
      the call stack:

      #3  0x000055e9c4a2632f in mongo::invariantWithContextAndLocation<bool, mongo::CanonicalQuery::canonicalize(mongo::OperationContext*, mongo::CanonicalQuery const&, mongo::MatchExpression*)::$_2>(bool const&, char const*, mongo::CanonicalQuery::canonicalize(mongo::OperationContext*, mongo::CanonicalQuery const&, mongo::MatchExpression*)::$_2&&, char const*, unsigned int) (testOK=@0x7fc7ab7d2797: false, expr=0x55e9bf316c86 "baseQuery.pipeline().empty()", contextExpr=..., file=0x55e9bf016771 "src/mongo/db/query/canonical_query.cpp", line=174) at src/mongo/util/invariant.h:98
      #4  0x000055e9c4a25e10 in mongo::CanonicalQuery::canonicalize (opCtx=0x7fc78b339020, baseQuery=..., root=0x7fc78b261dc0) at src/mongo/db/query/canonical_query.cpp:172
      #5  0x000055e9c49f28e2 in mongo::QueryPlanner::planSubqueries (opCtx=0x7fc78b339020, collection=..., planCache=0x7fc798ce03f0, query=..., params=...) at src/mongo/db/query/query_planner.cpp:1176
      #6  0x000055e9c4424d98 in mongo::sbe::SubPlanner::plan (this=0x7fc79bd08c20) at src/mongo/db/query/sbe_sub_planner.cpp:45
      #7  0x000055e9c42b45ca in mongo::(anonymous namespace)::getSlotBasedExecutor(mongo::OperationContext*, mongo::CollectionPtr const*, std::unique_ptr<mongo::CanonicalQuery, std::default_delete<mongo::CanonicalQuery> >, std::function<void (mongo::CanonicalQuery*)>, mongo::PlanYieldPolicy::YieldPolicy, unsigned long) (opCtx=0x7fc78b339020, collection=0x7fc7ab7d6158, cq=std::unique_ptr<mongo::CanonicalQuery> = {...}, extractAndAttachPipelineStages=..., requestedYieldPolicy=mongo::PlanYieldPolicy::YieldPolicy::YIELD_AUTO, plannerOptions=4096) at src/mongo/db/query/get_executor.cpp:1115
      #8  0x000055e9c42b3c9a in mongo::getExecutor(mongo::OperationContext*, mongo::CollectionPtr const*, std::unique_ptr<mongo::CanonicalQuery, std::default_delete<mongo::CanonicalQuery> >, std::function<void (mongo::CanonicalQuery*)>, mongo::PlanYieldPolicy::YieldPolicy, unsigned long) (opCtx=0x7fc78b339020, collection=0x7fc7ab7d6158, canonicalQuery=std::unique_ptr<mongo::CanonicalQuery> = {...}, extractAndAttachPipelineStages=..., yieldPolicy=mongo::PlanYieldPolicy::YieldPolicy::YIELD_AUTO, plannerOptions=4096) at src/mongo/db/query/get_executor.cpp:1172
      #9  0x000055e9c42b507a in mongo::getExecutorFind(mongo::OperationContext*, mongo::CollectionPtr const*, std::unique_ptr<mongo::CanonicalQuery, std::default_delete<mongo::CanonicalQuery> >, std::function<void (mongo::CanonicalQuery*)>, bool, unsigned long) (opCtx=0x7fc78b339020, collection=0x7fc7ab7d6158, canonicalQuery=std::unique_ptr<mongo::CanonicalQuery> = {...}, extractAndAttachPipelineStages=..., permitYield=true, plannerOptions=4096) at src/mongo/db/query/get_executor.cpp:1200
      #10 0x000055e9c428b945 in mongo::(anonymous namespace)::attemptToGetExecutor (expCtx=0x7fc78b49eb60 = {...}, collection=..., nss=..., queryObj=owned BSONObj 119 bytes @ 0x7fc78aead328 = {...}, projectionObj=owned BSONObj 41 bytes @ 0x7fc78a0cc6e8 = {...}, metadataRequested=std::bitset, sortObj=owned BSONObj 14 bytes @ 0x7fc7988e8268 = {...}, skipThenLimit=..., groupIdForDistinctScan=boost::optional<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > is not initialized, aggRequest=0x7fc78b449058, plannerOpts=4096, matcherFeatures=@0x55e9bf4810e0: 57, pipeline=0x7fc799b01940) at src/mongo/db/pipeline/pipeline_d.cpp:237
      #11 0x000055e9c4289aac in mongo::PipelineD::prepareExecutor (expCtx=0x7fc78b49eb60 = {...}, collection=..., nss=..., pipeline=0x7fc799b01940, sortStage=0x7fc78b62fa20 = {...}, rewrittenGroupStage=std::unique_ptr<mongo::GroupFromFirstDocumentTransformation> = {...}, unavailableMetadata=std::bitset = {...}, queryObj=owned BSONObj 119 bytes @ 0x7fc78aead328 = {...}, skipThenLimit=..., aggRequest=0x7fc78b449058, matcherFeatures=@0x55e9bf4810e0: 57, hasNoRequirements=0x7fc7ab7d4847) at src/mongo/db/pipeline/pipeline_d.cpp:1086
      #12 0x000055e9c42880c5 in mongo::PipelineD::buildInnerQueryExecutorGeneric (collection=..., nss=..., aggRequest=0x7fc78b449058, pipeline=0x7fc799b01940) at src/mongo/db/pipeline/pipeline_d.cpp:849
      #13 0x000055e9c42871b3 in mongo::PipelineD::buildInnerQueryExecutor (collection=..., nss=..., aggRequest=0x7fc78b449058, pipeline=0x7fc799b01940) at src/mongo/db/pipeline/pipeline_d.cpp:639
      #14 0x000055e9c390ba30 in mongo::runAggregate (opCtx=0x7fc78b339020, origNss=..., request=..., liteParsedPipeline=..., cmdObj=owned BSONObj 390 bytes @ 0x7fc78afcce3d = {...}, privileges=std::vector of length 0, capacity 0, result=0x7fc7a0c17420) at src/mongo/db/commands/run_aggregate.cpp:776
      

       

            Assignee:
            yoonsoo.kim@mongodb.com Yoon Soo Kim (Inactive)
            Reporter:
            yoonsoo.kim@mongodb.com Yoon Soo Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: