Optimize DB indexes for ES indexing of notes

To index notes, we exclude system notes and use `find_in_batches` to
load them in batches for submission to the ES bulk import API.
These queries often result in DB timeouts because the usage of
`ORDER BY id` results in the `notes_pkey` index being used.

This adds an optimized partial index, and removes the unused index
`index_notes_on_noteable_type` which is already covered for our
usage by the existing `index_notes_on_noteable_id_and_noteable_type`.

Newer versions of PostgreSQL (at least 11) are smarter about this and
use `index_notes_on_project_id_and_noteable_type` instead, so we might
be able to remove the partial index again in the future.
99 jobs for optimize-note-indexes in 64 minutes and 58 seconds (queued for 4 seconds)
Status Job ID Name Coverage
  Prepare
passed #274203272
gitlab-org
compile-assets pull-cache

00:06:33

passed #274203274
gitlab-org
retrieve-tests-metadata

00:00:32

passed #274203273
gitlab-org
setup-test-env

00:04:29

 
  Test
passed #274203357
docker gitlab-org
build-qa-image

00:05:36

passed #274203287
allowed to fail
code_quality

00:06:52

passed #274203360
gitlab-org
danger-review

00:02:54

passed #274203351
gitlab-org
db:check-schema-pg

00:03:22

passed #274203350
gitlab-org
db:migrate:reset-pg

00:02:43

passed #274203355
gitlab-org
db:rollback-pg

00:04:51

passed #274203289
allowed to fail
dependency_scanning

00:09:40

passed #274203275
gitlab-org
docs lint

00:02:50

passed #274203348
gitlab-org
downtime_check

00:01:59

passed #274203349
gitlab-org
ee_compat_check

00:02:46

passed #274203276
gitlab-org docker
gitlab:assets:compile pull-cache

00:18:32

passed #274203356
gitlab-org
gitlab:setup-pg

00:03:35

passed #274203361
gitlab-org
gitlab_git_test

00:00:26

passed #274203279
gitlab-org
jest

00:15:19

passed #274203277
gitlab-org
karma

00:11:32

53.88%
passed #274203363
gitlab-org
lint-ci-gitlab

00:00:33

passed #274203286
gitlab-org
memory-on-boot

00:05:36

passed #274203285
gitlab-org
memory-static

00:03:03

passed #274203353
gitlab-org
migration:path-pg

00:09:30

passed #274203362
gitlab-org
no_ee_check

00:00:25

passed #274203283
gitlab-org
qa-frontend-node:10

00:17:37

passed #274203282
gitlab-org
qa-frontend-node:8

00:15:56

passed #274203284
gitlab-org allowed to fail
qa-frontend-node:latest

00:12:49

passed #274203280
gitlab-org
qa:internal

00:04:49

passed #274203281
gitlab-org
qa:selectors

00:02:57

passed #274203358
allowed to fail manual
review-build-cng

00:26:45

passed #274203310
gitlab-org
rspec integration pg 1/6

00:18:05

passed #274203311
gitlab-org
rspec integration pg 2/6

00:16:03

passed #274203312
gitlab-org
rspec integration pg 3/6

00:18:12

passed #274203313
gitlab-org
rspec integration pg 4/6

00:14:58

passed #274203314
gitlab-org
rspec integration pg 5/6

00:19:22

passed #274203315
gitlab-org
rspec integration pg 6/6

00:14:14

passed #274203316
gitlab-org
rspec system pg 1/24

00:11:18

passed #274203330
gitlab-org
rspec system pg 10/24

00:12:32

passed #274203331
gitlab-org
rspec system pg 11/24

00:10:59

passed #274203332
gitlab-org
rspec system pg 12/24

00:10:46

passed #274203333
gitlab-org
rspec system pg 13/24

00:13:06

passed #274203334
gitlab-org
rspec system pg 14/24

00:12:22

passed #274203335
gitlab-org
rspec system pg 15/24

00:13:26

passed #274203336
gitlab-org
rspec system pg 16/24

00:13:50

passed #274203337
gitlab-org
rspec system pg 17/24

00:12:15

passed #274203338
gitlab-org
rspec system pg 18/24

00:14:43

passed #274203340
gitlab-org
rspec system pg 19/24

00:11:34

passed #274203317
gitlab-org
rspec system pg 2/24

00:13:14

passed #274203341
gitlab-org
rspec system pg 20/24

00:12:34

passed #274203342
gitlab-org
rspec system pg 21/24

00:12:15

passed #274203343
gitlab-org
rspec system pg 22/24

00:11:39

passed #274203344
gitlab-org
rspec system pg 23/24

00:13:06

passed #274203345
gitlab-org
rspec system pg 24/24

00:15:14

passed #274203318
gitlab-org
rspec system pg 3/24

00:12:37

passed #274203319
gitlab-org
rspec system pg 4/24

00:12:16

passed #274203320
gitlab-org
rspec system pg 5/24

00:13:31

passed #274203321
gitlab-org
rspec system pg 6/24

00:13:14

passed #274203324
gitlab-org
rspec system pg 7/24

00:09:58

passed #274203325
gitlab-org
rspec system pg 8/24

00:12:57

passed #274203327
gitlab-org
rspec system pg 9/24

00:10:03

passed #274203290
gitlab-org
rspec unit pg 1/20

00:17:28

passed #274203299
gitlab-org
rspec unit pg 10/20

00:16:37

passed #274203300
gitlab-org
rspec unit pg 11/20

00:16:38

passed #274203301
gitlab-org
rspec unit pg 12/20

00:17:54

passed #274203302
gitlab-org
rspec unit pg 13/20

00:13:35

passed #274203303
gitlab-org
rspec unit pg 14/20

00:18:52

passed #274203304
gitlab-org
rspec unit pg 15/20

00:16:53

passed #274203305
gitlab-org
rspec unit pg 16/20

00:17:49

passed #274203306
gitlab-org
rspec unit pg 17/20

00:17:51

passed #274203307
gitlab-org
rspec unit pg 18/20

00:15:24

passed #274203308
gitlab-org
rspec unit pg 19/20

00:14:32

passed #274203291
gitlab-org
rspec unit pg 2/20

00:15:46

passed #274203309
gitlab-org
rspec unit pg 20/20

00:13:22

passed #274203292
gitlab-org
rspec unit pg 3/20

00:14:05

passed #274203293
gitlab-org
rspec unit pg 4/20

00:11:58

passed #274203294
gitlab-org
rspec unit pg 5/20

00:13:14

passed #274203295
gitlab-org
rspec unit pg 6/20

00:11:59

passed #274203296
gitlab-org
rspec unit pg 7/20

00:13:55

passed #274203297
gitlab-org
rspec unit pg 8/20

00:12:37

passed #274203298
gitlab-org
rspec unit pg 9/20

00:17:37

passed #274203346
gitlab-org
rspec-fast-spec-helper

00:03:06

passed #274203288
allowed to fail
sast

00:08:30

passed #274203347
gitlab-org
static-analysis

00:15:07

 
  Review
manual #274203367
allowed to fail manual
package-and-qa
passed #274203368
gitlab-org allowed to fail
review-deploy

00:03:31

manual #274203365
gitlab-org allowed to fail manual
review-docs-cleanup
manual #274203364
gitlab-org allowed to fail manual
review-docs-deploy-manual
passed #274203369
gitlab-org allowed to fail manual
review-stop

00:00:33

 
  Qa
passed #274203379
docker gitlab-org allowed to fail
review-performance

00:03:31

manual #274203371
docker gitlab-org allowed to fail manual
review-qa-all 1/5
manual #274203372
docker gitlab-org allowed to fail manual
review-qa-all 2/5
manual #274203373
docker gitlab-org allowed to fail manual
review-qa-all 3/5
manual #274203374
docker gitlab-org allowed to fail manual
review-qa-all 4/5
manual #274203378
docker gitlab-org allowed to fail manual
review-qa-all 5/5
passed #274203370
docker gitlab-org allowed to fail
review-qa-smoke

00:05:48

 
  Post Test
passed #274203382
gitlab-org
coverage

00:03:40

96.57%
passed #274203384
gitlab-org allowed to fail
flaky-examples-check

00:02:10

passed #274203381
gitlab-org
jsdoc

00:03:33

passed #274203380
gitlab-org
lint:javascript:report

00:01:25

manual #274203383
gitlab-org allowed to fail manual
parallel-spec-reports