gitlab-org--gitlab-foss/spec/tasks/gitlab
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
..
artifacts fix the failing specs 2018-03-22 14:37:47 -04:00
lfs [cherry-pick] '4862-verify-file-checksums' 2018-03-08 10:20:40 -05:00
uploads Enhance performance of counting local Uploads 2018-11-07 11:29:31 +01:00
backup_rake_spec.rb Fix typos in comments and specs 2018-11-01 08:59:20 +02:00
check_rake_spec.rb Moved o_auth/saml/ldap modules under gitlab/auth 2018-02-28 16:53:02 +01:00
cleanup_rake_spec.rb Port cleanup tasks to use Gitaly 2018-09-07 13:58:31 +02:00
db_rake_spec.rb Fix the schema load test 2018-09-12 15:55:26 -07:00
git_rake_spec.rb Remove git rake tasks 2018-07-31 14:31:50 +02:00
gitaly_rake_spec.rb Remove storage path dependency of gitaly install task 2018-08-12 18:52:44 -03:00
info_rake_spec.rb
ldap_rake_spec.rb Stub ENV in the LDAP task spec file 2017-10-18 18:42:09 +02:00
mail_google_schema_whitelisting.rb
shell_rake_spec.rb Find and mark more Git disk access locations, part 2 2018-06-12 14:33:37 +02:00
site_statistics_rake_spec.rb Geo: sync disabled wikis. Stage 2 2018-09-25 17:49:39 +03:00
storage_rake_spec.rb Resolve "Hashed Storage: Make possible to migrate single project" 2018-06-07 15:40:44 +00:00
task_helpers_spec.rb Eliminate the warnings from task helpers 2018-01-26 19:42:48 +08:00
traces_rake_spec.rb Add rake command to migrate archived traces from local storage to object storage 2018-08-16 14:28:47 +00:00
workhorse_rake_spec.rb