public class School{
private int id;
private String schoolName;
private String schoolCode;
private String schoolType;
private int version;
……
// 假设这个类的成员超出16个
}
1、现在我要做个查询,查询的方法是:
List<School> get(int version, List<String>schoolType, int schoolCode);
2、假如schoolType为空,则查询所有的schoolType,或者说就不把schoolType当做查询条件。schoolCode同理。
3、假如schoolType和schoolCode都为空,则根据version一次最多可以查出大概12w的数据。目前总数据量大概是200w。
4、关于这个方法的相关情况
4.1、目前的sql写法是
select id, schoolName, schoolCode, schoolType, version, ... from school where version=#{version} <if test"schoolCode!=null"> and schoolCode=#{schoolCode} </if> <if test"schoolType!=null"> and schoolType in ... </if>
4.2、我做的优化
4.2.1、加了索引
4.2.1.1、给分别给version, schoolType, schoolCode加了普通索引
4.2.1.2、给version, schoolType, schoolCode建立联合索引
4.2.2、在mybatis那里设置default-fetch-size
4.2.2.1、设置成1w、10w、20w、100w、1000w
4.3、基于4.2的结果
4.3.1、不管是建普通索引,还是建立联合索引,还是普通索引和联合索引一起用。用postman做请求,响应最快都要3s以上。
4.3.2、设置default-fetch-size,感觉加了以后查询反而慢了一些。
请问有没有别的方面可以优化呢?我目前的处理有没有哪个地方没做好呢?请大神指教,谢谢~
按上面的描述一次如果返回12W条数据,优化的空间确实就很有限了。几个点可以试试