大数据量(千万级)查询优化实践经验
首先,一个表数据超过8千万条,而且还在以每5分钟5000条记录(不一定就是5000)增加中。
其次,该表有个字段有记录了时间。
再次,该表拥有80几个字段。
需求是:80几个字段中,要求查出50个字段,而且要求分页显示。根据需求写出的sql(样品语句)如下:
select * from ((select t1.*, rownum t1rownum from (select ddatetime, obtid, prediction_time, make_time, forecaster, temperature, relative_humidity, wind_direction, wind_speed, pressure, precipitation, total_cloud_amount, low_cloud_amount, weather_type, visibility, min_temp_24, max_temp_24, min_hum_24, max_hum_24, precipitation_12, precipitation_24, total_cloud_12, low_cloud_12, weather_type_12, wind_direction_12, wind_speed_12 from T_SEVP_GIFT d where 1 = 1and to_char(d.ddatetime, 'yyyy-MM-dd hh24:mi') >= ? and to_char(d.ddatetime, 'yyyy-MM-dd hh24:mi') <= ?) t1 where rownum <= ?)) where t1rownum >= ?
select * from ((select t1.*, rownum t1rownum from (select ddatetime, obtid, wdidf, wd2df, wd2dd, wd10df, wd10dd, wd3smaxdf, wd3smaxdd, wd3smaxtime, wd10maxdf, wd10maxdd, wd10maxtime, wd3daymax, wf3daymax, wd3daymaxtime, wd10daymax, wf10daymax, wd10daymaxtime, t, maxt, maxttime, mint, minttime, daymaxt, daymaxttime, daymint, dayminttime, rh, maxrh, maxrhtime, minrh, minrhtime, dp, p, maxp, maxptime, minp, minptime, hourrf, dayrf, rfmark1, minrf, wpv, othfields, rddatetime, procsts from T_OBTMIND d where d.ddatetime >= to_date('2011-09-01 10:35', 'yyyy-MM-dd hh24:mi') and d.ddatetime <= to_date('2011-09-01 10:38', 'yyyy-MM-dd hh24:mi')) t1 where rownum <= 10)) where t1rownum >= 1--样品语句。