[SERVER-20347] Document is not found when searching on a field indexed by a hash index using a $in clause with regular expression Created: 10/Sep/15  Updated: 13/Oct/15  Resolved: 14/Sep/15

Status: Closed
Project: Core Server
Component/s: Index Maintenance, Querying
Affects Version/s: 3.0.6
Fix Version/s: 3.0.7, 3.1.8

Type: Bug Priority: Minor - P4
Reporter: Felipe Albrecht Assignee: Daniel Pasette (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File server-20347.js    
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Completed:
Steps To Reproduce:

db.genes.insert({   "_id": "gn22",   "D": 3,   "C": "chr1",   "O": "ENSEMBL",   "T": "gene",   "S": 200880,   "E": 201017,   "R": 1.1754943508222875e-38,   "N": 43,   "M": 46,   "I": {     "gene_id": "ENSG00000275135.1",     "gene_type": "miRNA",     "gene_status": "NOVEL",     "gene_name": "FO538757.1",     "level": "3"   } })
Inserted 1 record(s) in 160ms
WriteResult({
  "nInserted": 1
})
 
db.genes.find({gene})
 
// Simple search with regular expression: OKAY
db.genes.find({"I.gene_name": /FO538757/i})
{
  "_id": "gn22",
  "D": 3,
  "C": "chr1",
  "O": "ENSEMBL",
  "T": "gene",
  "S": 200880,
  "E": 201017,
  "R": 1.1754943508222875e-38,
  "N": 43,
  "M": 46,
  "I": {
    "gene_id": "ENSG00000275135.1",
    "gene_type": "miRNA",
    "gene_status": "NOVEL",
    "gene_name": "FO538757.1",
    "level": "3"
  }
}
 
// Search with $in and regular expression without index: OKAY
db.genes.find({"I.gene_name": {$in: [/FO538757/i]}})
{
  "_id": "gn22",
  "D": 3,
  "C": "chr1",
  "O": "ENSEMBL",
  "T": "gene",
  "S": 200880,
  "E": 201017,
  "R": 1.1754943508222875e-38,
  "N": 43,
  "M": 46,
  "I": {
    "gene_id": "ENSG00000275135.1",
    "gene_type": "miRNA",
    "gene_status": "NOVEL",
    "gene_name": "FO538757.1",
    "level": "3"
  }
}
 
// Create index: OKAY
db.genes.ensureIndex({"I.gene_name":"hashed"})
{
  "createdCollectionAutomatically": false,
  "numIndexesBefore": 1,
  "numIndexesAfter": 2,
  "ok": 1
}
 
// Search on a simple search and HASHED INDEX: OKAY
db.genes.find({"I.gene_name": /FO538757/i})
{
  "_id": "gn22",
  "D": 3,
  "C": "chr1",
  "O": "ENSEMBL",
  "T": "gene",
  "S": 200880,
  "E": 201017,
  "R": 1.1754943508222875e-38,
  "N": 43,
  "M": 46,
  "I": {
    "gene_id": "ENSG00000275135.1",
    "gene_type": "miRNA",
    "gene_status": "NOVEL",
    "gene_name": "FO538757.1",
    "level": "3"
  }
}
 
// Search with $in and regular expression AND HeASHED INDEX: Not found :-(
db.genes.find({"I.gene_name": {$in: [/FO538757/i]}})
Fetched 0 record(s) in 1ms
 
// Dropping the index
db.genes.dropIndex({"I.gene_name": "hashed"})
{
  "nIndexesWas": 2,
  "ok": 1
}
 
// Search with $in and regular expression after dropped the index: Okay
db.genes.find({"I.gene_name": {$in: [/FO538757/i]}})
{
  "_id": "gn22",
  "D": 3,
  "C": "chr1",
  "O": "ENSEMBL",
  "T": "gene",
  "S": 200880,
  "E": 201017,
  "R": 1.1754943508222875e-38,
  "N": 43,	
  "M": 46,
  "I": {
    "gene_id": "ENSG00000275135.1",
    "gene_type": "miRNA",
    "gene_status": "NOVEL",
    "gene_name": "FO538757.1",
    "level": "3"
  }
}

Sprint: Quint 9 09/18/15
Participants:

 Description   

I have a collection, where I index one of the fields with the hash index.
No results are found when I perform a search on this field using $in with regular expression.

-
Extras:
If I used the "normal" index, the command finds the document.
I only tested with the out of the box configurations: Get mongodb, uncompress, execute mongod, open mongo shell.



 Comments   
Comment by Githook User [ 14/Sep/15 ]

Author:

{u'username': u'monkey101', u'name': u'Dan Pasette', u'email': u'dan@10gen.com'}

Message: SERVER-20347 $in containing a regex element cannot use a hashed index
Branch: v3.0
https://github.com/mongodb/mongo/commit/ce95ed2034a9f609ccd5da181d915cc2f8b041a1

Comment by Githook User [ 14/Sep/15 ]

Author:

{u'username': u'monkey101', u'name': u'Dan Pasette', u'email': u'dan@10gen.com'}

Message: SERVER-20347 $in containing a regex element cannot use a hashed index
Branch: master
https://github.com/mongodb/mongo/commit/fd23b6ac8500f5d8ef759e0a1064f5f396a1fcc2

Comment by Sam Kleinman (Inactive) [ 11/Sep/15 ]

Thanks so much for the report, and sorry that you've hit this issue. I've reproduced this issue and have minimized your reproduction case. I'm passing this ticket along to our query group for triage and more analysis.

Thanks again.

Regards,
sam

Comment by Felipe Albrecht [ 10/Sep/15 ]

One small comment: The search also works if there is the normal AND hashed index.

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