我優化更新查詢:Mysql的innodb的:選擇索引類型爲「大於> =」選擇
UPDATE projects SET rgt = rgt + 2 WHERE rgt >= @superRgt;
該表具有很多行(〜63000),並在查詢運行緩慢。當我
explain SELECT * FROM projects WHERE rgt >= @superRgt;
我得到這樣的結果:
+----+-------------+----------+------+---------------+------+---------+------+-------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+------+---------------+------+---------+------+-------+-------------+
| 1 | SIMPLE | projects | ALL | rgt | NULL | NULL | NULL | 69971 | Using where |
+----+-------------+----------+------+---------------+------+---------+------+-------+-------------+
的RGT鍵定義爲:
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| projects | 1 | rgt | 1 | rgt | A | 72770 | NULL | NULL | | BTREE | |
+----------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
我想知道如果我可以通過選擇索引優化更新查詢可以與WHERE rgt >= @superRgt
一起使用的類型?
如何63K行的很多沒有查詢實際更新? – nos 2011-02-09 00:00:31