[SERVER-3304] Change comparison order so all Dates sort before all Timestamps Created: 21/Jun/11  Updated: 27/Oct/15  Resolved: 09/Jan/15

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: 2.8.0-rc5

Type: Bug Priority: Critical - P2
Reporter: Aaron Staple Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: query_triage
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File server3304.js    
Issue Links:
Depends
is depended on by CSHARP-1089 Test against non-mmapv1 storage engine Closed
Documented
is documented by DOCS-4650 Update documentation to reflect order... Closed
Duplicate
duplicates SERVER-8386 Compare Date vs timestamp errors out,... Closed
is duplicated by SERVER-8010 Query anomaly with Date and Timestamp Closed
is duplicated by SERVER-11530 timestamp vs. date errors Closed
is duplicated by SERVER-12450 {$type: 17} with _id as date causes e... Closed
is duplicated by SERVER-16510 WiredTiger Crash when inserting docum... Closed
is duplicated by SERVER-17321 Querying for timestamp against date f... Closed
is duplicated by SERVER-7141 Consider making timestamp and date no... Closed
Related
is related to SERVER-7141 Consider making timestamp and date no... Closed
Tested
Backwards Compatibility: Minor Change
Operating System: ALL
Steps To Reproduce:

var t = db.server3304;
 
// this will cause an assertion in the mongod process
t.drop();
t.save({a: new Date(0)});
t.find({a: new Timestamp()});

Participants:

 Description   

Queries (including range queries) on one type will no longer match values of the other type. Previously the comparison depended on which type was on the left hand side, which is incompatible with a total ordering.

Original title: mongod assertion when attempt is made to compare a Date to a Timestamp

The assertion will happen when the collection contains a Date and the query filter is using a Timestamp, but not the other way around.

Here's the assertion and stack trace from a mongod running version 2.4.7.

Fri Nov  1 09:54:12.974 [conn2] Assertion: 13111:wrong type for field (a) 17 != 9
0x10044c66b 0x10042601e 0x1004260dd 0x100401380 0x10005ce97 0x1002227ec 0x100218a03 0x1002191da 0x1002236c2 0x1002238e0 0x10019b3f0 0x100239e0f 0x10014d796 0x100147ae5 0x100148a0c 0x1001492dc 0x10024093e 0x10024113f 0x1001ee28f 0x10000b802 
 0   mongod                              0x000000010044c66b _ZN5mongo15printStackTraceERSo + 43
 1   mongod                              0x000000010042601e _ZN5mongo11msgassertedEiPKc + 174
 2   mongod                              0x00000001004260dd _ZN5mongo11msgassertedEiRKSs + 29
 3   mongod                              0x0000000100401380 _ZNK5mongo11BSONElement3chkEi + 800
 4   mongod                              0x000000010005ce97 _ZN5mongo20compareElementValuesERKNS_11BSONElementES2_ + 679
 5   mongod                              0x00000001002227ec _ZNK5mongo7Matcher11valuesMatchERKNS_11BSONElementES3_iRKNS_14ElementMatcherE + 100
 6   mongod                              0x0000000100218a03 _ZNK5mongo7Matcher13matchesDottedEPKcRKNS_11BSONElementERKNS_7BSONObjEiRKNS_14ElementMatcherEbPNS_12MatchDetailsE + 3459
 7   mongod                              0x00000001002191da _ZNK5mongo7Matcher7matchesERKNS_7BSONObjEPNS_12MatchDetailsE + 314
 8   mongod                              0x00000001002236c2 _ZNK5mongo19CoveredIndexMatcher7matchesERKNS_7BSONObjERKNS_7DiskLocEPNS_12MatchDetailsEb + 450
 9   mongod                              0x00000001002238e0 _ZNK5mongo19CoveredIndexMatcher14matchesCurrentEPNS_6CursorEPNS_12MatchDetailsE + 212
 10  mongod                              0x000000010019b3f0 _ZN5mongo6Cursor14currentMatchesEPNS_12MatchDetailsE + 56
 11  mongod                              0x0000000100239e0f _ZN5mongo8runCountEPKcRKNS_7BSONObjERSsRi + 1455
 12  mongod                              0x000000010014d796 _ZN5mongo8CmdCount3runERKSsRNS_7BSONObjEiRSsRNS_14BSONObjBuilderEb + 268
 13  mongod                              0x0000000100147ae5 _ZN5mongo12_execCommandEPNS_7CommandERKSsRNS_7BSONObjEiRSsRNS_14BSONObjBuilderEb + 37
 14  mongod                              0x0000000100148a0c _ZN5mongo7Command11execCommandEPS0_RNS_6ClientEiPKcRNS_7BSONObjERNS_14BSONObjBuilderEb + 2516
 15  mongod                              0x00000001001492dc _ZN5mongo12_runCommandsEPKcRNS_7BSONObjERNS_11_BufBuilderINS_16TrivialAllocatorEEERNS_14BSONObjBuilderEbi + 1036
 16  mongod                              0x000000010024093e _ZN5mongo11runCommandsEPKcRNS_7BSONObjERNS_5CurOpERNS_11_BufBuilderINS_16TrivialAllocatorEEERNS_14BSONObjBuilderEbi + 46
 17  mongod                              0x000000010024113f _ZN5mongo8runQueryERNS_7MessageERNS_12QueryMessageERNS_5CurOpES1_ + 1551
 18  mongod                              0x00000001001ee28f _ZN5mongo16assembleResponseERNS_7MessageERNS_10DbResponseERKNS_11HostAndPortE + 1519
 19  mongod                              0x000000010000b802 _ZN5mongo16MyMessageHandler7processERNS_7MessageEPNS_21AbstractMessagingPortEPNS_9LastErrorE + 198
Fri Nov  1 09:54:12.991 [conn2] Count with ns: test.server3304 and query: { a: Timestamp 0|0 } failed with exception: 13111 wrong type for field (a) 17 != 9 code: 13111



 Comments   
Comment by Githook User [ 07/Jan/15 ]

Author:

{u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

Message: Make BSONObj::woCompare a total ordering

Changes:

  • Date and Timestamp are now distinct with all Dates before all Timestamps.
  • Numeric comparisons now correctly handle Doubles and Long > 2**53.
  • CodeWScope doesn't strcmp BSONObjs or strings which may contain NULs.

There should be no changes in any of the cases where woCompare defined a
correct total ordering before. The new behavior matches the ordering defined
by KeyString.

Related tickets:

Changes to the comparison function for aggregation will be handled separately
as SERVER-16708.
Branch: master
https://github.com/mongodb/mongo/commit/f58fa5f78a91ce36d8e31d6730ebfdaa6cc1d5ab

Comment by Githook User [ 01/Oct/14 ]

Author:

{u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

Message: SERVER-3304 Clean up index between inserting a Timestamp and a Date

This should be unnecessary once SERVER-3304 is resolved.
Branch: master
https://github.com/mongodb/mongo/commit/017d360814e366b7c2a91b2320b45db49d158358

Comment by Githook User [ 01/Oct/14 ]

Author:

{u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

Message: SERVER-3304 Clean up index between inserting a Timestamp and a Date

This should be unnecessary once SERVER-3304 is resolved.
Branch: master
https://github.com/mongodb/mongo/commit/017d360814e366b7c2a91b2320b45db49d158358

Comment by Michael Cahill [ 03/Sep/14 ]

Is https://github.com/mongodb/mongo/pull/764 a reasonable way to address this issue?

It is causing problems in testing the WiredTiger storage engine because the type3.js test causes comparison between a Date and a Timestamp.

Thanks!

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