java - 从mysql中查询数据,然后插入到另一个数据库中,怎样提升这个代码的运行速度
巴扎黑
巴扎黑 2017-04-17 17:51:11
0
2
625

我从mysql中查询数据,然后将查询到的数据插入到另一个数据库中,目前速度查询5000个并插入的速度大概在45秒到200秒之间。怎样可以提升它的速度。
这条sql本身的执行时间在numiid很多的时候或者表中数据较多的时候就较慢,有时在1.6秒以上
sql:
select ir.id,iss.numIid,iss.bid,b.bname as bT,iss.cid,c.name as cT,iss.userId ,ss.shopTitle,iss.title as itemTitle,ir.type,ir.page,if(count(keyword) is null,0,count(keyword)) keywordCount1,IF(k.ssrq is null, 0,sum(k.ssrq )) ssrqCount1,if(iss.sales!=-1,iss.sales,IF(iss.trades!=-1,iss.trades,iss.receivers)) salesCount1

    from table iss
    inner join table0  ir  on iss.numIid=ir.numIid
    <if test="type != null"> and ir.type =#{type}</if> 
    <if test="type == null"> and ir.type in (1,2,3,4,11,12,13,21,22,31,32)</if>
    <if test="page != null"> and ir.page =#{page}</if> 
    <if test="page == null"> and ir.page in(1,2,3,4,5,6,7,8,9,10) </if> 
    left join table1_${batchId} k on ir.keyword =k.id
    left join table2_${batchId} ss on ss.userId =iss.userId
    left join table3  b  on iss.bid=b.bid 
    left join table4  c  on iss.cid=c.id
    where iss.numIid  in (
        <foreach collection="numIids" item="numIid" separator=",">
          #{numIid}
        </foreach>
    )
    group by iss.numIid,ir.page,ir.type
巴扎黑
巴扎黑

모든 응답(2)
大家讲道理

45초에서 200초까지의 시간은 엄청납니다.
1. 작성한 SQL이 너무 복잡합니다. SQL을 단순화하고 코드에서 일부 논리 처리를 실행하는 것이 좋습니다.
2. 다른 데이터베이스에 저장하고 일괄 제출을 고려하세요.

大家讲道理

1. 쿼리의 첫 번째 단계는 최적화할 여지가 있는지 확인하는 것입니다. 1초 이상 쿼리하면 인덱스가 사용되는지 확인합니다.
2. 삽입 논리의 의사 코드를 게시할 수 있습니까? 삽입 작업을 어떻게 하는지 모르겠습니다. 5,000개의 데이터를 삽입하는 데 수십 초가 걸리지 않을 것 같습니다.

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿