简体   繁体   English

MySQL在Varchar字段上的唯一索引-优点和缺点?

[英]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)
...
  1. Will the be any major benefit from indexing the slugname? 索引slugname会带来什么主要好处吗?
  2. Since the slugname is unique will UNIQUE index be preferred over fulltext index? 由于slugname是唯一的,相对于fulltext索引, UNIQUE索引会被首选吗?
  3. Any cons of indexing the varchar field? 索引varchar字段有什么弊端?
  4. Would fulltext give me any benefits over UNIQUE index? fulltext会给我带来优于UNIQUE索引的任何好处?
  5. Would Django queries benefit from the index? Django查询会从索引中受益吗?

I can't anwser all of your questions, but: 我无法回答您所有的问题,但是:

  1. YES, lookup queries for specific slug names will be dramatically increased on a large set of data. 是的,针对大量数据的查找查询将大大增加。

  2. 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中正确处理它即可

  3. in todays systems, i would say no, particularly one that is only 50 characters. 在当今的系统中,我会拒绝,尤其是只有50个字符的系统。

  4. 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可以告诉您每个优点和缺点,您可以将其应用于您的情况/用法

  5. Yes, see #1. 是的,请参阅#1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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