-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix(releases): Add build number and code to semver index (DB migration) #102747
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
Conversation
|
This PR has a migration; here is the generated SQL for for --
-- Remove index sentry_release_semver_idx from release
--
DROP INDEX CONCURRENTLY IF EXISTS "sentry_release_semver_idx";
--
-- Create index sentry_release_semver_idx on F(organization), OrderBy(F(major), descending=True), OrderBy(F(minor), descending=True), OrderBy(F(patch), descending=True), OrderBy(F(revision), descending=True), OrderBy(CASE WHEN <Q: (AND: ('prerelease', ''))> THEN Value(1), ELSE Value(0), descending=True), OrderBy(F(prerelease), descending=True), OrderBy(F(build_number), descending=True), OrderBy(F(build_code), descending=True) on model release
--
CREATE INDEX CONCURRENTLY "sentry_release_semver_idx" ON "sentry_release" ("organization_id", "major" DESC, "minor" DESC, "patch" DESC, "revision" DESC, (CASE WHEN "prerelease" = '' THEN 1 ELSE 0 END) DESC, "prerelease" DESC, "build_number" DESC, "build_code" DESC); |
|
This PR has a migration; here is the generated SQL for for --
-- Remove index sentry_release_semver_idx from release
--
DROP INDEX CONCURRENTLY IF EXISTS "sentry_release_semver_idx";
--
-- Create index sentry_release_semver_idx on F(organization), OrderBy(F(major), descending=True), OrderBy(F(minor), descending=True), OrderBy(F(patch), descending=True), OrderBy(F(revision), descending=True), OrderBy(CASE WHEN <Q: (AND: ('prerelease', ''))> THEN Value(1), ELSE Value(0), descending=True), OrderBy(F(prerelease), descending=True), OrderBy(F(build_number), descending=True), OrderBy(F(build_code), descending=True) on model release
--
CREATE INDEX CONCURRENTLY "sentry_release_semver_idx" ON "sentry_release" ("organization_id", "major" DESC, "minor" DESC, "patch" DESC, "revision" DESC, (CASE WHEN "prerelease" = '' THEN 1 ELSE 0 END) DESC, "prerelease" DESC, "build_number" DESC, "build_code" DESC); |
| ("sentry", "1003_group_history_prev_history_safe_removal"), | ||
| ] | ||
|
|
||
| operations = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i will let the folks on the db migration reviewers group chime in but i think we want to first create the new index, then drop the old one after in a separate migration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we should switch these if we go ahead with this
wedamija
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you describe the queries you want to make with this?
My vague memory of this that build number/code didn't make sense to sort by. Do you have some example rows here just so I can make sure I'm following this correctly?
| ("sentry", "1003_group_history_prev_history_safe_removal"), | ||
| ] | ||
|
|
||
| operations = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we should switch these if we go ahead with this
@wedamija Yes definitely. According to the semver spec build code should not be included in the semver ordering. However it turns out that when detecting regressions we have been including the build_number and build_code columns in the ordering (see these test cases in my followup PR, which demonstrate the existing behavior for regression detection and act as our "target" behavior for semver ordering). We also have a case here (thread here) for the resolve in next release feature which points out this inconsistency. By adding the build code and number to the semver ordering, we can make sure that the "next" release picked to resolve by follows the same ordering. Here is the test I modified in the followup to confirm and demonstrate the new ordering. I'll make sure to create a new index for this. The changes in the followup PR will also be gated under a new feature flag (WIP) so we can roll this out safely. |
4a89b6c to
35fe4a5
Compare
|
This PR has a migration; here is the generated SQL for for --
-- Create index sentry_release_semver_new_idx on F(organization), OrderBy(F(major), descending=True), OrderBy(F(minor), descending=True), OrderBy(F(patch), descending=True), OrderBy(F(revision), descending=True), OrderBy(CASE WHEN <Q: (AND: ('prerelease', ''))> THEN Value(1), ELSE Value(0), descending=True), OrderBy(F(prerelease), descending=True), OrderBy(CASE WHEN <Q: (AND: ('build_code__isnull', False), ('build_number__isnull', True))> THEN Value(2), WHEN <Q: (AND: ('build_number__isnull', False))> THEN Value(1), ELSE Value(0), descending=True), OrderBy(F(build_number), descending=True), OrderBy(F(build_code), descending=True) on model release
--
CREATE INDEX CONCURRENTLY "sentry_release_semver_new_idx" ON "sentry_release" ("organization_id", "major" DESC, "minor" DESC, "patch" DESC, "revision" DESC, (CASE WHEN "prerelease" = '' THEN 1 ELSE 0 END) DESC, "prerelease" DESC, (CASE WHEN ("build_code" IS NOT NULL AND "build_number" IS NULL) THEN 2 WHEN "build_number" IS NOT NULL THEN 1 ELSE 0 END) DESC, "build_number" DESC, "build_code" DESC); |
Ok, this all sounds reasonable. One thing I want to check is whether the index will actually be used here. It might be fine to leave the existing index as is, since maybe there aren't that many builds per release. Are you able to print out an actual sql query that uses this sort so that we can verify whether the new columns in this index will get used? |
|
@wedamija The use case I'm interested in is the greatest_semver_release function, which with the changes would generate a sql query like this. Would of course be easier to skip having to create the new index if possible--let me know what you think. |
As is, this index won't be used for the build columns because we're sorting on
|
|
Update: We think it's ok to skip rebuilding the index when adding the build code columns to the semver ordering. We'll monitor the latency of the query on Datadog when changes are deployed. |
relates to REPLAY-803
followup: #102711