小時後我將步槍折以下命令:
CREATE INDEX idx_qry_status ON queries(status);
當你的查詢執行表,從業人員沒有任何指標。
請參閱Create Index上的手冊頁。
視覺的後,表明智的(不是性能明智):
create table queries
( id bigint auto_increment primary key,
status int null
-- partial definition
);
insert queries (status) values (7),(2),(1),(4),(1),(5),(9),(11);
CREATE INDEX idx_qry_status ON queries(status);
show indexes from queries;
+---------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+---------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| queries | 0 | PRIMARY | 1 | id | A | 8 | NULL | NULL | | BTREE | | |
| queries | 1 | idx_qry_status | 1 | status | A | 8 | NULL | NULL | YES | BTREE | | |
+---------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
謝謝,我想我在做一個備份,現在我想它。 – Vasilis
工程很好,查詢時間從11分鐘下降到不到1秒。我正在閱讀一篇關於MySQL索引的有趣文章,它解釋了很多內容https://www.dreamhost.com/blog/2013/08/27/mysql-indexing-basics/ – Vasilis