Skip to content

Add `system` to existing index for notes

Kerri Miller requested to merge 276943-add-non-system-index-to-notes into master

What does this MR do?

While investigating #276943 (closed), @patrickbajao spotted that we could save a ton of time on MR performance by adding system to the existing index.

Database

up

== 20201201034258 AddIndexForNonSystemNoteables: migrating ====================
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:notes, [:noteable_id, :noteable_type, :system], {:name=>"index_notes_on_noteable_id_and_noteable_type_and_system", :algorithm=>:concurrently})
   -> 0.0091s
-- execute("SET statement_timeout TO 0")
   -> 0.0002s
-- add_index(:notes, [:noteable_id, :noteable_type, :system], {:name=>"index_notes_on_noteable_id_and_noteable_type_and_system", :algorithm=>:concurrently})
   -> 0.0071s
-- execute("RESET ALL")
   -> 0.0003s
-- transaction_open?()
   -> 0.0000s
-- indexes(:notes)
   -> 0.0052s
-- remove_index(:notes, {:algorithm=>:concurrently, :name=>"index_notes_on_noteable_id_and_noteable_type"})
   -> 0.0020s
== 20201201034258 AddIndexForNonSystemNoteables: migrated (0.0253s) ===========

down

== 20201201034258 AddIndexForNonSystemNoteables: reverting ====================
-- transaction_open?()
   -> 0.0000s
-- index_exists?(:notes, [:noteable_id, :noteable_type], {:name=>"index_notes_on_noteable_id_and_noteable_type", :algorithm=>:concurrently})
   -> 0.0085s
-- execute("SET statement_timeout TO 0")
   -> 0.0001s
-- add_index(:notes, [:noteable_id, :noteable_type], {:name=>"index_notes_on_noteable_id_and_noteable_type", :algorithm=>:concurrently})
   -> 0.0114s
-- execute("RESET ALL")
   -> 0.0002s
-- transaction_open?()
   -> 0.0000s
-- indexes(:notes)
   -> 0.0869s
-- remove_index(:notes, {:algorithm=>:concurrently, :name=>"index_notes_on_noteable_id_and_noteable_type_and_system"})
   -> 0.0074s
== 20201201034258 AddIndexForNonSystemNoteables: reverted (0.1221s) ===========

Timings

SELECT COUNT(*)
FROM (
        (SELECT *
         FROM "notes"
         WHERE "notes"."noteable_id" = 46282578
           AND "notes"."noteable_type" = 'MergeRequest')
      UNION ALL
        (SELECT *
         FROM "notes"
         WHERE "system" = FALSE
           AND "project_id" IN (14278368, 278964)
           AND "noteable_type" = 'Commit'
           AND "commit_id" IN ('cac9ad10ff81b8734f819bc90327fb6fcd0e9302',
                                       '402ed9282f1e27571ecc137bb0e1bfa27efcc420',
                                       '782e5afbfe9a6828a9df5f7ae7fa73551e461e67',
                                       '4f0d570dcf6ffbb0b430e52b995bc84dbc835bcd',
                                       'fff9df16c9aaafef4508833b772bfa63adf71e42',
                                       '928907072575a0158e543bdd442755d0b8039b34'))) notes
WHERE "notes"."system" = FALSE;

Without index

Time: 235.342 ms
  - planning: 0.579 ms
  - execution: 234.763 ms
    - I/O read: 231.344 ms
    - I/O write: 0.000 ms

Shared buffers:
  - hits: 276 (~2.20 MiB) from the buffer pool
  - reads: 321 (~2.50 MiB) from the OS file cache, including disk I/O
  - dirtied: 3 (~24.00 KiB)
  - writes: 0

With index

Time: 12.890 ms
  - planning: 1.080 ms
  - execution: 11.810 ms
    - I/O read: 10.673 ms
    - I/O write: 0.000 ms

Shared buffers:
  - hits: 29 (~232.00 KiB) from the buffer pool
  - reads: 6 (~48.00 KiB) from the OS file cache, including disk I/O
  - dirtied: 0
  - writes: 0

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Related to #276943 (closed)

Edited by Kerri Miller

Merge request reports

Loading