mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 20:03:12 +03:00
d5a9731845
closes https://linear.app/tryghost/issue/ENG-791/migration-to-fix-email-recipients-indexes Our indexes over single columns (`delivered_at`, `opened_at`, `failed_at`) were ineffective because the only time we query those is alongside `email_id` meaning we were frequently performing full table scans on very large tables during our email analytics jobs. - added migration to add new indexes covering `email_id` and the respective columns - added migration to drop the old indexes that weren't being used in any query plans Local runtime with ~2M email_recipient rows: - before: 1.7s - after: 99ms Explain output... before: ``` +----+-------------+------------------+------------+-------+----------------------------------------------------------------------------------+----------------------------------------------+---------+-------+--------+----------+------------------------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+------------------+------------+-------+----------------------------------------------------------------------------------+----------------------------------------------+---------+-------+--------+----------+------------------------------------+ | 1 | UPDATE | emails | NULL | index | NULL | PRIMARY | 98 | NULL | 1 | 100.00 | Using where | | 4 | SUBQUERY | email_recipients | NULL | range | email_recipients_email_id_member_email_index,email_recipients_failed_at_index | email_recipients_failed_at_index | 6 | NULL | 2343 | 7.76 | Using index condition; Using where | | 3 | SUBQUERY | email_recipients | NULL | ref | email_recipients_email_id_member_email_index,email_recipients_opened_at_index | email_recipients_email_id_member_email_index | 98 | const | 159126 | 50.00 | Using where | | 2 | SUBQUERY | email_recipients | NULL | ref | email_recipients_email_id_member_email_index,email_recipients_delivered_at_index | email_recipients_email_id_member_email_index | 98 | const | 159126 | 50.00 | Using where | +----+-------------+------------------+------------+-------+----------------------------------------------------------------------------------+----------------------------------------------+---------+-------+--------+----------+------------------------------------+ ``` after: ``` +----+-------------+------------------+------------+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------+---------+------+--------+----------+--------------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+------------------+------------+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------+---------+------+--------+----------+--------------------------+ | 1 | UPDATE | emails | NULL | index | NULL | PRIMARY | 98 | NULL | 1 | 100.00 | Using where; | | 4 | SUBQUERY | email_recipients | NULL | range | email_recipients_email_id_member_email_index,email_recipients_email_id_delivered_at_index,email_recipients_email_id_opened_at_index,email_recipients_email_id_failed_at_index | email_recipients_email_id_failed_at_index | 104 | NULL | 60 | 100.00 | Using where; Using index | | 3 | SUBQUERY | email_recipients | NULL | range | email_recipients_email_id_member_email_index,email_recipients_email_id_delivered_at_index,email_recipients_email_id_opened_at_index,email_recipients_email_id_failed_at_index | email_recipients_email_id_opened_at_index | 104 | NULL | 119496 | 100.00 | Using where; Using index | | 2 | SUBQUERY | email_recipients | NULL | range | email_recipients_email_id_member_email_index,email_recipients_email_id_delivered_at_index,email_recipients_email_id_opened_at_index,email_recipients_email_id_failed_at_index | email_recipients_email_id_delivered_at_index | 104 | NULL | 146030 | 100.00 | Using where; Using index | +----+-------------+------------------+------------+-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------+---------+------+--------+----------+--------------------------+ ``` |
||
---|---|---|
.. | ||
adapter-cache-memory-ttl | ||
adapter-cache-redis | ||
adapter-manager | ||
admin | ||
announcement-bar-settings | ||
api-framework | ||
api-version-compatibility-service | ||
audience-feedback | ||
bookshelf-repository | ||
bootstrap-socket | ||
collections | ||
constants | ||
core | ||
custom-theme-settings-service | ||
data-generator | ||
domain-events | ||
donations | ||
dynamic-routing-events | ||
email-addresses | ||
email-analytics-provider-mailgun | ||
email-analytics-service | ||
email-content-generator | ||
email-events | ||
email-service | ||
email-suppression-list | ||
express-dynamic-redirects | ||
external-media-inliner | ||
extract-api-key | ||
ghost | ||
html-to-plaintext | ||
i18n | ||
importer-handler-content-files | ||
importer-revue | ||
in-memory-repository | ||
job-manager | ||
link-redirects | ||
link-replacer | ||
link-tracking | ||
magic-link | ||
mail-events | ||
mailgun-client | ||
member-attribution | ||
member-events | ||
members-api | ||
members-csv | ||
members-events-service | ||
members-importer | ||
members-ssr | ||
mentions-email-report | ||
milestones | ||
minifier | ||
model-to-domain-event-interceptor | ||
mw-api-version-mismatch | ||
mw-cache-control | ||
mw-error-handler | ||
mw-session-from-token | ||
mw-update-user-last-seen | ||
mw-version-match | ||
mw-vhost | ||
nql-filter-expansions | ||
oembed-service | ||
offers | ||
package-json | ||
payments | ||
post-events | ||
post-revisions | ||
posts-service | ||
recommendations | ||
referrers | ||
security | ||
session-service | ||
settings-path-manager | ||
slack-notifications | ||
staff-service | ||
stats-service | ||
stripe | ||
tiers | ||
update-check-service | ||
verification-trigger | ||
version-notifications-data-service | ||
webmentions | ||
tsconfig.json |