[SERVER-12531] $not expression inside $elemMatch causes assertion error Created: 29/Jan/14  Updated: 11/Jul/16  Resolved: 04/Feb/14

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.5.5
Fix Version/s: 2.6.0-rc0

Type: Bug Priority: Major - P3
Reporter: Samantha Ritter (Inactive) Assignee: hari.khalsa@10gen.com
Resolution: Done Votes: 0
Labels: query
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

mac os x


Attachments: File elemmatch_not.js     File elemmatch_not_v2.js    
Issue Links:
Depends
is depended on by SERVER-12532 Negate index bounds for $not instead ... Closed
Related
related to SERVER-13307 Server crash when a predicate inside ... Closed
Operating System: OS X
Participants:

 Description   

 { a: { $elemMatch: { $gt:4, $not: { $gte:6 } } } } 

A query like the one above that runs $not inside of an $elemMatch expression will cause the db to verify(0) when it attempts to build index bounds for the query.

Assertion failure 0 src/mongo/db/query/index_bounds_builder.cpp 447
0x10063f1fb 0x1005f7fc2 0x1005e8a12 0x10037aaa7 0x100379256 0x10039cfd8 0x10039da8b 0x1003a92c8 0x100370306 0x100370f2e 0x1002b25cd 0x10019dd04 0x100198ba5 0x1001997fd 0x10019a41c 0x100386573 0x1002630f6 0x100006f24 0x1006056b1 0x100673e55 
 0   mongod                              0x000000010063f1fb _ZN5mongo15printStackTraceERSo + 43
 1   mongod                              0x00000001005f7fc2 _ZN5mongo10logContextEPKc + 114
 2   mongod                              0x00000001005e8a12 _ZN5mongo12verifyFailedEPKcS1_j + 274
 3   mongod                              0x000000010037aaa7 _ZN5mongo18IndexBoundsBuilder9translateEPKNS_15MatchExpressionERKNS_11BSONElementERKNS_10IndexEntryEPNS_19OrderedIntervalListEPNS0_15BoundsTightnessE + 6605
 4   mongod                              0x0000000100379256 _ZN5mongo18IndexBoundsBuilder9translateEPKNS_15MatchExpressionERKNS_11BSONElementERKNS_10IndexEntryEPNS_19OrderedIntervalListEPNS0_15BoundsTightnessE + 380
 5   mongod                              0x000000010039cfd8 _ZN5mongo18QueryPlannerAccess12makeLeafNodeERKNS_14CanonicalQueryERKNS_10IndexEntryEPNS_15MatchExpressionEPNS_18IndexBoundsBuilder15BoundsTightnessE + 1984
 6   mongod                              0x000000010039da8b _ZN5mongo18QueryPlannerAccess22buildIndexedDataAccessERKNS_14CanonicalQueryEPNS_15MatchExpressionEbRKSt6vectorINS_10IndexEntryESaIS7_EE + 285
 7   mongod                              0x00000001003a92c8 _ZN5mongo12QueryPlanner4planERKNS_14CanonicalQueryERKNS_18QueryPlannerParamsEPSt6vectorIPNS_13QuerySolutionESaIS9_EE + 9246
 8   mongod                              0x0000000100370306 _ZN5mongo9getRunnerEPNS_10CollectionEPNS_14CanonicalQueryEPPNS_6RunnerEm + 3094
 9   mongod                              0x0000000100370f2e _ZN5mongo9getRunnerEPNS_14CanonicalQueryEPPNS_6RunnerEm + 158
 10  mongod                              0x00000001002b25cd _ZN5mongo8runCountERKSsRKNS_7BSONObjERSsRi + 1485
 11  mongod                              0x000000010019dd04 _ZN5mongo8CmdCount3runERKSsRNS_7BSONObjEiRSsRNS_14BSONObjBuilderEb + 296
 12  mongod                              0x0000000100198ba5 _ZN5mongo12_execCommandEPNS_7CommandERKSsRNS_7BSONObjEiRSsRNS_14BSONObjBuilderEb + 37
 13  mongod                              0x00000001001997fd _ZN5mongo7Command11execCommandEPS0_RNS_6ClientEiPKcRNS_7BSONObjERNS_14BSONObjBuilderEb + 2593
 14  mongod                              0x000000010019a41c _ZN5mongo12_runCommandsEPKcRNS_7BSONObjERNS_11_BufBuilderINS_16TrivialAllocatorEEERNS_14BSONObjBuilderEbi + 1388
 15  mongod                              0x0000000100386573 _ZN5mongo11newRunQueryERNS_7MessageERNS_12QueryMessageERNS_5CurOpES1_ + 1843
 16  mongod                              0x00000001002630f6 _ZN5mongo16assembleResponseERNS_7MessageERNS_10DbResponseERKNS_11HostAndPortE + 1958
 17  mongod                              0x0000000100006f24 _ZN5mongo16MyMessageHandler7processERNS_7MessageEPNS_21AbstractMessagingPortEPNS_9LastErrorE + 308
 18  mongod                              0x00000001006056b1 _ZN5mongo17PortMessageServer17handleIncomingMsgEPv + 1681
 19  mongod                              0x0000000100673e55 thread_proxy + 229
2014-01-29T14:46:52.282-0500 count failed: {
	"errmsg" : "exception: assertion src/mongo/db/query/index_bounds_builder.cpp:447",
	"code" : 0,
	"ok" : 0
} at src/mongo/shell/query.js:188



 Comments   
Comment by Steve Duan [ 21/Mar/14 ]

I'm still seeing this with the latest code 2.7.0-pre.
2014-03-21T12:17:16.416-0400 [conn29] test.correctness0.878168563729 Assertion failure 0 src/mongo/db/query/index_bounds_builder.cpp 543
2014-03-21T12:17:16.431-0400 [conn29] test.correctness0.878168563729 0xe7ede3 0xe312d5 0xe17f42 0xb700d3 0xb6ee3a 0xb996b4 0xb99f86 0xbaae1b 0x9c2adf 0x9c4143 0x9c5aad 0x9b4529 0xb92dfe 0xb7ce74 0xa550e0 0x7a79e2 0xe4172d 0x7f5129a87efc 0x7f5129020f8d
bin/mongod(_ZN5mongo15printStackTraceERSo+0x23) [0xe7ede3]
bin/mongod(_ZN5mongo10logContextEPKc+0x1a5) [0xe312d5]
bin/mongod(_ZN5mongo12verifyFailedEPKcS1_j+0xc2) [0xe17f42]
bin/mongod(_ZN5mongo18IndexBoundsBuilder9translateEPKNS_15MatchExpressionERKNS_11BSONElementERKNS_10IndexEntryEPNS_19OrderedIntervalListEPNS0_15BoundsTightnessE+0x1493) [0xb700d3]
bin/mongod(_ZN5mongo18IndexBoundsBuilder9translateEPKNS_15MatchExpressionERKNS_11BSONElementERKNS_10IndexEntryEPNS_19OrderedIntervalListEPNS0_15BoundsTightnessE+0x1fa) [0xb6ee3a]
bin/mongod(_ZN5mongo18QueryPlannerAccess12makeLeafNodeERKNS_14CanonicalQueryERKNS_10IndexEntryEmPNS_15MatchExpressionEPNS_18IndexBoundsBuilder15BoundsTightnessE+0x524) [0xb996b4]
bin/mongod(_ZN5mongo18QueryPlannerAccess22buildIndexedDataAccessERKNS_14CanonicalQueryEPNS_15MatchExpressionEbRKSt6vectorINS_10IndexEntryESaIS7_EE+0x2a6) [0xb99f86]
bin/mongod(_ZN5mongo12QueryPlanner4planERKNS_14CanonicalQueryERKNS_18QueryPlannerParamsEPSt6vectorIPNS_13QuerySolutionESaIS9_EE+0x1e2b) [0xbaae1b]
bin/mongod(ZN5mongo21SortStageKeyGenerator16getBoundsForSortERKNS_7BSONObjES3+0x21f) [0x9c2adf]
bin/mongod(ZN5mongo21SortStageKeyGeneratorC2ERKNS_7BSONObjES3+0x8f3) [0x9c4143]
bin/mongod(_ZN5mongo9SortStage4workEPm+0x31d) [0x9c5aad]
bin/mongod(_ZN5mongo7OrStage4workEPm+0x189) [0x9b4529]
bin/mongod(_ZN5mongo12PlanExecutor7getNextEPNS_7BSONObjEPNS_7DiskLocE+0xde) [0xb92dfe]
bin/mongod(ZN5mongo11newRunQueryERNS_7MessageERNS_12QueryMessageERNS_5CurOpES1+0xc24) [0xb7ce74]
bin/mongod(_ZN5mongo16assembleResponseERNS_7MessageERNS_10DbResponseERKNS_11HostAndPortE+0xbf0) [0xa550e0]
bin/mongod(_ZN5mongo16MyMessageHandler7processERNS_7MessageEPNS_21AbstractMessagingPortEPNS_9LastErrorE+0x92) [0x7a79e2]
bin/mongod(_ZN5mongo17PortMessageServer17handleIncomingMsgEPv+0x4cd) [0xe4172d]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x7efc) [0x7f5129a87efc]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x6d) [0x7f5129020f8d]
2014-03-21T12:17:16.432-0400 [conn29] assertion 0 assertion src/mongo/db/query/index_bounds_builder.cpp:543 ns:test.correctness0.878168563729 query:{ $query: { 2: { $elemMatch:

{ $size: 5, $nin: [ "b" ] }

} }, $orderby:

{ 2: -1, A: 1 }

}
2014-03-21T12:17:16.432-0400 [conn29] ntoskip:0 ntoreturn:299
2014-03-21T12:17:16.436-0400 [conn29] end connection 127.0.0.1:48216 (0 connections now open)
2014-03-21T12:17:45.457-0400 [clientcursormon] mem (MB) res:61 virt:683
2014-03-21T12:17:45.457-0400 [clientcursormon] mapped (incl journal view):480
2014-03-21T12:17:45.457-0400 [clientcursormon] connections:0

Comment by Githook User [ 04/Feb/14 ]

Author:

{u'username': u'hkhalsa', u'name': u'Hari Khalsa', u'email': u'hkhalsa@10gen.com'}

Message: SERVER-12531 can appear in an elemMatch(value) and we should generate bounds in that case
Branch: master
https://github.com/mongodb/mongo/commit/3eec306f42739fc2098c8cd8dc278c54e3376806

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