BigW Consortium Gitlab
This changes ProjectsFinder#init_collection so it no longer relies on a UNION. For example, to get starred projects of a user we used to run: SELECT projects.* FROM projects WHERE projects.pending_delete = 'f' AND ( projects.id IN ( SELECT projects.id FROM projects INNER JOIN users_star_projects ON users_star_projects.project_id = projects.id INNER JOIN project_authorizations ON projects.id = project_authorizations.project_id WHERE projects.pending_delete = 'f' AND project_authorizations.user_id = 1 AND users_star_projects.user_id = 1 UNION SELECT projects.id FROM projects INNER JOIN users_star_projects ON users_star_projects.project_id = projects.id WHERE projects.visibility_level IN (20, 10) AND users_star_projects.user_id = 1 ) ) ORDER BY projects.id DESC; With these changes the above query is turned into the following instead: SELECT projects.* FROM projects INNER JOIN users_star_projects ON users_star_projects.project_id = projects.id WHERE projects.pending_delete = 'f' AND ( EXISTS ( SELECT 1 FROM project_authorizations WHERE project_authorizations.user_id = 1 AND (project_id = projects.id) ) OR projects.visibility_level IN (20,10) ) AND users_star_projects.user_id = 1 ORDER BY projects.id DESC; This query in turn produces a better execution plan and takes less time, though the difference is only a few milliseconds (this however depends on the amount of data involved and additional conditions that may be added).
Name |
Last commit
|
Last update |
---|---|---|
.. | ||
api | Loading commit data... | |
assets | Loading commit data... | |
backup | Loading commit data... | |
banzai | Loading commit data... | |
bitbucket | Loading commit data... | |
ci | Loading commit data... | |
constraints | Loading commit data... | |
container_registry | Loading commit data... | |
generators/rails/post_deployment_migration | Loading commit data... | |
github | Loading commit data... | |
gitlab | Loading commit data... | |
json_web_token | Loading commit data... | |
mattermost | Loading commit data... | |
microsoft_teams | Loading commit data... | |
omni_auth | Loading commit data... | |
peek/rblineprof | Loading commit data... | |
rouge | Loading commit data... | |
support | Loading commit data... | |
system_check | Loading commit data... | |
tasks | Loading commit data... | |
additional_email_headers_interceptor.rb | Loading commit data... | |
banzai.rb | Loading commit data... | |
disable_email_interceptor.rb | Loading commit data... | |
email_template_interceptor.rb | Loading commit data... | |
event_filter.rb | Loading commit data... | |
expand_variables.rb | Loading commit data... | |
extracts_path.rb | Loading commit data... | |
feature.rb | Loading commit data... | |
file_size_validator.rb | Loading commit data... | |
file_streamer.rb | Loading commit data... | |
gitlab.rb | Loading commit data... | |
gt_one_coercion.rb | Loading commit data... | |
repository_cache.rb | Loading commit data... | |
static_model.rb | Loading commit data... | |
system_check.rb | Loading commit data... | |
unfold_form.rb | Loading commit data... | |
uploaded_file.rb | Loading commit data... | |
version_check.rb | Loading commit data... |