[SERVER-59059] Implement missing optimizations for $set* expressions Created: 03/Aug/21  Updated: 09/Feb/22  Resolved: 09/Feb/22

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

Type: Improvement Priority: Major - P3
Reporter: Rui Liu Assignee: Rui Liu
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-58875 Implement missing optimizations for $... Closed
Related
Sprint: QE 2021-08-23, QE 2021-10-18, QE 2021-11-01, QE 2021-11-15, QE 2021-11-29, QE 2021-12-13, QE 2021-12-27, QE 2022-01-10, QE 2022-02-07, QE 2022-02-21, QE 2022-01-24
Participants:

 Description   

We have observed two performance improvements for set related expression:

  1. Use unordered sets instead of ordered sets
  2. Cache constant sets to avoid the set building

These two optimizations have been implemented for $setIsSubset expression, but not for other expressions.

One problem for porting these optimization to other set expression is using unordered sets causes the set element order being non deterministic. These can fail the fuzzer tests also may result in cascading non-deterministic expression values. (e.g. $group on $setIntersection). Note that this is not a problem for $setIsSubset expression since it's of boolean value. See related tickets https://jira.mongodb.org/browse/SERVER-58875 and https://jira.mongodb.org/browse/TIG-3254 for some context.

We have the following potential proposals:

  1. Sort the set expression values before return to ensure a consistent order
  2. Let the expression be non-deterministic, fix the fuzzer by either not generating set expressions or by other more complicated mechanisms.


 Comments   
Comment by Rui Liu [ 05/Nov/21 ]

$setEquals also returns boolean so we can implement all the optimizations for it.

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