gpt4 book ai didi

mysql - 我怎样才能说服这个 MYSQL 查询使用索引?

转载 作者:可可西里 更新时间:2023-11-01 08:53:14 25 4
gpt4 key购买 nike

下面是有关查询的解释..

    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>

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

最佳答案

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

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

关于mysql - 我怎样才能说服这个 MYSQL 查询使用索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9484063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com