Skip to content

Commit

Permalink
simplify select of outgoing batch query and order in Java... even tho…
Browse files Browse the repository at this point in the history
…ugh this query had a low execution plan cost, there was a high number of "buffer gets" reported by an Oracle RAC system
  • Loading branch information
erilong committed Aug 21, 2008
1 parent 207da35 commit 2a4f28e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Expand Up @@ -26,6 +26,8 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -230,8 +232,28 @@ public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, D
*/
@SuppressWarnings("unchecked")
public List<OutgoingBatch> getOutgoingBatches(String nodeId) {
return (List<OutgoingBatch>) jdbcTemplate.query(getSql("selectOutgoingBatchSql"), new Object[] { nodeId },
new OutgoingBatchMapper());
List<OutgoingBatch> list = (List<OutgoingBatch>) jdbcTemplate.query(
getSql("selectOutgoingBatchSql"), new Object[] { nodeId }, new OutgoingBatchMapper());
final HashSet<String> errorChannels = new HashSet<String>();
for (OutgoingBatch batch : list) {
if (batch.getStatus().equals(OutgoingBatch.Status.ER)) {
errorChannels.add(batch.getChannelId());
}
}
Collections.sort(list, new Comparator<OutgoingBatch>() {
public int compare(OutgoingBatch b1, OutgoingBatch b2) {
boolean isError1 = errorChannels.contains(b1.getChannelId());
boolean isError2 = errorChannels.contains(b2.getChannelId());
if (isError1 == isError2) {
return b1.getBatchId() < b2.getBatchId() ? -1 : 1;
} else if (!isError1 && isError2) {
return -1;
} else {
return 1;
}
}
});
return list;
}

@SuppressWarnings("unchecked")
Expand Down
Expand Up @@ -34,11 +34,8 @@
</entry>
<entry key="selectOutgoingBatchSql">
<value>
select b.batch_id, b.node_id, b.channel_id, b.status, b.batch_type, b.create_time from
${sync.table.prefix}_outgoing_batch b left join (select node_id, channel_id from
${sync.table.prefix}_outgoing_batch where status = 'ER') e on e.node_id = b.node_id and
e.channel_id = b.channel_id where b.node_id = ? and b.status in ('NE', 'SE', 'ER') order by
case when e.channel_id is null then 1 else 2 end, b.batch_id
select batch_id, node_id, channel_id, status, batch_type, create_time from
${sync.table.prefix}_outgoing_batch where node_id = ? and status in ('NE', 'SE', 'ER')
</value>
</entry>
<entry key="selectOutgoingBatchRangeSql">
Expand Down

0 comments on commit 2a4f28e

Please sign in to comment.