[SERVER-7804] compareElementValues for CodeWScope is broken Created: 29/Nov/12  Updated: 23/Jan/15  Resolved: 09/Jan/15

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

Type: Bug Priority: Major - P3
Reporter: Mathias Stearn Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Tested
Backwards Compatibility: Minor Change
Operating System: ALL
Participants:

 Description   

f = strcmp( l.codeWScopeScopeDataUnsafe() , r.codeWScopeScopeDataUnsafe() );

1) codeWScopeScopeDataUnsafe is deprecated because it is broken
2) strcmp stops at the first NUL byte, which is (almost) guaranteed to be within the BSON size int.
3) Ideally the comparison wouldn't depend on having the scope serialized to BSON. A simple solution would be to just use the normal BSONObj::woCompare to compare the scopes.
4) (added later) The code part is also compared with strcmp rather than memcmp.

Unfortunately this requires an index rev bump to fix since someone (probably mistakenly) might have indexed a field containing CodeWScope.



 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 Mathias Stearn [ 29/Nov/12 ]

Related: if we are going to change the compare order for CodeWScope, we should also give it the same canonicalType as Code so that a CodeWScope with an empty scope compares equal to a regular Code with the same text.

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