[SERVER-57321] $mod match expression incorrectly handles NaN, Infinity and large values Created: 01/Jun/21  Updated: 29/Oct/23  Resolved: 25/Aug/21

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 5.0.0-rc7, 5.1 Required
Fix Version/s: 4.4.10, 5.0.4, 5.1.0-rc0

Type: Bug Priority: Major - P3
Reporter: Mindaugas Malinauskas Assignee: Mihai Andrei
Resolution: Fixed Votes: 0
Labels: sbe-diff, sbe-rollout
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Documented
is documented by DOCS-14662 Investigate changes in SERVER-57321: ... Closed
Duplicate
is duplicated by SERVER-58188 Inconsistency between the classic eng... Closed
Problem/Incident
causes SERVER-58874 Coverity analysis defect 120344: Oper... Closed
Related
Backwards Compatibility: Minor Change
Operating System: ALL
Backport Requested:
v5.0, v4.4, v4.2, v4.0
Steps To Reproduce:

db.coll.remove({});
db.coll.insert({
		"_id" : 1000907,
		"obj" : {
			"obj" : {
				"num" : NaN,
			}
		}
	});
db.coll.aggregate([
	{
		"$match" : {
			"obj.obj.num" : {
				"$mod" : [
					NumberDecimal("9.999999999999999999999999999999999E+6144"),
					NumberLong(0)
				]
			}
		}
	}
])

Result:
Classic: one document in "coll" collection.
SBE: empty set of documents.

Sprint: Query Execution 2021-07-12, Query Execution 2021-07-26, QE 2021-09-06
Participants:
Linked BF Score: 163

 Description   

In classic variant of query execution $mod match expression (ModMatchExpression) interprets dividend value NaN (double) as -9223372036854775808 64-bit integer. In SBE, on the other hand, NaN to 64-bit integer transformation results in Nothing.  Furthermore, NumberDecimal("9.999999999999999999999999999999999E+6144") gets interpreted as NumberLong("-9223372036854775808") (classic and SBE). Those two factors, when combined, give unexpected results.  Please see "Steps to Reproduce".

 



 Comments   
Comment by Vivian Ge (Inactive) [ 06/Oct/21 ]

Updating the fixversion since branching activities occurred yesterday. This ticket will be in rc0 when it’s been triggered. For more active release information, please keep an eye on #server-release. Thank you!

Comment by Githook User [ 27/Sep/21 ]

Author:

{'name': 'Mihai Andrei', 'email': 'mihai.andrei@10gen.com', 'username': 'mtandrei'}

Message: SERVER-57321 Make $mod match expression handle NaN, Infinity and large values

(cherry picked from commit 23e56121a014719f0dd29d27a60a72a0e11dac10)
(cherry picked from commit b9e15d31f7cc46fe2581545ce7c5ebaeb04cfea5)
(cherry picked from commit ed1231808d79d17952a0cc39e7180892fed5b72b)

Co-authored-by: Mihai Andrei <mihai.andrei@mongodb.com>
Branch: v4.4
https://github.com/mongodb/mongo/commit/f0e4e7f892e3354c99908bf17926412e2229abeb

Comment by Githook User [ 20/Sep/21 ]

Author:

{'name': 'Mindaugas Malinauskas', 'email': 'mindaugas.malinauskas@mongodb.com'}

Message: SERVER-57321 Make $mod match expression handle NaN, Infinity and large values

(cherry picked from commit 23e56121a014719f0dd29d27a60a72a0e11dac10)
(cherry picked from commit b9e15d31f7cc46fe2581545ce7c5ebaeb04cfea5)

Co-authored-by: Mihai Andrei <mihai.andrei@mongodb.com>
Branch: v5.0
https://github.com/mongodb/mongo/commit/ed1231808d79d17952a0cc39e7180892fed5b72b

Comment by Githook User [ 25/Aug/21 ]

Author:

{'name': 'Mihai Andrei', 'email': 'mihai.andrei@10gen.com', 'username': 'mtandrei'}

Message: SERVER-57321 ModMatchExpression returns false when dividend cannot be represented as a valid integer
Branch: master
https://github.com/mongodb/mongo/commit/b9e15d31f7cc46fe2581545ce7c5ebaeb04cfea5

Comment by Kyle Suarez [ 20/Aug/21 ]

Sending this to Mihai to get it over the line next sprint while Mindaugas is on holiday.

Comment by Githook User [ 20/Jul/21 ]

Author:

{'name': 'Mindaugas Malinauskas', 'email': 'mindaugas.malinauskas@mongodb.com'}

Message: SERVER-57321 Make $mod match expression handle NaN, Infinity and large values
Branch: master
https://github.com/mongodb/mongo/commit/23e56121a014719f0dd29d27a60a72a0e11dac10

Comment by Kyle Suarez [ 25/Jun/21 ]

Right, they are a checklist, not alternatives. I agree, an attempt to cast an unrepresentable value to uint64 should be an error.

Comment by Mindaugas Malinauskas [ 25/Jun/21 ]

kyle.suarez, shouldn't we address the problem #2 in the comment

Comment by Kyle Suarez [ 25/Jun/21 ]

mindaugas.malinauskas, if going with option 1 would make the classic engine match SBE, then I think that's the most sensible thing to do. It does seem like a bug in the classic engine to me.

Comment by Mindaugas Malinauskas [ 01/Jun/21 ]

This is a root cause of BF-21240.

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