ExportXMLWordPrintableJSON

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

      In agg_join_model.cpp there is this code which determines which pipeline stage to pass into the graph's canPathBeArray:

      auto foreignPathId = pathResolver.resolve(
          predicate.foreignField(),
          predicate.isExpr() ? predicate.source() : getFirstSubpipelineStage(*lookup),
          foreignNodeId,
          fallbackReason);
      

      For a subpipeline, we see that the first subpipeline stage is selected.

      So the call ends up being canPathBeArray("path", <first stage>).

      canPathBeArray: Returns false if the path as seen at the input of 'stage' can be proven to not be an array.

      This means that the first stage (the $match) will not be considered for type inference, instead returning the types only from the base collection.

      If we have \\{$match: {x: {$type: {$not: 'array'}}}}, ... we would want to consider the type of 'x' after the $match, not before.

      Solution

      Something along the lines of, "if the first stage is a $match, select the second stage". 

      I'm pretty sure that $match merging will mean that there will only be 1 $match stage at the start of the pipeline.

      Verification

      Please make sure that a join with a $match proving the foreign join field non-array is eligible for JO without the need for index on the field.

            Assignee:
            Matt Olma
            Reporter:
            Vesko Karaganev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: