[SERVER-74264] Incorrect $$NOW behavior in projection of find Created: 22/Feb/23 Updated: 29/Oct/23 Resolved: 21/Mar/23 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 6.3.0-rc0 |
| Fix Version/s: | 7.0.0-rc0, 6.3.0-rc2 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Militsa Sotirova | Assignee: | Zixuan Zhuang |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||||||||||||
| Operating System: | ALL | ||||||||||||||||||||||||||
| Backport Requested: |
v6.3
|
||||||||||||||||||||||||||
| Steps To Reproduce: | Start up a mongod on master with featureFlagSbeFull enabled. (Note that we do not see this behavior when the flag is not enabled.) Here is an example of the commands I used to get this behavior:
I called new Date() between the two find commands to show that time had indeed passed before I ran the second one. Example where the projected field name differs (time1 and time2) and the time is different:
|
||||||||||||||||||||||||||
| Sprint: | QE 2023-03-06, QE 2023-03-20, QE 2023-04-03 | ||||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||||
| Description |
|
When featureFlagSbeFull is enabled, $$NOW evaluates to the same value across two consecutive find commands when it is present in the projection part of the command (for example, db.coll.findOne({}, {time: "$$NOW"})). I suspect that this is because when we cache the plan for the first query to use for the second, we save the actual value that $$NOW evaluates to, not a reference to it. Looking at the log printed at this point, running an example similar to the one below - the log printed for the first find command is
and the log printed for the second one is
You can see that in the second log the value of $$NOW in the env is (correctly) later than that of the first log but the value used in the stages field is still the value from the first log. Another reason I suspect this is because of how we are storing the value in the plan cache is that when we run the same commands but change the projected field name so that it is different in the second one, we see that value of $$NOW changes (since we wouldn't be able to use the cached plan from the first command). See the second example in the steps to reproduce. This may also be the behavior for other system variables. |
| Comments |
| Comment by Githook User [ 21/Mar/23 ] |
|
Author: {'name': 'Zixuan Zhuang', 'email': 'zixuan.zhuang@mongodb.com', 'username': 'leozzx'}Message: |
| Comment by Githook User [ 20/Mar/23 ] |
|
Author: {'name': 'Zixuan Zhuang', 'email': 'zixuan.zhuang@mongodb.com', 'username': 'leozzx'}Message: |