开发者

What gives better performance: name__iexact=name or name=name.lower() in Django?

开发者 https://www.devze.com 2023-03-07 18:34 出处:网络
I\'m trying to decide if I want to use name__iexact=name or name=name.lower() in a filter quer开发者_如何学JAVAy. What gives better performance? If I\'m storing name always as lowercase.

I'm trying to decide if I want to use name__iexact=name or name=name.lower() in a filter quer开发者_如何学JAVAy. What gives better performance? If I'm storing name always as lowercase.

The strings are not bigger than 10 characters if that matters.


Doing name=name.lower() would perform better as you're only doing the lowercasing once (or it would not be needed since you mention you already stored it in lowercase) and then comparing with equality in the DB

Doing name__iexact=name will be a little slower as the ORM will perform a "LIKE" instead of "=", thus evaluating whether it matches for upper or lower case on each row.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号