[SERVER-15015] Assertion failure when combining $max/$min and reverse index scan Created: 25/Aug/14  Updated: 11/Jul/16  Resolved: 29/Aug/14

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.6.4, 2.7.5
Fix Version/s: 2.6.5, 2.7.6

Type: Bug Priority: Major - P3
Reporter: Kamran K. Assignee: David Storch
Resolution: Done Votes: 0
Labels: 28qa
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Duplicate
is duplicated by SERVER-9547 min() / max() with descending order s... Closed
Related
is related to SERVER-9547 min() / max() with descending order s... Closed
Tested
Operating System: ALL
Backport Completed:
Participants:

 Description   
Issue Status as of Sep 02, 2014

ISSUE SUMMARY
Queries combining the $max or $min operators with a reverse index scan on the same field fail producing a stack trace in the log. When run from the shell, an error message is also printed on screen. For example:

db.foo.ensureIndex({a:-1});
db.foo.find().max({a: 4}).sort({a: 1})

produce the following message:

error: { "$err" : "assertion src/mongo/db/query/query_planner_common.h:110" }

USER IMPACT
Queries with these characteristics fail, but they do not affect the server's availability or operation.

WORKAROUNDS
N/A

AFFECTED VERSIONS
MongoDB 2.6 production releases up to 2.6.4 are affected by this issue.

FIX VERSION
The fix is included in the 2.6.5 production release.

RESOLUTION DETAILS
Make $min and $max operators aware of index direction so the right index bounds are computed.

Original description

This bug causes 2.6.0 - 2.7.4 to non-fatally assert and 2.7.5+ to abort.

Backtrace from master (c40a73d76c):

2014-08-25T00:13:23.916-0400 I          [conn1] Invariant failure 0 src/mongo/db/query/query_planner_common.cpp 65
 
Program received signal SIGTRAP, Trace/breakpoint trap.
[Switching to Thread 0x7ffff7fcd700 (LWP 10434)]
0x00007ffff7bcc20b in raise (sig=5) at ../nptl/sysdeps/unix/sysv/linux/pt-raise.c:37
37	../nptl/sysdeps/unix/sysv/linux/pt-raise.c: No such file or directory.
 
(gdb) bt
#0  0x00007ffff7bcc20b in raise (sig=5) at ../nptl/sysdeps/unix/sysv/linux/pt-raise.c:37
#1  0x00000000017a842a in mongo::mongo_breakpoint () at src/mongo/util/debug_util.cpp:58
#2  0x000000000179ec2c in mongo::breakpoint () at src/mongo/util/debug_util.h:73
#3  0x000000000179da9e in mongo::invariantFailed (msg=0x1dd6c74 "0", file=0x1dd6c48 "src/mongo/db/query/query_planner_common.cpp", line=65) at src/mongo/util/assert_util.cpp:142
#4  0x00000000014a5e87 in mongo::QueryPlannerCommon::reverseScans (node=0x2e86270) at src/mongo/db/query/query_planner_common.cpp:65
#5  0x0000000001499b7d in mongo::QueryPlannerAnalysis::analyzeSort (query=..., params=..., solnRoot=0x2e86270, blockingSortOut=0x7ffff7fcaf16) at src/mongo/db/query/planner_analysis.cpp:400
#6  0x000000000149a2cf in mongo::QueryPlannerAnalysis::analyzeDataAccess (query=..., params=..., solnRoot=0x2e86270) at src/mongo/db/query/planner_analysis.cpp:516
#7  0x00000000014a3506 in mongo::QueryPlanner::plan (query=..., params=..., out=0x7ffff7fcbb70) at src/mongo/db/query/query_planner.cpp:595
#8  0x000000000145465b in mongo::(anonymous namespace)::prepareExecution (opCtx=0x7ffff7fccb70, collection=0x2e77880, ws=0x2e60850, canonicalQuery=0x3695300, plannerOptions=0, rootOut=0x7ffff7fcbe50, 
    querySolutionOut=0x7ffff7fcbe58) at src/mongo/db/query/get_executor.cpp:315
#9  0x0000000001455396 in mongo::getExecutor (txn=0x7ffff7fccb70, collection=0x2e77880, rawCanonicalQuery=0x3695300, out=0x7ffff7fcc0e0, plannerOptions=0) at src/mongo/db/query/get_executor.cpp:406
#10 0x000000000146b734 in mongo::newRunQuery (txn=0x7ffff7fccb70, m=..., q=..., curop=..., result=...) at src/mongo/db/query/new_find.cpp:598
#11 0x000000000134ecfc in mongo::receivedQuery (txn=0x7ffff7fccb70, c=..., dbresponse=..., m=...) at src/mongo/db/instance.cpp:263
#12 0x000000000134fdf9 in mongo::assembleResponse (txn=0x7ffff7fccb70, m=..., dbresponse=..., remote=...) at src/mongo/db/instance.cpp:437
#13 0x000000000108a923 in mongo::MyMessageHandler::process (this=0x2e421a8, m=..., port=0x2e5f180, le=0x2e5fb80) at src/mongo/db/db.cpp:198
#14 0x00000000017c46e5 in mongo::PortMessageServer::handleIncomingMsg (arg=0x2e52600) at src/mongo/util/net/message_server_port.cpp:227
#15 0x00007ffff7bc4182 in start_thread (arg=0x7ffff7fcd700) at pthread_create.c:312
#16 0x00007ffff6cc538d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

2.6.4 non-fatal assertion:

Assertion failure 0 src/mongo/db/query/query_planner_common.h 110



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

Author:

{u'username': u'dstorch', u'name': u'David Storch', u'email': u'david.storch@10gen.com'}

Message: SERVER-15015 fix $min/$max handling for descending indices

(cherry picked from commit b365799cde89ffcb255d1950057298f6f724d0c8)
Branch: v2.6
https://github.com/mongodb/mongo/commit/f02059e077337bc769ad0a3c8cc6b6f28ac2f189

Comment by Githook User [ 29/Aug/14 ]

Author:

{u'username': u'dstorch', u'name': u'David Storch', u'email': u'david.storch@10gen.com'}

Message: SERVER-15015 fix $min/$max handling for descending indices
Branch: master
https://github.com/mongodb/mongo/commit/b365799cde89ffcb255d1950057298f6f724d0c8

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