ここで私の答えを読むのに時間がかかります:(あなたと同様のボリュームがあります)
0.02 秒で 5 億行、1,500 万行の範囲スキャン。
MySQL と NoSQL: 適切なものを選択するのを手伝ってください
次に、次のようにテーブル エンジンを innodb に修正します。
create table tag_date_value
(
tag_id smallint unsigned not null, -- i prefer ints to chars
tag_date datetime not null, -- can we make this date vs datetime ?
value int unsigned not null default 0, -- or whatever datatype you require
primary key (tag_id, tag_date) -- clustered composite PK
)
engine=innodb;
代わりに、以下を主キーと見なすことができます。
primary key (tag_id, tag_date, value) -- added value save some I/O
ただし、値がLARGE varchar型ではない場合のみ!
以前のようにクエリ:
select
tag_date,
value
from
tag_date_value
where
tag_id = 1 and
tag_date between 'x' and 'y'
order by
tag_date;
お役に立てれば :)
編集
言い忘れていましたが、alter table を使用してエンジン タイプを mysiam から innodb に変更するのではなく、データを csv ファイルにダンプし、新しく作成された空の innodb テーブルに再インポートします。
エクスポート プロセス中にデータを注文していることに注意してください。クラスター化インデックスが重要です。
書き出す
select * into outfile 'tag_dat_value_001.dat'
fields terminated by '|' optionally enclosed by '"'
lines terminated by '\r\n'
from
tag_date_value
where
tag_id between 1 and 50
order by
tag_id, tag_date;
select * into outfile 'tag_dat_value_002.dat'
fields terminated by '|' optionally enclosed by '"'
lines terminated by '\r\n'
from
tag_date_value
where
tag_id between 51 and 100
order by
tag_id, tag_date;
-- etc...
輸入
正しい順序でテーブルにインポートし直してください!
start transaction;
load data infile 'tag_dat_value_001.dat'
into table tag_date_value
fields terminated by '|' optionally enclosed by '"'
lines terminated by '\r\n'
(
tag_id,
tag_date,
value
);
commit;
-- etc...