gitlab-org--gitlab-foss/spec
Toon Claes 1c481b7aac Enhance performance of counting local Uploads
Add an index to the `store` column on `uploads`. This makes counting
local uploads faster.

Also, there is no longer need to check for objects with `store = NULL`.
See https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/18557

---

### Query plans

Query:

```sql
SELECT COUNT(*)
FROM "uploads"
WHERE ("uploads"."store" = ? OR "uploads"."store" IS NULL)
```

#### Without index

```
gitlabhq_production=# EXPLAIN ANALYZE SELECT uploads.* FROM uploads WHERE (uploads.store = 1 OR uploads.store IS NULL);
                                                  QUERY PLAN
---------------------------------------------------------------------------------------------------------------
 Seq Scan on uploads  (cost=0.00..601729.54 rows=578 width=272) (actual time=6.170..2308.256 rows=545 loops=1)
   Filter: ((store = 1) OR (store IS NULL))
   Rows Removed by Filter: 4411957
 Planning time: 38.652 ms
 Execution time: 2308.454 ms
(5 rows)
```

#### Add index

```
gitlabhq_production=# create index uploads_tmp1 on uploads (store);
CREATE INDEX
```

#### With index

```
gitlabhq_production=# EXPLAIN ANALYZE SELECT uploads.* FROM uploads WHERE (uploads.store = 1 OR uploads.store IS NULL);
                                                          QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------
 Bitmap Heap Scan on uploads  (cost=11.46..1238.88 rows=574 width=272) (actual time=0.155..0.577 rows=545 loops=1)
   Recheck Cond: ((store = 1) OR (store IS NULL))
   Heap Blocks: exact=217
   ->  BitmapOr  (cost=11.46..11.46 rows=574 width=0) (actual time=0.116..0.116 rows=0 loops=1)
         ->  Bitmap Index Scan on uploads_tmp1  (cost=0.00..8.74 rows=574 width=0) (actual time=0.095..0.095 rows=545 loops=1)
               Index Cond: (store = 1)
         ->  Bitmap Index Scan on uploads_tmp1  (cost=0.00..2.44 rows=1 width=0) (actual time=0.020..0.020 rows=0 loops=1)
               Index Cond: (store IS NULL)
 Planning time: 0.274 ms
 Execution time: 0.637 ms
(10 rows)
```

Closes https://gitlab.com/gitlab-org/gitlab-ee/issues/6070
2018-11-07 11:29:31 +01:00
..
bin Remove Git circuit breaker 2018-10-10 09:08:18 +02:00
config Enable omniauth by default 2018-09-13 13:44:04 +01:00
controllers Merge branch 'bw-serializer-tech-debit' into 'master' 2018-11-06 18:33:13 +00:00
db Use Rails.root for CommonMetricsImporter 2018-09-11 17:40:32 +02:00
dependencies
factories Squashed commit of the following: 2018-11-06 10:54:27 +09:00
features Merge branch 'winh-delayed-jobs-dynamic-timer' into 'master' 2018-11-07 10:27:54 +00:00
finders Squashed commit of the following: 2018-11-06 10:54:27 +09:00
fixtures Extract code into IssueBoardEntity 2018-11-06 10:33:55 -06:00
graphql Make GitLab pages support access control 2018-10-05 13:41:11 +00:00
helpers Update event helper spec to check for target prefix 2018-11-06 14:40:16 +02:00
initializers
javascripts Merge branch 'winh-delayed-jobs-dynamic-timer' into 'master' 2018-11-07 10:27:54 +00:00
lib Merge branch 'winh-delayed-jobs-dynamic-timer' into 'master' 2018-11-07 10:27:54 +00:00
mailers Automatically disable Auto DevOps for project upon first pipeline failure 2018-09-06 19:20:42 +00:00
migrations Squashed commit of the following: 2018-11-06 10:54:27 +09:00
models Enhance performance of counting local Uploads 2018-11-07 11:29:31 +01:00
policies Hides Close MR button on merged MR 2018-10-02 16:17:55 +02:00
presenters Allow to make builds soft-archived. 2018-11-05 15:51:57 +01:00
rack_servers Add experimental support for Puma 2018-10-25 17:50:15 +01:00
requests Squashed commit of the following: 2018-11-06 10:54:27 +09:00
routing Remove Koding integration and documentation 2018-10-12 22:18:51 -07:00
rubocop Add a new QA::ElementWithPattern cop 2018-10-15 14:28:03 +02:00
serializers Merge branch 'bw-serializer-tech-debit' into 'master' 2018-11-06 18:33:13 +00:00
services Fix flaky spec 2018-11-06 14:26:36 +09:00
sidekiq/cron
support Merge branch 'ccr/51052_keep_labels_on_issue' into 'master' 2018-11-06 16:31:32 +00:00
tasks Enhance performance of counting local Uploads 2018-11-07 11:29:31 +01:00
uploaders Merge branch 'fix-namespace-upload' into 'master' 2018-09-11 14:42:35 +00:00
validators Allow UrlValidator to work with attr_encrypted 2018-09-17 19:34:40 +01:00
views Merge branch 'fast_project_blob_path' into 'master' 2018-11-05 11:12:02 +00:00
workers Create deployments only if action: start 2018-11-06 10:54:27 +09:00
factories_spec.rb
fast_spec_helper.rb Allow CE do nothing if route doesn't exist 2018-10-26 14:27:05 +08:00
rails_helper.rb
rake_helper.rb
simplecov_env.rb
spec_helper.rb Require spec helpers loaded by other spec helpers first 2018-10-04 21:40:07 -03:00