需要使用索引和全文索引的快速mysql查询
尝试进行基准测试,但只有简单的全文本索引查询才能很好地进行,其他结果是不可接受的(通常超过一分钟)。
mysql安装在具有4 cpu和8GB RAM的容器上。
表格:
-raw_products有超过700万行
-primary key int
-columns provider_id-索引,foregin键(大约20个id)
-column名称-全文索引,索引;带有“孕妇红色褶皱裹身连衣裙”之类的数据
pointed
只是我尝试返回1000-40000行的示例单词
SELECT count(*) FROM `raw_products` WHERE match(Name) against ('+pointed' in boolean mode);
0.01 s
SELECT count(*) FROM `raw_products` WHERE providers_id=1 and match(Name) against ('+pointed' in boolean mode);
48.35 s
SELECT count(*) FROM `raw_products` WHERE match(Name) against ('+pointed' in boolean mode) and id_raw_products in (select id_raw_products from raw_products where providers_id=1);
不能接受
SELECT count(*) FROM `raw_products` WHERE id_raw_products in (select id_raw_products from raw_products where providers_id=1) and match(Name) against ('+pointed' in boolean mode);
不能接受
SELECT count(*) FROM (select * FROM `raw_products` WHERE providers_id=1) rp where match(rp.Name) against ('+pointed' in boolean mode);
不能接受
SELECT count(*) FROM raw_products WHERE EXISTS (SELECT id_raw_products FROM raw_products as rp WHERE providers_id = 1 AND rp.id_raw_products = raw_products.id_raw_products) AND MATCH (raw_products.`Name`) AGAINST ('+pointed' IN BOOLEAN MODE);
不能接受
结果:
1.约0.01 s
2.约48.35 s
比分钟长3,4,5,6
当搜索到的单词不在表格中时,每个查询都会快速运行
期望:
表现出色(不到一秒)的查询即可获取匹配的行