-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
The email index is not used by get_by_email()
method
#4
Comments
Thank you for raising this, @stephane! That's indeed a welcome optimization. My preference would go for 2, i.e. create a functional index. I prefer not to rely on custom extension, especially since CIText looks only designed for PostgreSQL. As for storing the e-mail in lower-case, this is a debate we had some time ago and we purposefully chose to store the e-mails case-sensitive but query them case-insensitive. If you agree with this, I would be happy to review a PR that creates a lowercased index for e-mails 🙂 |
Django offers the possibility to provide migrations in third-apps code but I didn't find a similar mechanism with Alembic. With the new
So I had to manually create the Alembic migration in my project and it's convenient for users of fastapi-users. op.create_index("ix_user_email_lower", "user", [sa.text("lower(email)")]) |
Describe the bug
An index is created on the
email
field:https://github.com/fastapi-users/fastapi-users-db-sqlalchemy/blob/main/fastapi_users_db_sqlalchemy/__init__.py#L61
but the index can't be used by the
get_by_email()
method because the filtering uses a function on the SQL field.To Reproduce
Sequential scan is used instead of index scan.
Expected behavior
There is several ways to fix the issue:
CREATE INDEX ix_auth_user ON auth_user (lower(email) text_pattern_ops);
I can provide a PR when we'll agree on a solution.
Configuration
The text was updated successfully, but these errors were encountered: