Question

Below is the EXPLAIN for the query in question..

    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>   

I have indexes on the three columns it's trying to do where conditions on but sadly it's not trying to use an index merge. Is the only option to create a multi-column index or is there something that's putting MYSQL off using those indexes?

Was it helpful?

Solution

You have to create a multi-columns index.

For example, to do that in Phpmyadmin, you have to check this different fields of your table and click the 'index' button below the table structure.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top