incuna / django-pgcrypto-fields

Transparent field level encryption for Django using the pgcrypto postgresql extension.
BSD 2-Clause "Simplified" License
229 stars 49 forks source link

Performance #576

Closed some1ataplace closed 8 months ago

some1ataplace commented 10 months ago

https://stackoverflow.com/questions/72642457/django-pgcrypto-fields-taking-long-time-to-load

https://stackoverflow.com/questions/62511078/django-postrgresql-performance-issues

Would like to have a discussion to see if there is anything we can all do to improve performance.

peterfarrell commented 8 months ago

Using a .filter on email requires PGSQL to unencrypt every single row in your table in order to make the comparison to your comparison value.

One workaround is to keep a hash on the email field using the HashField:

https://github.com/incuna/django-pgcrypto-fields#hash-based-fields

Then filter on the hash value instead of the encrypted value instead

my_model = MyModel.objects.filter(email_hashed__hash_of='me@example.com')