我有索引列'unique_identifier'。當我使用索引列獲取數據時,它不會使用索引獲取數據。varchar不工作的索引列
mysql> show index from stock_index_table;
+-------------------+------------+-------------------+--------------+-------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------------------+------------+-------------------+--------------+-------------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| stock_index_table | 0 | PRIMARY | 1 | id | A | 4393 | NULL | NULL | | BTREE | | |
| stock_index_table | 1 | unique_identifier | 1 | unique_identifier | A | 4393 | NULL | NULL | | BTREE | | |
當使用'explain extended'進行檢查時,顯示'using where'而不是'using index'。這是否意味着數據沒有使用索引列獲取?以下是選擇查詢的'explain extended'結果。
mysql> explain extended select id
from stock_index_table
where unique_identifier='Nifty' ;
+----+-------------+-------------------+------+-------------------+-------------------+---------+-------+------+----------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-------------------+------+-------------------+-------------------+---------+-------+------+----------+--------------------------+
| 1 | SIMPLE | stock_index_table | ref | unique_identifier | unique_identifier | 52 | const | 1 | 100.00 | Using where; Using index |
+----+-------------+-------------------+------+-------------------+-------------------+---------+-------+------+----------+--------------------------+
'explain'的結果應該看起來像Extra。
+--------------------------+
| Extra |
+--------------------------+
| Using index |
+--------------------------+
您可能會發現它有助於閱讀:http://meta.stackoverflow.com/a/271056/ –
是否有實際的** **的問題在這裏或者是它只是你煩惱的是指數沒有被用過的?你的查詢很慢嗎? – Mjh
請提供'SHOW CREATE TABLE'。 –