Mysql在通配符搜索上的表现

时间:2022-09-01 22:13:08

Is there a performance difference between these two queries ?

这两个查询之间是否存在性能差异?

1) Select * from table;

1)从表中选择*;

2) Select * from table where column like '%';

2)从表中选择*,其中列为'%';

Both the queries return me the same result set.

两个查询都返回相同的结果集。

1 个解决方案

#1


1  

If both return the same results, then the LIKE query is almost certainly less efficient, because it has to get the same results from the database and check the LIKE clause, even though it doesn't do anything.

如果两者都返回相同的结果,那么LIKE查询几乎肯定效率较低,因为它必须从数据库获得相同的结果并检查LIKE子句,即使它没有做任何事情。

That said, you should benchmark it yourself and see if it makes a difference. It's hard to think of a situation where both would be valid queries though.

也就是说,您应该自己进行基准测试,看看它是否有所作为。很难想到两者都是有效查询的情况。

#1


1  

If both return the same results, then the LIKE query is almost certainly less efficient, because it has to get the same results from the database and check the LIKE clause, even though it doesn't do anything.

如果两者都返回相同的结果,那么LIKE查询几乎肯定效率较低,因为它必须从数据库获得相同的结果并检查LIKE子句,即使它没有做任何事情。

That said, you should benchmark it yourself and see if it makes a difference. It's hard to think of a situation where both would be valid queries though.

也就是说,您应该自己进行基准测试,看看它是否有所作为。很难想到两者都是有效查询的情况。