gpt4 book ai didi

sql - 缓慢的 mysql 查询。有小费吗?

转载 作者:行者123 更新时间:2023-12-01 00:33:32 26 4
gpt4 key购买 nike

我有以下查询...它有效但运行速度极慢。希望有人能给我一些改进执行时间的技巧吗?

SELECT tb_clients.*, tb_clients_phone_fax.*
FROM tb_clients, tb_clients_phone_fax
WHERE tb_clients.client_id=tb_clients_phone_fax.client_id
AND MATCH (client_company,client_description,client_keywords) AGAINST ('test') > 0
AND CONCAT(client_address,' ',client_city,', ',client_state,' ',client_zip) LIKE '%brooklyn%'
LIMIT 10;

编辑:

这是表格信息:

CREATE TABLE `tb_clients` (
`client_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`client_company` varchar(254) NOT NULL,
`client_address` varchar(254) NOT NULL,
`client_street` varchar(254) NOT NULL,
`client_city` varchar(254) NOT NULL,
`client_state` varchar(254) NOT NULL,
`client_zip` varchar(45) NOT NULL,
`client_email` varchar(254) NOT NULL,
`client_website` varchar(254) NOT NULL,
`client_description` text NOT NULL,
`client_keywords` text NOT NULL,
PRIMARY KEY (`client_id`) USING BTREE,
FULLTEXT KEY `client_company` (`client_company`,`client_description`,`client_keywords`)
) ENGINE=MyISAM AUTO_INCREMENT=68347 DEFAULT CHARSET=latin1;

CREATE TABLE `tb_clients_phone_fax` (
`client_phone_fax_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`client_id` int(11) unsigned NOT NULL,
`client_phone_1` varchar(45) NOT NULL,
`client_phone_2` varchar(45) NOT NULL,
`client_phone_3` varchar(45) NOT NULL,
`client_fax_1` varchar(45) NOT NULL,
`client_fax_2` varchar(45) NOT NULL,
`client_fax_3` varchar(45) NOT NULL,
PRIMARY KEY (`client_phone_fax_id`) USING BTREE
) ENGINE=MyISAM AUTO_INCREMENT=33944 DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;

最佳答案

tb_clients.client_id 和 tb_clients_phone_fax.client_id 应该被索引。

但主要问题似乎是两个字符串比较,MATCH 和 LIKE 与 CONCAT。你确定周围没有其他 war 吗?比如,避免在执行 LIKE 语句之前连接所有地址字段?

更新: tb_clients_phone_fax.client_id 似乎没有编入索引,如果编入索引会提高性能。

关于sql - 缓慢的 mysql 查询。有小费吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1911229/

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