简体   繁体   中英

Choices VS Charfield in filtering

If database(Django ORM) is based on data which is parsed . And there is a 'city' field, which is often used when filtering data. Is it much better to use Chocies or just Charfield for saving 'city' into the field. Will be filtering much faster?

Choices field like positiveintegerfield will has smaller size than charfield if you save cities as [(1, 'NY'),(2, ' LA')] in positiveintegerfield but at query complexity time I think integer will win

Int comparisons are faster than varchar comparisons, for the simple fact that ints take up much less space than varchars.

This holds true both for unindexed and indexed access. The fastest way to go is an indexed int column.

for postgresql, you might be interested in the space usage of different date types:

int fields occupy between 2 and 8 bytes, with 4 being usually more than enough ( -2147483648 to +2147483647 )
character types occupy 4 bytes plus the actual strings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM