java - While loop takes too much time -
this select statement returns 4k+ rows. takes time in application while-loop. loop alone takes 2 4 minutes. ideas on how optimize it?
don't worry query doesn't take time on query response.
arraylist<membershipmemberinterestsvo> list = new arraylist<membershipmemberinterestsvo>(); stringbuffer sql = new stringbuffer(); sql.append("select to_char(mai.id_info) id, "); sql.append("to_char(mai.field_title) title, "); sql.append("to_char(mmi.member_id) membership_id "); sql.append("from memserv_member_interests mmi, memserv_add_info mai "); sql.append("where mmi.interests '%-' || mai.memserv_id || '-%' "); sql.append("and mai.soc_body_id = ? "); sql.append("union "); sql.append("select to_char(mit.interest_id) id, "); sql.append("to_char(mit.text) title, "); sql.append("to_char(mit.member_id) membership_id "); sql.append("from memserv_member_interest_text mit "); sql.append("where society_id = ?"); pstmt = conn.preparestatement(sql.tostring()); pstmt.setstring(1, societyid); pstmt.setstring(2, societyid); rs = pstmt.executequery(); membershipmemberinterestsvo vo = null; while (rs.next()) { vo = new membershipmemberinterestsvo(); vo.setinterestid(rs.getstring("id")); vo.setmembershipid(rs.getstring("membership_id")); vo.settitle(rs.getstring("title")); vo.setsocietyid(societyid); list.add(vo); }
the problem sql statement. adding 4,000 entries list, doesn't take noticeable amount of time.
if not typo
where mmi.interests '%-' || mai.memserv_id || '-%'
you end whole table result set.
Comments
Post a Comment