[SERVER-70538] SBE fillEmpty should short circuit Created: 13/Oct/22  Updated: 29/Oct/23  Resolved: 10/Nov/22

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

Type: Improvement Priority: Major - P3
Reporter: David Percy Assignee: Martin Neupauer
Resolution: Fixed Votes: 0
Labels: pm2697-m2
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Problem/Incident
Backwards Compatibility: Fully Compatible
Sprint: QE 2022-10-31, QE 2022-11-14
Participants:
Linked BF Score: 5
Story Points: 5

 Description   

Sometimes the right-hand argument of fillEmpty is a complex expression:

$ mongod --setParameter featureFlagSbeFull=1
...
$ mongo
> db.c.find({$expr: {$eq: ["$a", 42]}}).explain().queryPlanner.winningPlan.slotBasedPlan.stages
...
fillEmpty(((l1.0 <=> l1.1) == 0), ((exists(l1.0) && typeMatch(l1.0, -65)) == (exists(l1.1) && typeMatch(l1.1, -65))))

Ideally when the left argument is non-Nothing, we shouldn't evaluate the right argument.

But currently, fillEmpty is represented as an EFunction, and all EFunctions are expected to be strict. (EFunctions cannot short circuit.) We should introduce an EPrimBinary for fillEmpty, and then compile it similarly to logicOr to jump over the compiled right-hand side.

We can also have special cases when the rhs is EConstant or EVariable (use the existing fillEmpty and fillEmptyImm instructions) and remove the EFunction fillEmpty.



 Comments   
Comment by Githook User [ 10/Nov/22 ]

Author:

{'name': 'Martin Neupauer', 'email': 'martin.neupauer@mongodb.com', 'username': 'MartinNeupauer'}

Message: SERVER-70538 Replace fillEmpty function with a binary operation
Branch: master
https://github.com/mongodb/mongo/commit/e9c34ed06ca402773a01816dff99a462c43e933a

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