[SERVER-79096] Simplified constant folding and ref tracking under interval simplification Created: 19/Jul/23 Updated: 29/Oct/23 Resolved: 03/Oct/23 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 7.2.0-rc0 |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Timour Katchaounov | Assignee: | Timour Katchaounov |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | M1 | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Assigned Teams: |
Query Optimization
|
| Backwards Compatibility: | Fully Compatible |
| Sprint: | QO 2023-10-02, QO 2023-10-16 |
| Participants: |
| Description |
|
Interval simplification relies on constant folding, which uses heavily reference tracking. Taking into account that interval boundaries are expressions of a specific form, both constant folding and its use of reference tracking can be simplified/optimized to improve optimization performance. svilen.mihaylov@mongodb.com david.percy@mongodb.com I remember discussing some ideas with you, could you please add some notes here? |
| Comments |
| Comment by Githook User [ 03/Oct/23 ] | |||
|
Author: {'name': 'Timour Katchaounov', 'email': 'timour.katchaounov@mongodb.com', 'username': 'timourk'}Message: Before this commit, all comparisons of ABT interval bounds were done via constant folding. However, the input intervals' bounds are already constant folded before we get to do interval simplification. This commit replaces all "simple" comparisons of ABT interval bounds so that instead of going through constant folding, the comparisons use directly SBE value comparison. | |||
| Comment by David Percy [ 19/Jul/23 ] | |||
|
In 'intersectIntervals' we are constant-folding these expressions that come from the input: https://github.com/10gen/mongo/blob/a0866639120c8bdce3eff8c446ea70e982ce1839/src/mongo/db/query/optimizer/utils/interval_utils.cpp#L442-L443 But we're already constant-folding when we construct an interval, so we can do a simple 'is<Constant>()' check when we read the interval. This would also avoid a copy. In the same function, we're using constant folding to compare two expressions with Eq: https://github.com/10gen/mongo/blob/a0866639120c8bdce3eff8c446ea70e982ce1839/src/mongo/db/query/optimizer/utils/interval_utils.cpp#L459-L461. We want to only get 'true' if both arguments are constants, and are equal according to Eq. Instead of constant-folding we could do a more specialized thing where we check 'is<Contant>()' for the arguments and then call the SBE function that implements Eq. A similar thing happens in 'cmpABT':
We can change this to use 'is<Constant>()' and call SBE's 3-way comparison. The behavior would change for inputs that are constant-foldable but not Constant nodes; that's fine because we can move that responsibility to the caller to make sure the inputs are simplified. |