[SERVER-9400] Certain queries can fail on collection containing compound index with "text" component Created: 18/Apr/13  Updated: 11/Jul/16  Resolved: 17/May/13

Status: Closed
Project: Core Server
Component/s: Index Maintenance, Querying, Text Search
Affects Version/s: 2.4.2
Fix Version/s: 2.5.0

Type: Bug Priority: Major - P3
Reporter: Will Shaver Assignee: J Rassi
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Steps To Reproduce:

Some command line statements that will show the issue.

> db.stacks.find()
{ "_id" : "S00001", "name" : "stack S00001", "description" : "description right beneath early feel as cars and give
 one little able animals good try food my a in drinks kids education use events design or", "authorId" : "U00001", "published" : true, "popularity" : 0, "galleryId" : "G00001", "popularityHistory" : [ ], "popularityDate" : ISODate("2012-04-18T23:26:14Z"), "comments" : [ ], "blocks" : [ ], "updatedDate" : ISODate("2013-04-18T23:26:15.850Z"), "createdDate" : ISODate("2013-04-18T23:26:15.850Z"), "__v" : 0 }
 
> db.stacks.getIndexes()
[
        {
                "v" : 1,
                "key" : {
                        "_id" : 1
                },
                "ns" : "unit_test.stacks",
                "name" : "_id_"
        },
        {
                "v" : 1,
                "key" : {
                        "_fts" : "text",
                        "_ftsx" : 1,
                        "published" : 1
                },
                "ns" : "unit_test.stacks",
                "name" : "textIndex",
                "background" : true,
                "safe" : null,
                "weights" : {
                        "name" : 1
                },
                "default_language" : "english",
                "language_override" : "language",
                "textIndexVersion" : 1
        }
]
 
> db.stacks.runCommand('text', {search: 'stack'})
{
        "queryDebugString" : "stack||||||",
        "language" : "english",
        "results" : [
                {
                        "score" : 0.75,
                        "obj" : {
                                "_id" : "S00001",
                                "name" : "stack S00001",
                                "description" : "description right beneath early feel as cars and give one little able animals good try food my a in drinks kids education use events design or",
                                "authorId" : "U00001",
                                "published" : true,
                                "popularity" : 0,
                                "galleryId" : "G00001",
                                "popularityHistory" : [ ],
                                "popularityDate" : ISODate("2012-04-18T23:28:32Z"),
                                "comments" : [ ],
                                "blocks" : [ ],
                                "updatedDate" : ISODate("2013-04-18T23:28:34.387Z"),
                                "createdDate" : ISODate("2013-04-18T23:28:34.386Z"),
                                "__v" : 0
                        }
                }
        ],
        "stats" : {
                "nscanned" : 1,
                "nscannedObjects" : 0,
                "n" : 1,
                "nfound" : 1,
                "timeMicros" : 118
        },
        "ok" : 1
}
 
> db.stacks.find({published: true});
error: { "$err" : "assertion src\\mongo\\db\\fts\\fts_index.cpp:55" }

Participants:

 Description   

1) add a full-text index that includes a boolean or integer field, either before or after the full text index.
2) perform a regular .find() query that filters on the boolean field
3) error:

{ "$err" : "assertion src\\mongo\\db\\fts\\fts_index.cpp:55" }

 Comments   
Comment by Michael Mikhjian [ 11/Jul/13 ]

Also had this same issue via v2.4.5

Comment by J Rassi [ 17/May/13 ]

Fixed in SERVER-8791 refactor.

Comment by Will Shaver [ 19/Apr/13 ]

@Jason - that's a bit simpler! Glad to see that you were able to reproduce the problem.

Comment by J Rassi [ 19/Apr/13 ]

Reproduce with:

db.dropDatabase();
db.c.ensureIndex({foo:"text",bar:1});
db.c.findOne({bar:1})

or

db.dropDatabase();
db.c.ensureIndex({bar:1,foo:"text"});
db.c.findOne({bar:1})

For the above queries, QueryPlanGenerator::addFallbackPlans() is returning a plan that uses the text index, which should not happen.

Comment by Will Shaver [ 18/Apr/13 ]

A temporary fix for others who hit this issue: place an exact match index before the text index:

> db.stacks.getIndexes()
[
        {
                "v" : 1,
                "key" : {
                        "_id" : 1
                },
                "ns" : "unit_test.stacks",
                "name" : "_id_"
        },
        {
                "v" : 1,
                "key" : {
                        "published" : 1
                },
                "ns" : "unit_test.stacks",
                "name" : "published_1",
                "background" : true,
                "safe" : null
        },
        {
                "v" : 1,
                "key" : {
                        "_fts" : "text",
                        "_ftsx" : 1,
                        "published" : 1
                },
                "ns" : "unit_test.stacks",
                "name" : "textIndex",
                "background" : true,
                "safe" : null,
                "weights" : {
                        "name" : 1
                },
                "default_language" : "english",
                "language_override" : "language",
                "textIndexVersion" : 1
        }
]

Comment by Will Shaver [ 18/Apr/13 ]

Excuse the gibberish content of the db, that's generated from a unit test.

Generated at Thu Feb 08 03:20:18 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.