Skip to content

Instantly share code, notes, and snippets.

@susmithagudapati
Created April 27, 2020 18:31
Show Gist options
  • Save susmithagudapati/b71e64579da59beb56e26c1ac4ed5f11 to your computer and use it in GitHub Desktop.
Save susmithagudapati/b71e64579da59beb56e26c1ac4ed5f11 to your computer and use it in GitHub Desktop.
# these 2 queries are faster because upc & id are unique and indexed.
product = Product.objects.get(upc='PXO01')
product = Product.objects.get(id=33)
# this is much slower than above queries because name isn't indexed.
product = Product.objects.get(name='Neon Shoes')
# this query can have multiple matches which hinders query performance.
product = Product.objects.get(name__startswith='Neon')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment