MySQL 性能极慢

Extremely slow MySQL performance

我有一个 table,其中包含大约 50 万个作业,每个作业都有一个用作主键的唯一 ID 和一个用于指示作业是挂起、完成还是失败的状态。状态是一个不是键的整数。

我的问题是,我尝试根据状态 select 作业进行简单查询需要太多时间,超过 10 分钟。数据库中连接了大约 46 个线程,我也重新启动了,但这对性能没有帮助。

我在此处粘贴了 table 架构和我尝试 运行 的查询: http://pastie.org/10416054

有没有什么方法可以找到瓶颈并优化 table 从而不需要那么长时间?

下班后我会执行以下命令:

CREATE INDEX idx_qry_status ON queries(status);

由于您的查询正在进行table扫描,因此不使用任何索引。

请参阅 Create Index 上的手册页。

之后的视觉效果,table-明智的(不是性能方面的):

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      |         |               |
+---------+------------+----------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+