我不熟悉MySQL。在大型數據集上使用JOIN運行SQL查詢
我試着去運行一個內部聯接查詢,80000數據庫之間(這是表格B)對一個40GB的數據與約6億的記錄刷新記錄(這是表A)
是Mysql的適合跑步這排序查詢? 我應該預計它會花費多少時間?
這是我ied下面的代碼。但是,由於我的dbs連接在60000秒失敗,所以失敗了。
set net_read_timeout = 36000;
INSERT
INTO C
SELECT A.id, A.link_id, link_ref, network,
date_1, time_per,
veh_cls, data_source, N, av_jt
from A
inner join B
on A.link_id = B.link_id;
我開始研究如何將40GB表大小縮減爲臨時表,嘗試使查詢更易於管理。不過,我不斷收到
錯誤代碼:1206鎖的總數超過了鎖表的大小646.953秒
我在正確的軌道上? 歡呼!
我分裂數據庫的代碼是:
LOCK TABLES TFM_830_car WRITE, tfm READ;
INSERT
INTO D
SELECT A.id, A.link_id, A.time_per, A.av_jt
from A
where A.time_per = 34 and A.veh_cls = 1;
UNLOCK TABLES;
也許我的表索引是正確的我只有一個簡單的主鍵
CREATE Table A
(
id int unsigned Not Null auto_increment,
link_id varchar(255) not Null,
link_ref int not Null,
network int not Null,
date_1 varchar(255) not Null,
#date_2 time default Null,
time_per int not null,
veh_cls int not null,
data_source int not null,
N int not null,
av_jt int not null,
sum_squ_jt int not null,
Primary Key (id)
);
Drop table if exists B;
CREATE Table B
(
id int unsigned Not Null auto_increment,
TOID varchar(255) not Null,
link_id varchar(255) not Null,
ABnode varchar(255) not Null,
#date_2 time not Null,
Primary Key (id)
);
在架構方面,它僅僅是這兩個表(A和B)加載在數據庫下面
「對一個40GB的數據集」。有多少條記錄?你的表格是否正確編制索引? – 2014-11-24 19:35:37
80k記錄對於這樣的數據量似乎相當低,你在那裏存儲什麼,XML轉儲,圖像二進制文件? – 2014-11-24 19:38:38
您可以通過從子查詢(派生表)中選擇來解決錯誤,但它不會解決性能問題。發佈您的架構和一些示例數據以獲得進一步幫助。 – 2014-11-24 19:59:23