Files
gitlabhq/app/models
Yorick Peterse 8591cc02be Use a JOIN in IssuableFinder#by_project
When using IssuableFinder/IssuesFinder to find issues for multiple
projects it's more efficient to use a JOIN + a "WHERE project_id IN"
condition opposed to running a sub-query.

This change means that when finding issues without labels we're now
using the following SQL:

    SELECT issues.*
    FROM issues
    JOIN projects ON projects.id = issues.project_id

    LEFT JOIN label_links ON label_links.target_type = 'Issue'
                          AND label_links.target_id  = issues.id

    WHERE (
        projects.id IN (...)
        OR projects.visibility_level IN (20, 10)
    )
    AND issues.state IN ('opened','reopened')
    AND label_links.id IS NULL
    ORDER BY issues.id DESC;

instead of:

    SELECT issues.*
    FROM issues
    LEFT JOIN label_links ON label_links.target_type = 'Issue'
                          AND label_links.target_id  = issues.id

    WHERE issues.project_id IN (
        SELECT id
        FROM projects
        WHERE id IN (...)
        OR visibility_level IN (20,10)
    )
    AND issues.state IN ('opened','reopened')
    AND label_links.id IS NULL
    ORDER BY issues.id DESC;

The big benefit here is that in the last case PostgreSQL can't properly
use all available indexes. In particular it ends up performing a
sequence scan on the "label_links" table (processing around 290 000
rows). The new query is roughly 2x as fast as the old query.
2015-11-19 11:58:05 +01:00
..
2015-11-13 19:22:46 +01:00
2015-05-03 13:38:27 -07:00
2011-10-09 00:36:38 +03:00
2015-11-17 15:49:37 +01:00
2015-09-29 21:47:01 +02:00
2015-11-13 19:22:46 +01:00
2015-08-03 01:52:54 +09:00
2015-11-13 19:22:46 +01:00
2015-05-03 13:38:27 -07:00
2015-04-03 12:28:47 +02:00
2015-11-18 13:05:45 +01:00
2015-11-13 19:22:46 +01:00
2015-08-04 14:33:18 +02:00
2014-08-25 12:25:02 +03:00
2015-11-13 19:22:46 +01:00
2015-11-16 12:39:13 +01:00
2015-11-17 15:49:37 +01:00
2015-11-13 19:22:46 +01:00
2014-10-09 18:22:20 +03:00
2015-05-03 13:38:27 -07:00
2014-10-09 18:22:20 +03:00
2015-11-13 19:22:46 +01:00
2015-08-03 01:52:54 +09:00
2015-06-20 01:06:57 +02:00
2015-03-16 21:38:41 +02:00
2015-05-18 22:51:56 +02:00
2014-08-25 12:25:02 +03:00