使用
select * from abc as t where t.num = 8898 order by t.create_dt
select * from abc as t where t.num like '8898' order by t.create_dt
select * from abc as t where t.num like reverse('%8898') order by t.create_dt
哪一个最快?
我会说这将是更快的
select * from abc as t where t.num = 8898 order by t.create_dt
为什么?
您正在比较整数,但是您的其他两种方法实际上是比较字符。
此方法实际上是错误的,但可用:
select * from abc as t where t.num like '8898' order by t.create_dt
类似于数据库中的字符串或varchar。
此方法也是错误的,但也是可用的:
select * from abc as t where t.num like reverse('%8898') order by t.create_dt
对于整数,最好使用=,=!,>,<,>=,<=
至于字符串,建议使用要找到包含您要寻找的值的精确字符串。如果要使用通配符查找特定字符串,则可以使用此 LIKE '%something%'
假设 num
是一个数字,第一个
第一个
不应慢于其他。它可以从abc(num, create_dt)
上的索引中受益。
第二个可能很快,除了它将num
转换为字符串。没有索引,这与第一个索引非常小。但是,它可能排除了索引的使用。
第三个几乎是相同的推理。