gpt4 book ai didi

mysql - 应为此 MySQL 查询创建哪些索引

转载 作者:行者123 更新时间:2023-11-29 08:57:19 25 4
gpt4 key购买 nike

如果我有以下查询,可以创建哪些索引来加快速度?

SELECT `residentials`.* 
FROM `residentials`
WHERE
(is_active = 1) AND
(
(created_at > '2012-02-20 20:51:56' OR modified > '2012-02-20 20:51:56') AND
list_price >= 229000 AND
list_price <= 311000 AND
square_feet >= '1223' AND
square_feet <= '1654' AND
property_type IN ('commercial','condo','detached','house','multi','rowtownhouse','semidetached') AND
(zip LIKE '%19147%')
)
ORDER BY list_price DESC

仅供引用,此查询是由 Rails 生成的,因此我无法完全控制它的构造方式。

使用 EXPLAIN 会产生以下结果:

id=1

select_type = 简单

表格=住宅

类型=范围

可能的键=index_residentials_on_list_price、index_residentials_on_property_style、index_residentials_on_square_feet、index_residentials_on_modified、index_residentials_on_is_active、index_residentials_on_is_active_and_board_id、index_residentials_is_active_board_id_list_price_property_type、index_residentials_ on_is_active_and_created_at_and_modified、dates_and_type、dates_type_price、board_price_type_zip、board_price_type_zip_mls

键=index_residentials_on_list_price

key_len = 6

引用=空

行数 = 209272

额外 = 使用位置

最佳答案

你尝试过吗:

EXPLAIN SELECT `residentials`.* 
FROM `residentials`
WHERE
(is_active = 1) AND
(
(created_at > '2012-02-20 20:51:56' OR
modified > '2012-02-20 20:51:56') AND
list_price >= 229000 AND
list_price <= 311000 AND
square_feet >= '1223' AND
square_feet <= '1654' AND
property_type IN ('commercial','condo','detached','house','multi','rowtownhouse','semidetached') AND
(zip LIKE '%19147%')
)
ORDER BY list_price DESC

关于mysql - 应为此 MySQL 查询创建哪些索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9620843/

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