【发布时间】:2017-08-31 11:59:25
【问题描述】:
ps = (PreparedStatement) connection.prepareStatement(
"SELECT nm.id, nid.key, nm.name, nm.languageCode FROM odds.name as nm JOIN (odds.name_id as nid)\r\n"
+ "ON (nm.id = nid.id) where nm.name like '%' and nid.key not like \"vhc%\" and nid.key not like \"vdr%\" and nid.key not like \"vto%\" and nid.key not like \"vbl%\"\r\n"
+ "and nid.key not like \"vf%\" and nid.key not like \"vfl%\" and nid.key not like \"vsm%\" and nid.key not like \"rgs%\"\r\n"
+ "and nid.key not like \"srrgs%\" and nm.typeId=8 and nm.sourceId=-1 and nm.languageCode = 'en'");
for(Entry <String, Tag> e : allTags.entrySet()) {
ResultSet rs = ps.executeQuery();
while(rs.next()) {
if(rs.getString("name").equals(e.getValue().getTranslation(Language.EN))) {
e.getValue().setAlternativeKey(rs.getString("name"));
break;
}
}
}
);
您有什么想法可以让我更快地做到这一点。我将尝试在数据库中查找一个字符串,并为我的对象添加一个额外的信息。但我必须对 1265 个对象执行此操作,因此程序运行大约 80 秒。
提前致谢!
【问题讨论】:
-
由于 LIKE 语句执行模式匹配,因此成本可能很高。将所有使用 3 个字符后跟百分号的模式的 LIKE 减少到:
(substr(nid.key,1,3) not in ("vhc", "vdr", "vto", "vbl", "vfl", "vsm", "rgs")
标签: java sql database performance