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

Aggregation fails to optimize TEXT_OR to OR when appropriate

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

      In SERVER-26833, a $text query can be optimized to not use a blocking TEXT_OR stage when user doesn't specify any textScore projection, instead to use a OR stage. In BF-16877, Aggregation failed to respect this optimization.

       

      The query plan for the aggregate() $text query:

      db.fuzzer_coll.explain().aggregate([{"$match":{"$text":{"$search" : "Dynamic"}}}]);
      
      "winningPlan" : {
      			"stage" : "TEXT",
      			"indexPrefix" : {
      
      			},
      			"indexName" : "$**_text",
      			"parsedTextQuery" : {
      				"terms" : [
      					"dynam"
      				],
      				"negatedTerms" : [ ],
      				"phrases" : [ ],
      				"negatedPhrases" : [ ]
      			},
      			"textIndexVersion" : 3,
      			"inputStage" : {
      				"stage" : "TEXT_MATCH",
      				"inputStage" : {
      					"stage" : "TEXT_OR",
      					"inputStage" : {
      						"stage" : "IXSCAN",
      						"keyPattern" : {
      							"_fts" : "text",
      							"_ftsx" : 1
      						},
      						"indexName" : "$**_text",
      						"isMultiKey" : true,
      						"isUnique" : false,
      						"isSparse" : false,
      						"isPartial" : false,
      						"indexVersion" : 2,
      						"direction" : "backward",
      						"indexBounds" : {
      
      						}
      					}
      				}
      			}
      		}
      

      The query plan for the equivalent find() $text query:

      db.fuzzer_coll.explain().find({$text:{$search: "Dynamic"}});
      
      "winningPlan" : {
      			"stage" : "TEXT",
      			"indexPrefix" : {
      
      			},
      			"indexName" : "$**_text",
      			"parsedTextQuery" : {
      				"terms" : [
      					"dynam"
      				],
      				"negatedTerms" : [ ],
      				"phrases" : [ ],
      				"negatedPhrases" : [ ]
      			},
      			"textIndexVersion" : 3,
      			"inputStage" : {
      				"stage" : "TEXT_MATCH",
      				"inputStage" : {
      					"stage" : "FETCH",
      					"inputStage" : {
      						"stage" : "OR",
      						"inputStage" : {
      							"stage" : "IXSCAN",
      							"keyPattern" : {
      								"_fts" : "text",
      								"_ftsx" : 1
      							},
      							"indexName" : "$**_text",
      							"isMultiKey" : true,
      							"isUnique" : false,
      							"isSparse" : false,
      							"isPartial" : false,
      							"indexVersion" : 2,
      							"direction" : "backward",
      							"indexBounds" : {
      
      							}
      						}
      					}
      				}
      			}
      		}
      

            Assignee:
            david.percy@mongodb.com David Percy
            Reporter:
            ruoxin.xu@mongodb.com Ruoxin Xu
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: