简体   繁体   中英

MYSQL InnoDB engine indexing (B-Tree)

I have the following 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.

User_vars is a field that the user might be updating on daily basis (or even weekly); 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. Based on the table likely queries are for User_name and Email. Change those to CHAR and index those.

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