简体   繁体   English

MYSQL InnoDB引擎索引(B树)

[英]MYSQL InnoDB engine indexing (B-Tree)

I have the following user registration table : 我有以下user registration table

      ID INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
      User_name VARCHAR(35) NOT NULL,
      Full_name VARCHAR(55) NOT NULL,
      User_vars VARCHAR(255) NOT NULL,
      BirthDay DATE NOT NULL,
      password CHAR(70) NOT NULL,  
      Security_hint VARCHAR(27) NOT NULL,
      Email VARCHAR(225) NOT NULL,
      userType ENUM ('a','b','c','d') NOT NULL DEFAULT 'a',
      Signup_Date TIMESTAMP NOT NULL  DEFAULT CURRENT_TIMESTAMP,
      activation   TINYINT(1) UNSIGNED NOT NULL,
      Ip BINARY(16) NOT NULL,
      PRIMARY KEY (ID),
      UNIQUE KEY User_name (User_name,Email)

I am really confused to whether I SHOULD index the fields BirthDay, Signup_Date, Full_name, User_vars and userType as this information will have to be displayed in any page the user visits. 我真的对是否应该为字段BirthDay, Signup_Date, Full_name, User_vars and userType编制索引感到困惑,因为此信息将必须显示在用户访问的任何页面中。

User_vars is a field that the user might be updating on daily basis (or even weekly); User_vars是用户可能每天(甚至每周)更新的字段; I think that indexing this field might not be good idea as indexes slow down write operations; 我认为索引这个字段可能不是一个好主意,因为索引会减慢写操作的速度。 correct me if wrong. 如果有错请纠正我。 I have many other fields like this one in other tables (fields that user updates on daily basis and their updates have toble displayed in any page they visit ), and don't know if they have to be indexed as well 我在其他表格中还有许多其他字段(用户每天更新的字段,并且他们的更新都显示在他们访问的任何页面上的字段),并且不知道是否也需要对其进行索引

Note: I know that I can query them once then cache them, however I am afraid that the first query to the table will be slow to return the result-set. 注意:我知道可以查询一次然后将其缓存,但是,恐怕对表的第一个查询返回结果集的速度会很慢。

Many thanks 非常感谢

For performance change the VARCHAR to TINYTEXT which allows the rows to have a fixed size thereby speeding up table scans. 为了提高性能,请将VARCHAR更改为TINYTEXT,这允许行具有固定的大小,从而加快了表扫描的速度。 Based on the table likely queries are for User_name and Email. 根据该表,可能会查询User_name和Email。 Change those to CHAR and index those. 将其更改为CHAR并为其编制索引。

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

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