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

[Technical] Consider adding a database index on Upper(slug) in Organization model #87679

Open
floels opened this issue Mar 22, 2025 · 2 comments

Comments

@floels
Copy link
Contributor

floels commented Mar 22, 2025

Problem Statement

When reading through the code of the Organization model, I saw this old TODO:

class Meta:
app_label = "sentry"
db_table = "sentry_organization"
# TODO: Once we're on a version of Django that supports functional indexes,
# include index on `upper((slug::text))` here.

Since Sentry is now running on Django 5.1, which supports functional indexes, and I don't see the index on Upper(slug) created anywhere in the meantime, I was wondering whether it'd be worth creating this database index to improve the performances in production.

If not, we might want to remove the TODO to clean up the code.

Solution Brainstorm

We could add the index as suggested by the TODO by declaring it at the same place:

class Meta:
    app_label = "sentry"
    db_table = "sentry_organization"
    indexes = [
        models.Index(
            models.functions.Upper("slug"),
            name="organization_slug_upper_idx",
        )
    ]

which would result in a migration file in the likes of:

class Migration(CheckedMigration):
   (...)

    operations = [
        migrations.AddIndex(
            model_name="organization",
            index=models.Index(
                django.db.models.functions.text.Upper("slug"), name="organization_slug_upper_idx"
            ),
        ),
    ]

Product Area

Other

@getsantry
Copy link
Contributor

getsantry bot commented Mar 22, 2025

Assigning to @getsentry/support for routing ⏲️

@getsantry
Copy link
Contributor

getsantry bot commented Mar 24, 2025

Routing to @getsentry/product-owners-other for triage ⏲️

@getsantry getsantry bot moved this from Waiting for: Support to Waiting for: Product Owner in GitHub Issues with 👀 3 Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for: Product Owner
Development

No branches or pull requests

2 participants