[SERVER-13803] Query planner should be able to plan $text queries that require collection scan Created: 30/Apr/14 Updated: 28/Dec/23 |
|
| Status: | Backlog |
| Project: | Core Server |
| Component/s: | Querying, Text Search |
| Affects Version/s: | 2.6.0 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Will Shaver | Assignee: | Backlog - Query Integration |
| Resolution: | Unresolved | Votes: | 3 |
| Labels: | qi-text-search | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||
| Assigned Teams: |
Query Integration
|
||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||
| Description |
|
On a schema like the following:
With an index like:
Doing this with $and query succeeds as expected:
But this query fails:
With this error
(I realize this seems asinine, but my actual code is quite a bit more complicated with a full-text index on several different text fields.) |
| Comments |
| Comment by Jerome Mutgeert [ 16/Jun/21 ] |
|
Hi all in trouble, I've got a decent workaround solutuion:
Given that I have an index on the column: db.Products.find({$or:[ {name:{$regex:'hi', $options:'i'}, created: {$ne: 'nonExistingString'}}, {$text: {$search: 'Hi'}} ]})
|
| Comment by Billy Tetrud [ 25/Jan/17 ] |
|
"can't currently be used for queries that require a collection scan" A. mongo doesn't normally prevent collection scans, as that is sometimes a valid thing to do, and B. having a $text query alongside an unindexed clause does not always result in a collection scan (in my case it doesn't). Here's an example: MyCollection.find({parent: ObjectId("32fj8sf328f"), $or:[{$text:{$search:"hello"}}, {$regex:"hello", $options: '-i'}}] Where parent is indexed, that search might be very cheap regardless of the lack of an index. |
| Comment by J Rassi [ 01/May/14 ] |
|
$text predicates can't currently be used for queries that require a collection scan (yep, documented under $text Behavior). Updating title, changing ticket type from "Bug" to "Improvement". |
| Comment by Will Shaver [ 30/Apr/14 ] |
|
Just in case it is different, my actual use-case is to perform a regex on some of the fields that are also in the full text search. Currently full text restricts some results that I would like to include, and a regex $or on the same field would allow this inclusion. |
| Comment by Will Shaver [ 30/Apr/14 ] |
|
From the docs, "To use a $text query in an $or expression, all clauses in the $or array must be indexed." |