Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPP-3780: Tune glean query #4551

Merged
merged 2 commits into from
Mar 28, 2024
Merged

MPP-3780: Tune glean query #4551

merged 2 commits into from
Mar 28, 2024

Conversation

jwhitlock
Copy link
Member

The glean logging looks for a user's first mask with generated_for, to guess when they started using the add-on or Firefox integration. This query was very slow in production until this index was added:

CREATE INDEX incident_glean_202403
 ON emails_relayaddress (user_id)
 INCLUDE (created_at)
 WHERE (generated_for != '');

This PR adds this partial index with the Django model syntax. The generated PostgreSQL index statement is:

CREATE INDEX "idx_ra_created_by_addon"
 ON "emails_relayaddress" ("user_id")
 INCLUDE ("created_at")
 WHERE NOT ("generated_for" = '');

SQLite3 does not allow INCLUDE ("created_at"), so it is omitted. There is a warning "models.W040" that is silenced.

The migration will also drop the incident_glean_202403 index if found, after creating the new index.

Additionally, the query now only loads two fields, such as:

SELECT "emails_relayaddress"."id", "emails_relayaddress"."created_at"
 FROM "emails_relayaddress"
 WHERE ("emails_relayaddress"."user_id" = 1 AND
   NOT ("emails_relayaddress"."generated_for" = ''))
 ORDER BY "emails_relayaddress"."created_at" ASC
 LIMIT 1;

This will hopefully mean the index has all the required information for this query, making it even more efficient.

This index is used by glean logging to determine if and when a user
first created a RelayAddress with the add-on or Firefox integration.
This may mean the index alone is needed to satisfy the query.
@jwhitlock jwhitlock requested a review from say-yawn March 28, 2024 19:15
Copy link
Contributor

@say-yawn say-yawn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Today I learned about partial index and learned how to add index via model's metadata.

@jwhitlock jwhitlock added this pull request to the merge queue Mar 28, 2024
Merged via the queue into main with commit f9aa17f Mar 28, 2024
27 checks passed
@jwhitlock jwhitlock deleted the tune-glean-query-mpp-3780 branch March 28, 2024 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants