现在我遇到一个mysql数据查询时间太慢问题 数据结构为一对多 数据查询出来全部返回不需要使用分页
描述如下:
前端要求通过时间区间查询一个月甚至几个月的分钟级数据(分钟数据:一分钟一条),并在折线图展示,但是我后台sql查询很慢(使用的嵌套子查询,字段已建立索引,并强制走了索引)
<!--分钟数据主表-->
<resultMap type="com.arid.dataDisplay.domain.MinuteDataRecord" id="MinuteDataRecordResult">
<result property="id" column="id"/>
<result property="stationCode" column="station_code"/>
<result property="aqi" column="aqi"/>
<result property="primaryPollutant" column="primary_pollutant"/>
<result property="exceedPollutant" column="exceed_pollutant"/>
<result property="sampleTime" column="sample_time"/>
<result property="createTime" column="create_time"/>
<collection property="mpList" ofType="com.arid.dataDisplay.domain.MinutePollutantDataVO"
javaType="java.util.List" select="selectPollutantData"
column="id" />
</resultMap>
<!--分钟数据副表-->
<resultMap type="com.arid.dataDisplay.domain.MinutePollutantDataVO" id="MinutePollutantDataResult">
<result property="spdc_id" column="id"/>
<result property="recordId" column="record_id"/>
<result property="pollutantCode" column="pollutant_code"/>
<result property="pollutantName" column="pollutant_name"/>
<result property="dataValue" column="data_value"/>
<result property="flag" column="flag"/>
<result property="iAqi" column="i_aqi"/>
<result property="pollutionLevel" column="pollution_level"/>
<result property="spdc_sample_time" column="sample_time"/>
</resultMap>
<select id="selectMinuteDataRecordByCodeAndTime" parameterType="String" resultMap="MinuteDataRecordResult" fetchSize="10000">
select
sdrc.id,
sdrc.exceed_pollutant,
sdrc.primary_pollutant,
sdrc.sample_time,
st.station_name,
st.latitude,
st.longitude
from minute_data_record sdrc
FORCE INDEX(`id`)
left join station AS st
on st.station_code = sdrc.station_code
<where>
<if test="code!=null and code!=''">
AND sdrc.station_code = #{code}
</if>
<if test="startTime!=null and startTime!=''">
AND
<![CDATA[
sdrc.sample_time >= #{startTime,jdbcType=TIMESTAMP}
]]>
</if>
<if test="endTime!=null and endTime!=''">
AND
<![CDATA[
sdrc.sample_time <= #{endTime,jdbcType=TIMESTAMP}
]]>
</if>
</where>
</select>
<select id="selectPollutantData" parameterType="map" resultMap="MinutePollutantDataResult">
SELECT
spdc.id AS spdc_id,
spdc.record_id,
spdc.pollutant_code,
spdc.pollutant_name,
spdc.data_value,
spdc.sample_time,
spdc.i_aqi
FROM
minute_pollutant_data spdc
FORCE INDEX(`record_id`)
where spdc.record_id=#{id}
</select>
怎么优化