3

下面是有问题的查询的解释..

    mysql> EXPLAIN SELECT orders_0.id, orders_0.created_at, orders_0.total_amount, orders_0.delivery_date, orders_0.customer_id, orders_0.items_summary, orders_0.site_id, orders_0.depot_id, orders_0.region_id, addresses_0.country, orders_0.payment_status, orders_0.created_by, orders_0.status, orders_0.delivered_by
        -> FROM production.addresses addresses_0, production.orders orders_0
        -> WHERE orders_0.delivery_address_id = addresses_0.id AND ((orders_0.status Not In ('cancelled','checkout','expired')) AND (orders_0.delivery_date>{d '2011-10-31'}));
    +----+-------------+-------------+--------+------------------------------------------+---------+---------+-----------------------------------------------+--------+-------------+
    | id | select_type | table       | type   | possible_keys                            | key     | key_len | ref                                           | rows   | Extra       |
    +----+-------------+-------------+--------+------------------------------------------+---------+---------+-----------------------------------------------+--------+-------------+
    |  1 | SIMPLE      | orders_0    | ALL    | status,delivery_date,delivery_address_id | NULL    | NULL    | NULL                                          | 929330 | Using where | 
    |  1 | SIMPLE      | addresses_0 | eq_ref | PRIMARY                                  | PRIMARY | 4       | production.orders_0.delivery_address_id |      1 |             | 
    +----+-------------+-------------+--------+------------------------------------------+---------+---------+-----------------------------------------------+--------+-------------+
    2 rows in set (0.00 sec)

    mysql>   

我在它试图在 where 条件下执行的三列上有索引,但遗憾的是它没有尝试使用索引合并。是创建多列索引的唯一选择,还是有什么东西让 MYSQL 无法使用这些索引?

4

1 回答 1

1

您必须创建一个多列索引。

例如,要在 Phpmyadmin 中执行此操作,您必须检查表的不同字段并单击表结构下方的“索引”按钮。

于 2012-02-28T15:53:44.813 回答