[英]getting data from result set is too slow
從帶有結果集的PostgreSQL數據庫中獲取數據太慢。
這是我的代碼。
for (int i = 0; i < qry_list.size(); i++) {
try {
resultSet = statement.executeQuery(qry_list.get(i));
resultSet.setFetchSize(0);
while (resultSet.next()) {
totalfilecrated = totalfilecrated
+ resultSet.getInt(columnname);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
在這里我嘗試在for循環中獲取數據,這樣好嗎?
這是我的查詢。
用於獲取各個組織的ID( org_unit_id
)。
"select org_unit_id from emd.emd_org_unit where org_unit_id
in(select org_unit_id from emd.emd_org_unit_detail where entity_type_id=1 and is_active=true) and
is_active=true order by org_unit_name_en";
然后我想獲取每個org_unit_id
的文件數
select count(*) as totalfilecreatedelectronic from fl_file ff
left join vw_employee_details_with_department epd on epd.post_detail_id=ff.file_opened_by_post_fk
where ff.file_nature = 'E' and ((ff.migration_date>='2011-01-01' and ff.migration_date<='2015-01-01') or
(ff.opening_date >='2011-01-01' and ff.opening_date <='2015-01-01')) and
epd.departmentid=org_unit_id";
看到第二個查詢如何已經包含對org_unit_id列的引用,您可能會認為直接將emd_org_unit表加入其中:
select org.org_unit_id, count(*) as totalfilecreatedelectronic
from fl_file ff
left join vw_employee_details_with_department epd on epd.post_detail_id=ff.file_opened_by_post_fk
-- join to active entries in emd_org_unit
inner join from emd.emd_org_unit org ON epd.departmentid=org.org_unit_id
AND org.is_active=true
where ff.file_nature = 'E'
and (
(ff.migration_date>='2011-01-01' and ff.migration_date<='2015-01-01') or
(ff.opening_date >='2011-01-01' and ff.opening_date <='2015-01-01'))
-- and now group by org_unit_id to get the counts
group by org_unit_id
如果您為此創建一個SQLFiddle,我想事情將會變得更加清晰。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.