Skip to content

Add index to sp_return_logs to speed up reporting queries#5670

Merged
zachmargolis merged 1 commit intomainfrom
margolis-return-logs-reporting-index
Dec 6, 2021
Merged

Add index to sp_return_logs to speed up reporting queries#5670
zachmargolis merged 1 commit intomainfrom
margolis-return-logs-reporting-index

Conversation

@zachmargolis
Copy link
Contributor

Note: My goal is to deploy this index as a patch release (today?) so that it if goes poorly, we can revert it and clean it up well before the scheduled Thursday deploy

Background:
We're getting consistent timeouts in the new, Combined IAA report see below is one of the queries that's timing out (inside of TotalMonthlyAuthCountsWithinIaaWindow)

The sp_return_logs table is very big, and even using the requested_at index still yields too many rows, so our current hypothesis is that a new index would help to speed things up, assuming the query planner doesn't pick the wrong one.

SELECT
sp_return_logs.user_id
, '202109' AS year_month
, sp_return_logs.ial
, COUNT(sp_return_logs.id) AS auth_count
FROM sp_return_logs
WHERE
sp_return_logs.requested_at BETWEEN '2021-09-01' AND '2021-09-29'
AND sp_return_logs.returned_at IS NOT NULL
AND sp_return_logs.issuer = '...'
GROUP BY
sp_return_logs.user_id
, sp_return_logs.ial

@zachmargolis zachmargolis merged commit bbf4f4b into main Dec 6, 2021
@zachmargolis zachmargolis deleted the margolis-return-logs-reporting-index branch December 6, 2021 21:13
zachmargolis added a commit that referenced this pull request Dec 6, 2021
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