summaryrefslogtreecommitdiff
path: root/jstests/aggregation/bugs
diff options
context:
space:
mode:
authorHartek Sabharwal <hartek.sabharwal@mongodb.com>2021-02-16 16:24:25 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-02-16 17:08:34 +0000
commit2eb1fbcfc5a10cd777f7e6883b2aeb971f1333ac (patch)
treed6d623ee5e93328825136dc2f653009b0dd351c1 /jstests/aggregation/bugs
parente6c38cb94c71f751fa05bc11a625123c4a713832 (diff)
downloadmongo-2eb1fbcfc5a10cd777f7e6883b2aeb971f1333ac.tar.gz
SERVER-36794 Non-blocking plans with just one search term do not need an OR stage
Diffstat (limited to 'jstests/aggregation/bugs')
-rw-r--r--jstests/aggregation/bugs/optimize_text.js (renamed from jstests/aggregation/bugs/server47848.js)14
1 files changed, 10 insertions, 4 deletions
diff --git a/jstests/aggregation/bugs/server47848.js b/jstests/aggregation/bugs/optimize_text.js
index 706790e6a05..dc22208ff8a 100644
--- a/jstests/aggregation/bugs/server47848.js
+++ b/jstests/aggregation/bugs/optimize_text.js
@@ -1,4 +1,4 @@
-// Ensures TEXT_OR stage is replaced with OR when possible.
+// Ensures TEXT_OR stage is elided or replaced with OR stage when possible.
// @tags: [
// # We don't try to replace TEXT_OR with OR when the results are consumed by a merging node,
// # because the shard doesn't know whether the merger needs the textScore metadata.
@@ -10,11 +10,12 @@
load("jstests/libs/analyze_plan.js");
-const coll = db.server47848;
+const coll = db.optimize_text;
assert.commandWorked(coll.createIndex({"$**": "text"}));
-const findExplain = coll.find({$text: {$search: 'banana'}}).explain();
-const aggExplain = coll.explain().aggregate({$match: {$text: {$search: 'banana'}}});
+const findExplain = coll.find({$text: {$search: 'banana leaf'}}).explain();
+const findSingleTermExplain = coll.find({$text: {$search: 'banana'}}).explain();
+const aggExplain = coll.explain().aggregate({$match: {$text: {$search: 'banana leaf'}}});
// The .find() plan doesn't have TEXT_OR, it has OR instead.
// Both kinds of stages deduplicate record IDs, but OR is better because OR is streaming
@@ -33,4 +34,9 @@ assert(!planHasStage(db, findExplain, 'TEXT_OR'), findExplain);
// be an implicit dependency on textScore.
assert(planHasStage(db, aggExplain, 'OR'), aggExplain);
assert(!planHasStage(db, aggExplain, 'TEXT_OR'), aggExplain);
+
+// Non-blocking $text plans with just one search term do not need an OR stage, as a further
+// optimization.
+assert(!planHasStage(db, findSingleTermExplain, 'OR'), findSingleTermExplain);
+assert(!planHasStage(db, findSingleTermExplain, 'TEXT_OR'), findSingleTermExplain);
})();