diff options
author | Shinya Maeda <shinya@gitlab.com> | 2019-05-02 13:02:38 +0000 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2019-05-03 08:55:05 +0700 |
commit | 971ed49cd2d815c0a8a24e69cafb83485b2cf387 (patch) | |
tree | 55f412c65bbe2974fb678a92ddad3fd4239ef04c | |
parent | a8347c22d0e33ab626ee4c3b4b9acffa69f7cf46 (diff) | |
download | gitlab-ce-add-note-for-fk-with-index.tar.gz |
Add note for index requirement with FK constraintadd-note-for-fk-with-index
Update migration_style_guide.md
-rw-r--r-- | doc/development/migration_style_guide.md | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/doc/development/migration_style_guide.md b/doc/development/migration_style_guide.md index 0c326eeb851..6e3151a06dc 100644 --- a/doc/development/migration_style_guide.md +++ b/doc/development/migration_style_guide.md @@ -186,7 +186,11 @@ end When adding a foreign-key constraint to either an existing or new column remember to also add a index on the column. -This is _required_ for all foreign-keys. +This is _required_ for all foreign-keys, e.g. to support efficient cascading +deletes: When a lot of rows in a table get deleted, the referenced records need +to be deleted, too. The database has to look up corresponding records in the +referenced table. Without an index, this will result in a sequential scan on the +table which can take a long time. Here's an example where we add a new column with a foreign key constraint. Note it includes `index: true` to create an index for it. |