查询挂起"创建排序索引"

时间:2018-04-18 02:33:06

标签: mysql sql indexing query-performance

用于运行一分钟的查询,现在在更改为具有略微不同架构的新表后需要将近一个小时。

查询:

select 
    date(datetime_field)
    ,str_1
    ,str_2
    ,str_3
    ,str_4
    ,dayname(datetime_field)
    ,str_5
    ,date(convert_tz(datetime_field, 'Timezone', t.timezone))
    ,time(convert_tz(cpt_datetime, 'Timezone', t.timezone))
    ,sum_field_1
    ,sum_field_2 
from 
(select 
    concat_ws(' ', date_date, date_time) as datetime_field
    ,str_1
    ,str_2
    ,str_3
    ,str_4
    ,ceiling(sum(agg_field1)) as sum_field_1
    ,ceiling(sum(agg_field2)) as sum_field_2 
from raw_table f 
force index(raw_table_index) 
join lookup_table c on f.str_3 = c.str_3 and f.id_2 = c.id_2 
where str_3 = 'VALUE' 
and id_1 = 0 
and f.id_2 in ('val1','val2') 
and date_date >= '2018-04-12' 
group by concat_ws(' ', date_date, date_time)
,str_1
,str_2
,str_3
,str_4
,c.str_5) 
fcst left join timezones_table t on fcst.str_2 = t.str_2;

该表具有以下索引:

ALTER TABLE `raw_table` ADD INDEX raw_table_index (id_2, id_1, str_3, date_date);

说明显示它正在使用表中的索引:

*************************** 4. row ***************************
           id: 2
  select_type: DERIVED
        table: f
         type: ref
possible_keys: raw_table_index
          key: raw_table_index
      key_len: 171
          ref: const,const,func
         rows: 414
        Extra: Using index condition

           id: 1
  select_type: PRIMARY
        table: <derived2>
         type: ALL
possible_keys: NULL
          key: NULL
      key_len: NULL
          ref: NULL
         rows: 38088
        Extra: NULL

所以它在具有40M +

的桌子上过滤到38,088

查询在&#34;发送数据&#34;状态约128秒,然后在&#34;创建排序索引&#34;中花费接近2小时;州。我玩过不同的索引并没有看到任何改进。当前索引与旧表上的索引非常相似。我不确定自己是在做一些真正愚蠢的事情而只是缺少某些东西?有什么想法吗?

0 个答案:

没有答案
相关问题