[SERVER-78672] Expression::optimize() is used incorrectly when trying to convert $group to streaming for time-series Created: 05/Jul/23  Updated: 29/Oct/23  Resolved: 19/Jul/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.1.0-rc0

Type: Improvement Priority: Major - P3
Reporter: David Storch Assignee: Foteini Alvanaki
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Execution
Backwards Compatibility: Fully Compatible
Sprint: QE 2023-08-07
Participants:

 Description   

This line of code incorrectly discards the return value. It's written like so:

idFields[i]->optimize();  // We optimize here to make use of constant folding.

But it should be this:

idFields[i] = idFields[i]->optimize();  // We optimize here to make use of constant folding.

The reason is that the Expression::optimize() function does not optimize the expression in place but rather returns a pointer to the optimized expression.

While we're at it, we should consider adding the "[[nodiscard]]" attribute to Expression::optimize() in order to try to prevent this kind of mistake in the future.



 Comments   
Comment by Githook User [ 18/Jul/23 ]

Author:

{'name': 'Foteini Alvanaki', 'email': 'foteini.alvanaki@mongodb.com', 'username': ''}

Message: SERVER-78672 Do not discard the return value of Expression::optimize()
Branch: master
https://github.com/mongodb/mongo/commit/64203084ed7b0ad348e90867e415ceeed0e171ed

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