****进公司不久,因为要完成百万级的数据量查询 ,以前没有接触过这方面,在mybatis中
用自己书写的动态sql查询的话查询量在10w时效率就很低,求大神知道如果通过存储过程进
行查询。一共三张表,需要实现多条件动态查询以及分页,下面是自己写的sql,求告知存储过程如何实现:所有的查询条件都封装在pojo---CollectDataQuery里面
select c.id cid,c.score,c.publishDate,c.author,c.title,c.content,c.source,c.url,c.source,c.click,c.zanTotal,
c.repeatTotal,c.forward,c.type,t.key_words,t.id tId
from t_collectdata c
left JOIN t_data_subject d on d.id=c.id
left JOIN t_task t on d.subjectId=t.id
order by ${publishDate} ${order}
limit #{pageNum},#{pageSize}
<sql id="whereSql">
<where>
<if test="null!=ids and ids.size>0">
AND d.subjectId IN
<foreach collection="ids" item="item" index="index" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<choose>
<when test="keyWords!=null and keyWords !=''">
and (c.title like concat('%',#{keyWords},'%')
or c.content like concat('%',#{keyWords},'%'))
</when>
<when test="title!=null and title!=''">
and c.title like concat('%',#{title},'%')
</when>
<when test="content!=null and content!=''">
and c.content like concat('%',#{content},'%')
</when>
</choose>
<if test="type!=null and type!=''">
AND c.type = #{type}
</if>
<if test="score!=null and score!=''">
<choose>
<when test="score==2">
AND c.score BETWEEN #{i} and #{j}
</when>
<when test="score==-1">
<![CDATA[ and (c.score<#{i})]]>
</when>
<when test="score==1">
<![CDATA[ and (c.score>#{j})]]>
</when>
</choose>
</if>
<if test="startTime!=null and score!=''">
AND c.publishDate BETWEEN #{startTime} and #{endTime}
</if>
<if test="taskId!=null and taskId!=''">
AND t.id = #{taskId}
</if>
</where>
</sql>
其中t_data_subject是t_collectdata和t_task的中jian表
下面时两张表的字段对应
<resultMap id="CollectDataMap" type="com.bicap.cloud.monitor.entity.CollectData">
<id column="cid" property="id"/>
<result column="score" property="score"/>
<result column="publishDate" property="publishDate"/>
<result column="author" property="author"/>
<result column="authorId" property="authorId"/>
<result column="content" property="content"/>
<result column="source" property="source"/>
<result column="url" property="url"/>
<result column="title" property="title"/>
<result column="source" property="source"/>
<result column="click" property="click"/>
<result column="zanTotal" property="zanTotal"/>
<result column="repeatTotal" property="repeatTotal"/>
<result column="forward" property="forward"/>
<result column="type" property="type"/>
<collection property="keyWords" resultMap="keywordsMap"/>
</resultMap>
<resultMap id="keywordsMap" type="com.bicap.cloud.monitor.entity.Task">
<id property="id" column="tId"/>
<result property="keyWords" column="key_words"/>
</resultMap>
急求大腿知道用存储过程如何实现