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

Remove JOIN from GetAuthorizations2 and filter in code #4512

Merged
merged 4 commits into from
Oct 31, 2019
Merged

Conversation

rolandshoemaker
Copy link
Contributor

@rolandshoemaker rolandshoemaker commented Oct 28, 2019

Previously we used a JOIN on the orderToAuthz2 table in order to make sure
we only returned authorizations created using the ACME v2 API. Each time an
order is created a pivot row (order ID + authz ID) is added to the
orderToAuthz2 table. If a large number of orders are created that all contain
the same authorization, due to reuse, then the JOINd query would return a full
authorization row for each entry in the orderToAuthz2 table with the authorization
ID.

Instead we now filter out these authorizations by doing a second query against
the orderToAuthz2 table. Using this query still requires examining a large number
of rows, but because we don't need to construct a temporary table for the JOIN
and fill it with all the full authorization rows we should save resources.

Fixes #4500.

@rolandshoemaker rolandshoemaker requested a review from a team as a code owner October 28, 2019 19:51
var authz2IDs []int64
_, err = ssa.dbMap.Select(
&authz2IDs,
fmt.Sprintf(`SELECT DISTINCT(authzID) FROM orderToAuthz2 WHERE authzID IN (%s)`, strings.Join(qmarks, ",")),
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at this, it may turn out to be similarly expensive in the corner case we found, since it's potentially reading many orderToAuthz2 rows for a single authorization that's included in many orders. Presumably it's still somewhat cheaper since at least it's not doing the join, so I think it's worthwhile, but not the big win we'd hoped for.

The only alternative I see would be to split this into N independent queries, each with a LIMIT 1, but that definitely increases the complexity and might actually make performance work. So on balance I think this approach is fine.

sa/sa.go Outdated
// Instead of using a JOIN on the orderToAuthz2 table in order to filter out
// authorizations that don't have associated orders we do a second query
// and do the filtering in code. This allows us to bypass the large number
// of duplicate rows that are generated by using a JOIN.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to see a little more description here of the conditions under which we see a large number of rows in the orderToAuthz2 table for a single authorization, since it's slightly harder to grok, and is the motivating reason for this change. I'd also like to see a similar description in the PR description.

cpu
cpu previously approved these changes Oct 30, 2019
Copy link
Contributor

@cpu cpu left a comment

Choose a reason for hiding this comment

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

@rolandshoemaker Are you confident this doesn't need to be feature flagged?

LGTM other than that thought.

jsha
jsha previously approved these changes Oct 30, 2019
@rolandshoemaker
Copy link
Contributor Author

@rolandshoemaker Are you confident this doesn't need to be feature flagged?

Hm, it's probably a good idea to flag it, good call.

@cpu
Copy link
Contributor

cpu commented Oct 31, 2019

Hm, it's probably a good idea to flag it, good call.

@rolandshoemaker 👍 In that case should we wait on merging this until you've had a chance to push another commit?

@rolandshoemaker rolandshoemaker dismissed stale reviews from jsha and cpu via d6aeb2b October 31, 2019 16:49
@rolandshoemaker
Copy link
Contributor Author

Pushed flag change.

@cpu cpu merged commit e49b6d7 into master Oct 31, 2019
@cpu cpu deleted the unjoin-the-join branch October 31, 2019 17:25
jsha pushed a commit that referenced this pull request Nov 8, 2019
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.

Optimize GetAuthorizations2 query
3 participants