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

perf(issues): improve adjacent_events query #79365

Merged
merged 4 commits into from
Oct 18, 2024

Conversation

JoshFerge
Copy link
Member

@JoshFerge JoshFerge commented Oct 18, 2024

Right now the a adjacent_events query does a really big scan in order to find the adjacent events given an event id. It does this because the old query does not specify an order by which can take advantage of the primary key
ORDER BY (project_id, toStartOfDay(timestamp), primary_hash, cityHash64(event_id))

This PR adds a new function get_adjacent_event_ids_snql which uses SnQL and adds a order by clause. We observe in the snuba admin tool this new query takes only 2 seconds and scans hundreds of MBs of data as opposed to the old query which scans 10+ GB on large issues.

get_adjacent_event_ids_snql is not general purpose as its only used in one place.

see ticket below for more info:
Fixes https://github.com/getsentry/team-issues/issues/42

@JoshFerge JoshFerge requested a review from a team as a code owner October 18, 2024 17:50
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 18, 2024
Condition(
Column(DATASETS[dataset][Columns.TIMESTAMP.value.alias]),
Op.LT,
event.datetime + timedelta(days=100),
Copy link
Member

Choose a reason for hiding this comment

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

Why 100 days?

Copy link
Member Author

Choose a reason for hiding this comment

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

prev_filter.start = event.datetime - timedelta(days=100)

Copy link
Member

Choose a reason for hiding this comment

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

OK carried forward 👍🏻

@JoshFerge JoshFerge merged commit d8ff0cb into master Oct 18, 2024
49 of 50 checks passed
@JoshFerge JoshFerge deleted the jferg/efficient-adjacent-query branch October 18, 2024 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants