我不知道为什么这个查询运行速度非常慢,如果表有180多万条记录的数据。我连接的数据库是DB2。jdbcTemplate.query运行缓慢,数百万条记录
public CustomerEmailFreq getFreqCodeByEmail(String email, String domain) {
CustomerEmailFreq customerEmailFreq = new CustomerEmailFreq();
Map namedParameters = new HashMap();
namedParameters.put("email", email);
namedParameters.put("domain", domain);
String sql = "select freq_cde,email_local,email_domain,last_src_date,last_src_time from ADDRESS where upper(email_local)=upper(:email) and upper(email_domain)=upper(:domain) ORDER BY TIMESTAMP(LAST_SRC_DATE,LAST_SRC_TIME) DESC FOR READ ONLY WITH UR FETCH FIRST ROW ONLY";
this.jdbcTemplate.query(sql, namedParameters, (rs, rowNum) ->
{
customerEmailFreq.setEmailDomain(rs.getString("EMAIL_DOMAIN").trim());
customerEmailFreq.setEmailLocal(rs.getString("EMAIL_LOCAL").trim());
customerEmailFreq.setFreqCode(rs.getString("FREQ_CDE"));
customerEmailFreq.setLastSrcDate(rs.getString("LAST_SRC_DATE"));
customerEmailFreq.setLastSrcTime(rs.getString("LAST_SRC_TIME"));
return null;
});
return customerEmailFreq;
}
任何提示,以帮助这一点。
查询需要多长时间直接在db上运行? 你为什么返回null? –
它需要超过4分钟。因为我已经使用lambda表达式,所以必须返回null。 –
你为什么期望它跑得快? – mustaccio