Consider the distribution of the middle value of a column.For a column with a unique value, the index has the best effect, and a column with multiple repeats has the worst index.For example, the age column has different values and is easy to distinguish between the lines.The columns used to record sex only contain M and F, so indexing this column is not very useful.
For BTREE index, when using >, =, or LIKE'pattern'(where'pattern' does not start with wildcards) operator, the comparison relation between key elements and constant values corresponds to a range condition.Constant values refer to the constants in the query string, the columns in const or system tables in the same connection, the results of irrelevant sub queries, and the expressions which are composed entirely of the preceding subexpressions.
以下是WHERE子句中范围条件查询的示例。
下列范围查询适合B树索引和哈希索引:
复制代码代码如下:SELECT * FROM T1,key_col = 1或key_col在(15,18,20);
下列范围查询适用于btree索引
复制代码代码如下:SELECT * FROM T1,key_col > 1和key_col<10;
SELECT * FROM T1,key_col like'ab %或key_col between'bar;