我有一个有两个列的表:"users“有一个全文索引,"x”是一个简单的int列。该表包含的条目略少于200万项。使用match...against选择包含特定用户的行会很快返回。
通过x的值进行搜索(没有索引)在大约3秒内返回。
但是,当我将这两个查询组合在一起时,查询时间为9秒!如果有的话,我希望合并的查询所花费的时间要少得多,因为全文索引会将可能的行减少一个数量级。甚至忘记全文索引和使用like "%___%"也更快!
这里发生了什么事?我怎么才能修好它?
mySQL输出包括以下内容:
mysql> desc testing;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| users | varchar(120) | YES | MUL | NULL | |
| x | int(11) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> select count(*) from testing;
+----------+
| count(*) |
+----------+
| 1924272 |
+----------+
1 row in set (3.56 sec)
mysql> select count(*) from testing where match(users) against("shy");
+----------+
| count(*) |
+----------+
| 149019 |
+----------+
1 row in set (0.42 sec)
mysql> select count(*) from testing where x>0;
+----------+
| count(*) |
+----------+
| 1924272 |
+----------+
1 row in set (3.62 sec)
mysql> select count(*) from testing where match(users) against("shy") and x>0;
+----------+
| count(*) |
+----------+
| 149019 |
+----------+
1 row in set (8.82 sec)
mysql> select count(*) from testing where users like "%shy%" and x>0;
+----------+
| count(*) |
+----------+
| 149019 |
+----------+
1 row in set (3.57 sec)发布于 2018-03-20 13:38:24
始终检查innodb_buffer_pool_size的值,并根据系统的功能和软件需求对其进行调整。这意味着不要给MySQL比您拥有的内存更多的内存:)
如果索引不适合内存,MySQL将从磁盘上读取它,从而限制了硬盘的速度。如果你在使用SSD,这可能是好的,但在机械驱动器它是缓慢的蜗牛。
如果索引不能放入RAM中,它们就没有那么有用。
发布于 2018-03-20 13:12:22
考虑使用子查询。
select count(*) from (
select *
from testing
where match(users) against("shy")
) shy_results
where x>0;https://stackoverflow.com/questions/49385095
复制相似问题