[SERVER-47848] Aggregation fails to optimize TEXT_OR to OR when appropriate Created: 30/Apr/20  Updated: 29/Oct/23  Resolved: 12/May/20

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 4.7.0

Type: Bug Priority: Major - P3
Reporter: Ruoxin Xu Assignee: David Percy
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
is related to SERVER-26833 Permit non-blocking $text queries whe... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:
Linked BF Score: 0

 Description   

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" : {
 
							}
						}
					}
				}
			}
		}



 Comments   
Comment by Githook User [ 12/May/20 ]

Author:

{'name': 'David Percy', 'email': 'david.percy@mongodb.com', 'username': 'dpercy'}

Message: SERVER-47848 Don't assume pipeline needs textScore, unless needsMerge
Branch: master
https://github.com/mongodb/mongo/commit/2a599c879c0775773ac4f67ef148a0838a5e9898

Generated at Thu Feb 08 05:15:25 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.