简体   繁体   English

MySQL Innodb索引混乱

[英]MySQL Innodb indexing confusion

A very basic database design question: 一个非常基本的数据库设计问题:

I'm creating a very large table with the following columns: Employee_Name(VARCHAR), Employee_ID(INT), Employee_Birthday(INT). 我正在创建带有以下列的超大表:Employee_Name(VARCHAR),Employee_ID(INT),Employee_Birthday(INT)。

I wish to create a single column b-tree index for Employee_ID, as many of my queries use SELECT and WHERE clauses based on the values in this column. 我希望为Employee_ID创建一个单列b树索引,因为我的许多查询都基于此列中的值使用SELECT和WHERE子句。

Although I will not be updating the Employee_ID once created, I will be frequently INSERTING new employee's into this table. 尽管创建后不会更新Employee_ID,但我经常将新员工插入该表中。

Does the addition of rows with an indexed column create additional cost compared to no indexing? 与没有索引相比,添加具有索引列的行是否会产生额外的成本? Or does the additional cost only apply when UPDATING existing rows? 还是仅在更新现有行时才需要额外费用?

Create indexes based on the typical SELECTs , UPDATEs , and DELETEs . 根据典型的SELECTsUPDATEsDELETEs创建索引。 Don't worry much about INSERTs ; 不用太担心INSERTs the overhead for one INSERT is a lot less than the speedup for the other operations. 一个INSERT的开销比其他操作的加速要少得多。

With InnoDB, there always is a PRIMARY KEY , so you may as well make it something useful to you. 使用InnoDB时,始终会有一个PRIMARY KEY ,因此您也可以对其进行一些使用。

When evaluating the creation of an index, the KEY question is: Would this table be accessed MOSTLY for queries or for INSERTIONS. 在评估索引的创建时,KEY问题是:是否将表最多用于查询或INSERTIONS。 Also, you need to specify what you mean by very large table (since you are talking about employees, I would guess that the table would host, perhaps, less than 100K records, right?). 另外,您需要指定非常大的表的含义(因为您在谈论员工,所以我猜该表可能托管少于10万条记录,对吗?)。 If you expect to have, say, thousands of INSERTs for each SELECT, you might try going without index. 如果您希望每个SELECT都有数千个INSERT,则可以尝试不使用索引。 If, on the other hand, you will be mainly querying the table, setting an index in your column Employee_ID is the way to go. 另一方面,如果您将主要查询表,则可以在列Employee_ID设置索引。

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

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