2014-03-13 55 views
2
select 
    * from table 
where 
    substring(username,1) >= 'A' 
    and substring(username,1) <= 'C' 
    and height_in_meters * 100 > 140 
    and height_in_meters * 100 < 170; 

什么是加快查询的可能方法?它运行很慢优化子串sql查询

回答

1

where username like '[A-C]%'

将允许在username索引的使用(一个应该存在)而不是通过一个总是阻止它的函数传递username

1

没有太多可以优化,但

WHERE username >= 'A' 
    AND username < 'D' 
    AND height_in_meters > 1.4 
    AND height_in_meters < 1.7; 

那么你可以使用计算

1

我不认为你可以从你的查询中获得很多性能改进。 也许通过删除子字符串,但这是我能想到的。

select 
    * from table 
where 
    username >= 'A' AND username <= 'CZ' 
    and height_in_meters * 100 > 140 
    and height_in_meters * 100 < 170; 

我添加了一个ZC所以用户名后开始C也包括