forked from ory/kratos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add missing indexes for identity delete (ory#2952)
This significantly improves the performance of identity deletes. Co-authored-by: hackerman <[email protected]>
- Loading branch information
Showing
5 changed files
with
136 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
persistence/sql/migrations/sql/20221214101328000000_identity_delete_indices.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
DROP INDEX IF EXISTS "identity_recovery_codes_identity_id_nid_idx"; | ||
|
||
DROP INDEX IF EXISTS "identity_verification_codes_verifiable_address_nid_idx"; | ||
|
||
DROP INDEX IF EXISTS "selfservice_settings_flows_identity_id_nid_idx"; | ||
|
||
DROP INDEX IF EXISTS "continuity_containers_identity_id_nid_idx"; | ||
|
||
DROP INDEX IF EXISTS "selfservice_recovery_flows_recovered_identity_id_nid_idx"; | ||
|
||
DROP INDEX IF EXISTS "identity_recovery_tokens_identity_id_nid_idx"; | ||
|
||
DROP INDEX IF EXISTS "identity_recovery_codes_identity_recovery_address_id_nid_idx"; |
36 changes: 36 additions & 0 deletions
36
persistence/sql/migrations/sql/20221214101328000000_identity_delete_indices.mysql.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
-- MySQL requires indexes on foreign keys and referenced keys so that foreign key checks can be fast and not require a table scan. | ||
-- In the referencing table, there must be an index where the foreign key columns are listed as the first columns in the same order. | ||
-- Such an index is created on the referencing table automatically if it does not exist. This index might be silently dropped later | ||
-- if you create another index that can be used to enforce the foreign key constraint. | ||
|
||
-- from https://dev.mysql.com/doc/refman/8.0/en/create-table-foreign-keys.html | ||
|
||
-- -> The indexes in question already existed. We have to create new ones that are just the foreign key to restore the previous state. | ||
|
||
ALTER TABLE identity_recovery_codes ADD INDEX (identity_id); | ||
|
||
DROP INDEX identity_recovery_codes_identity_id_nid_idx ON identity_recovery_codes; | ||
|
||
ALTER TABLE identity_verification_codes ADD INDEX (identity_verifiable_address_id); | ||
|
||
DROP INDEX identity_verification_codes_verifiable_address_nid_idx ON identity_verification_codes; | ||
|
||
ALTER TABLE selfservice_settings_flows ADD INDEX (identity_id); | ||
|
||
DROP INDEX selfservice_settings_flows_identity_id_nid_idx ON selfservice_settings_flows; | ||
|
||
ALTER TABLE continuity_containers ADD INDEX (identity_id); | ||
|
||
DROP INDEX continuity_containers_identity_id_nid_idx ON continuity_containers; | ||
|
||
ALTER TABLE selfservice_recovery_flows ADD INDEX (recovered_identity_id); | ||
|
||
DROP INDEX selfservice_recovery_flows_recovered_identity_id_nid_idx ON selfservice_recovery_flows; | ||
|
||
ALTER TABLE identity_recovery_tokens ADD INDEX (identity_id); | ||
|
||
DROP INDEX identity_recovery_tokens_identity_id_nid_idx ON identity_recovery_tokens; | ||
|
||
ALTER TABLE identity_recovery_codes ADD INDEX (identity_recovery_address_id); | ||
|
||
DROP INDEX identity_recovery_codes_identity_recovery_address_id_nid_idx ON identity_recovery_codes; |
22 changes: 22 additions & 0 deletions
22
persistence/sql/migrations/sql/20221214101328000000_identity_delete_indices.mysql.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
-- MySQL requires indexes on foreign keys and referenced keys so that foreign key checks can be fast and not require a table scan. | ||
-- In the referencing table, there must be an index where the foreign key columns are listed as the first columns in the same order. | ||
-- Such an index is created on the referencing table automatically if it does not exist. This index might be silently dropped later | ||
-- if you create another index that can be used to enforce the foreign key constraint. | ||
|
||
-- from https://dev.mysql.com/doc/refman/8.0/en/create-table-foreign-keys.html | ||
|
||
-- -> We create new indexes to be consistent with the other databases. However, dropping those will be a bit different. | ||
|
||
CREATE INDEX identity_recovery_codes_identity_id_nid_idx ON identity_recovery_codes (identity_id, nid); | ||
|
||
CREATE INDEX identity_verification_codes_verifiable_address_nid_idx ON identity_verification_codes (identity_verifiable_address_id, nid); | ||
|
||
CREATE INDEX selfservice_settings_flows_identity_id_nid_idx ON selfservice_settings_flows (identity_id, nid); | ||
|
||
CREATE INDEX continuity_containers_identity_id_nid_idx ON continuity_containers (identity_id, nid); | ||
|
||
CREATE INDEX selfservice_recovery_flows_recovered_identity_id_nid_idx ON selfservice_recovery_flows (recovered_identity_id, nid); | ||
|
||
CREATE INDEX identity_recovery_tokens_identity_id_nid_idx ON identity_recovery_tokens (identity_id, nid); | ||
|
||
CREATE INDEX identity_recovery_codes_identity_recovery_address_id_nid_idx ON identity_recovery_codes (identity_recovery_address_id, nid); |
13 changes: 13 additions & 0 deletions
13
persistence/sql/migrations/sql/20221214101328000000_identity_delete_indices.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CREATE INDEX IF NOT EXISTS "identity_recovery_codes_identity_id_nid_idx" ON "identity_recovery_codes" (identity_id, nid); | ||
|
||
CREATE INDEX IF NOT EXISTS "identity_verification_codes_verifiable_address_nid_idx" ON "identity_verification_codes" (identity_verifiable_address_id, nid); | ||
|
||
CREATE INDEX IF NOT EXISTS "selfservice_settings_flows_identity_id_nid_idx" ON "selfservice_settings_flows" (identity_id, nid); | ||
|
||
CREATE INDEX IF NOT EXISTS "continuity_containers_identity_id_nid_idx" ON "continuity_containers" (identity_id, nid); | ||
|
||
CREATE INDEX IF NOT EXISTS "selfservice_recovery_flows_recovered_identity_id_nid_idx" ON "selfservice_recovery_flows" (recovered_identity_id, nid); | ||
|
||
CREATE INDEX IF NOT EXISTS "identity_recovery_tokens_identity_id_nid_idx" ON "identity_recovery_tokens" (identity_id, nid); | ||
|
||
CREATE INDEX IF NOT EXISTS "identity_recovery_codes_identity_recovery_address_id_nid_idx" ON "identity_recovery_codes" (identity_recovery_address_id, nid); |