[SERVER-82070] Classic window function $stdDevSamp handles empty window frame incorrectly Created: 11/Oct/23  Updated: 05/Feb/24  Resolved: 11/Oct/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.1.1, 7.2.0-rc0, 5.0.22, 7.0.3, 6.0.12

Type: Bug Priority: Major - P3
Reporter: Rui Liu Assignee: Rui Liu
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v7.1, v7.0, v6.0, v5.0
Participants:
Linked BF Score: 150

 Description   

When the number of documents in the window frame is 0, the adjusted count for $stdDevSamp might be negative, and we should return NULL in this case.

https://github.com/10gen/mongo/blob/fc174d081bdd6a5178cc888e6f0309d23504b4df/src/mongo/db/pipeline/window_function/window_function_stddev.h#L65-L67

$covarianceSamp handles this correctly.

https://github.com/10gen/mongo/blob/fc174d081bdd6a5178cc888e6f0309d23504b4df/src/mongo/db/pipeline/window_function/window_function_covariance.cpp#L96-L98



 Comments   
Comment by Githook User [ 12/Oct/23 ]

Author:

{'name': 'Rui Liu', 'email': 'lriuui0x0@gmail.com', 'username': 'lriuui0x0'}

Message: SERVER-82070 Return default value for $stdDevSamp with empty window

(cherry picked from commit 075e35514569813fad6dfafb0554781cfd109959)
Branch: v7.1
https://github.com/mongodb/mongo/commit/a1022e2465274be0be41c77cf90f646052da5cf7

Comment by Githook User [ 12/Oct/23 ]

Author:

{'name': 'Rui Liu', 'email': 'lriuui0x0@gmail.com', 'username': 'lriuui0x0'}

Message: SERVER-82070 Return default value for $stdDevSamp with empty window

(cherry picked from commit 075e35514569813fad6dfafb0554781cfd109959)
Branch: v6.0
https://github.com/mongodb/mongo/commit/76ba81ff6dbf71535d2ad8029213d2a245f03949

Comment by Githook User [ 12/Oct/23 ]

Author:

{'name': 'Rui Liu', 'email': 'lriuui0x0@gmail.com', 'username': 'lriuui0x0'}

Message: SERVER-82070 Return default value for $stdDevSamp with empty window

(cherry picked from commit 075e35514569813fad6dfafb0554781cfd109959)
Branch: v7.0
https://github.com/mongodb/mongo/commit/f74909c65542088e46238c2119f72eb906e852e1

Comment by Githook User [ 12/Oct/23 ]

Author:

{'name': 'Rui Liu', 'email': 'lriuui0x0@gmail.com', 'username': 'lriuui0x0'}

Message: SERVER-82070 Return default value for $stdDevSamp with empty window

(cherry picked from commit 075e35514569813fad6dfafb0554781cfd109959)
Branch: v5.0
https://github.com/mongodb/mongo/commit/ddb1e08429308c559e4d4fccfc5d7690292bbf7a

Comment by Githook User [ 11/Oct/23 ]

Author:

{'name': 'Rui Liu', 'email': 'lriuui0x0@gmail.com', 'username': 'lriuui0x0'}

Message: SERVER-82070 Return default value for $stdDevSamp with empty window
Branch: master
https://github.com/mongodb/mongo/commit/075e35514569813fad6dfafb0554781cfd109959

Generated at Thu Feb 08 06:48:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.