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

Removed use of subqueries in email analytics queries #19917

Merged

Commits on Apr 2, 2024

  1. Removed use of subqueries in email analytics queries

    closes https://linear.app/tryghost/issue/ENG-790/remove-use-of-sub-queries-in-email-analytics
    
    Avoiding sub queries means we don't have a process tied up for longer than necessary and we can more easily see if one of the queries is non-performant.
    
    - extracted the count queries into separate queries and used the retrieved values in the final update query
    - removed a query by moving the email open rate calculation into JS as we've already fetched the necessary data before that point
    kevinansfield committed Apr 2, 2024
    Configuration menu
    Copy the full SHA
    c8eba37 View commit details
    Browse the repository at this point in the history
  2. Optimised email stats aggregation query for typical column usage

    ref https://linear.app/tryghost/issue/ENG-790/remove-use-of-sub-queries-in-email-analytics
    
    - the `delivered_at` column is typically entirely/nearly entirely filled with values meaning the `IS NOT NULL` query matches a huge number of rows that MySQL has to fetch from the index to count
    - using `IS NULL` switches that behaviour around as it will now match very few rows which has been shown in testing to be considerably quicker
    - after switching to `IS NULL` the query returns an "undelivered" count rather than a "delivered" count, in order to keep the rest of the system behaviour the same we can calculate the delivered count by subtracting the query result from the total number of emails sent which we can fetch using a very fast primary key lookup query on the `emails` table
    kevinansfield committed Apr 2, 2024
    Configuration menu
    Copy the full SHA
    0569379 View commit details
    Browse the repository at this point in the history