RUN-AS-IF-FOSS: SQL set operators INTERSECT and EXCEPT
What does this MR do?
Provides the ability to SQL INTERSECT
and EXCEPT
like we already have with UNION
.
The initial use case is to improve performance on queries that depend on the overlap of multiple namespace hierarchies.
For example, to improve the use case of:
hierarchies1 = query_with_lots_of_groups
hierarchies2 = query_with_lots_of_groups
hierarchies1.where(id: hierarchies2)
The INTERSECT
operator improved query performance from 1 minute down to 2.9 seconds!
There were significant dependencies on existing derivatives of Gitlab::SQL::Union
, FromUnion
, #from_union
class and method names which I did not want to change. I ended up having to meta-program in app/models/concerns/from_set_operator.rb
which I could not avoid despite my efforts to keep things simple. FWIW I did try a few other methods first before I settled on this. I am happy to hear of a more simple solution.
Screenshots
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team