提高选择速度 - mysql - 非常大的表

时间:2014-02-12 01:35:08

标签: mysql query-performance large-data-volumes

一般来说MySQL和SQL的新手 - 所以请温柔: - )

我有一个行数非常多的表。该表是:

create table iostat (
pkey     int not null auto_increment,
serverid int not null,
datestr  char(15) default 'NULL',
esttime  int not null default 0,

rs       float not null default 0.0,
ws       float not null default 0.0,
krs      float not null default 0.0,
kws      float not null default 0.0,
wait     float not null default 0.0,
actv     float not null default 0.0,
wsvct    float not null default 0.0,
asvct    float not null default 0.0,
pctw     int not null default 0,
pctb     int not null default 0,
device   varchar(50),
avgread  float not null default 0.0,
avgwrit  float not null default 0.0,

primary key (pkey),

index i_serverid (serverid),
index i_esttime (esttime),
index i_datestr (datestr),
index i_rs (rs),
index i_ws (ws),
index i_krs (krs),
index i_kws (kws),
index i_wait (wait),
index i_actv (actv),
index i_wsvct (wsvct),
index i_asvct (asvct),
index i_pctb (pctb),
index i_device (device),
index i_servdate (serverid, datestr),
index i_servest (serverid, esttime)

)
engine = MyISAM
data directory = '${IOSTATdatadir}'
index directory = '${IOSTATindexdir}'
;

现在该表有834,317,203行。

是的 - 我需要所有数据。数据的最高级别组织是收集日期(datestr)。它是一个CHAR而不是一个日期来保存我用于各种加载,提取和分析脚本的特定日期格式。

每天增加约16,000,000行。

我想加快的其中一项操作是(限制通常为50,但范围从10到250):

create table TMP_TopLUNsKRead
  select
    krs, device, datestr, esttime
  from
    iostat
  where
    ${WHERECLAUSE}
  order by
    krs desc limit ${Limit};

WHERECLAUSE是:

serverid = 29 and esttime between X and Y and device like '%t%'

其中X和Y是时间戳,跨越4分钟到24小时。

我不想更改数据库引擎。这让我可以将数据和索引放在不同的驱动器上,从而获得了显着的整体性能。它总共有16亿行,这需要花费大量的时间来重新加载。

2 个答案:

答案 0 :(得分:3)

device like '%t%'

这是杀手。前导%表示它是对整列的搜索,或索引是否为索引,而不是索引查找。看看你是否可以不使用前导%

答案 1 :(得分:0)

如果不知道${WHERECLAUSE}中的内容,就无法帮助您。你是对的,这是一张很大的桌子。

但这是一个可能有所帮助的观察结果:一个覆盖索引的化合物

(krs, device, datestr, esttime) 

可能会加快数据子集的排序和提取。

相关问题