Authored by qinchao

sql查询计算耗时

... ... @@ -20,11 +20,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* Created by craig.qin on 2017/6/26.
... ... @@ -147,6 +145,7 @@ public class SqlOperateServiceImpl implements SqlOperateService {
BaseResponse res=null;
Map<String,Object> rtnList=new HashMap<String,Object>();
String queryDescr="";
long compareTs=-1;
String hasNext="no";//分页,是否存在下一页
boolean showSeqNOColumn=false;
String seqNOColumnName="_seqno_column_numberIndex";
... ... @@ -196,6 +195,10 @@ public class SqlOperateServiceImpl implements SqlOperateService {
rtnList.put("showPi",false);
}
//
Calendar beginCal = Calendar.getInstance();
long beginTs = beginCal.getTime().getTime();
st = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
st.setFetchSize(SqlQueryConstant.FETCH_COUNT_FROM_MYSQL);
//不是desc的查询需要限定数量了
... ... @@ -205,6 +208,18 @@ public class SqlOperateServiceImpl implements SqlOperateService {
}
rs = st.executeQuery(sql);
//计算耗时
Calendar endCal = Calendar.getInstance();
long endTs = endCal.getTime().getTime();
compareTs = endTs - beginTs;
int test =rs.getRow();
System.out.println("==**"+test);
rs.last();
test = rs.getRow();
System.out.println("==**"+test);
rs.beforeFirst();
rs.relative(SqlQueryConstant.MAX_QUERY_RESULT_COUNT*sqlOperateModel.getCurrentPage());
JSONArray ja_column=new JSONArray();
... ... @@ -373,6 +388,9 @@ public class SqlOperateServiceImpl implements SqlOperateService {
}
}
rtnList.put("queryDescr", StringUtils.isBlank(queryDescr)?("本页共查询到"+count+"条数据"):queryDescr);
if(compareTs>=0){
rtnList.put("queryDescr",rtnList.get("queryDescr")+",总耗时 " + compareTs+"ms ");
}
rtnList.put("queryCount",count);
rtnList.put("hasNext",hasNext);
res=new BaseResponse();
... ...