[SERVER-54129] Simplify generated SBE expressions when some arguments are constants Created: 29/Jan/21  Updated: 06/Dec/22

Status: Open
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Anton Korshunov Assignee: Backlog - Query Execution
Resolution: Unresolved Votes: 0
Labels: sbe-post-v1, sbe-rollout
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Execution
Sprint: Query Execution 2021-05-03, Query Execution 2021-05-17, Query Execution 2021-05-31, Query Execution 2021-06-14, Query Execution 2021-06-28, Query Execution 2021-07-12, Query Execution 2021-07-26
Participants:

 Description   

When we translate MQL expressions in SBE, some arguments for these expressions can be constants. In this case we can statically perform all necessary checks on the constant arguments during the stage building phase, rather than doing it in runtime. This should greatly simplify generated SBE expressions. For example, here is an expressions generated for $split: ["$a", " "]:

 

project [s12 = let [l1.0 = s11, l1.1 = " "] if (! exists (l1.1) || typeMatch (l1.1, 0x00000440), null, if (! isString (l1.1), fail ( 5155400 ,$split delimiter must be a string), if (l1.1 == "", fail ( 5155401 ,$split delimiter must not be an empty string), if (! exists (l1.0) || typeMatch (l1.0, 0x00000440), null, if (! isString (l1.0), fail ( 5155402 ,$split string expression must be a string), if (l1.0 == "", [""], split (l1.0, l1.1)))))))]

Note all the checks around slot l1.1 - they're totally redundant.

We need to analyze all expressions in the SBE expression stage builder and optimize them to perform compile time checks for constant arguments.

 



 Comments   
Comment by Kyle Suarez [ 05/Aug/21 ]

Per a discussion with Mihai, bumping this out to the future to wait, in case there are things here that interfere with the plan cache / query parametrization.

Comment by Githook User [ 02/Aug/21 ]

Author:

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

Message: Revert "SERVER-54129 Simplify generated SBE expressions for $mod, $add, and $split when some arguments are constants"

This reverts commit 149c1670828efa6937220ab0e5bc4fa40ed55a1d.
Branch: master
https://github.com/mongodb/mongo/commit/5e65c42c3103ea79e5eabfab315649cd7587d4e6

Comment by Githook User [ 30/Jul/21 ]

Author:

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

Message: SERVER-54129 Simplify generated SBE expressions for $mod, $add, and $split when some arguments are constants
Branch: master
https://github.com/mongodb/mongo/commit/149c1670828efa6937220ab0e5bc4fa40ed55a1d

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