[英]MySQL Unique Index on Varchar Field - Pros & Cons?
I have a Django app with MySQL table where in addition to querying based on the primary key of the table I also do lots of queries on the slugname of the business name as the slugname is part of the url. 我有一个带MySQL表的Django应用,除了基于表的主键查询外,我还对企业名称的Slugname进行很多查询,因为slugname是url的一部分。
www.mywebsite.com/slug-name/
. www.mywebsite.com/slug-name/
。 The slugname is unique value. slugname是唯一值。
I do have business ID
integer as PRIMARY
key and PRIMARY
index. 我确实有业务
ID
整数作为PRIMARY
键和PRIMARY
索引。
MySQL TABLE: MySQL表:
id - int, pk, primary index
name - varchar(50)
slugname - varchar(50) (is unique value)
...
UNIQUE
index be preferred over fulltext
index? fulltext
索引, UNIQUE
索引会被首选吗? fulltext
give me any benefits over UNIQUE
index? fulltext
会给我带来优于UNIQUE
索引的任何好处? I can't anwser all of your questions, but: 我无法回答您所有的问题,但是:
YES, lookup queries for specific slug names will be dramatically increased on a large set of data. 是的,针对大量数据的查找查询将大大增加。
You should use UNIQUE index, that way you don't have to do a lookup to test for unique, simply let the database throw the error and handle it correctly in django 您应该使用UNIQUE索引,这样就不必进行查找来测试唯一性,只需让数据库抛出错误并在Django中正确处理它即可
in todays systems, i would say no, particularly one that is only 50 characters. 在当今的系统中,我会拒绝,尤其是只有50个字符的系统。
Not sure... i'm betting google can tell you the pro's and cons of each of those and you could apply that to your situation/usage 不确定...我敢打赌Google可以告诉您每个优点和缺点,您可以将其应用于您的情况/用法
Yes, see #1. 是的,请参阅#1。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.