I have a large table (500M rows with ibd size of 1.5TB)
CREATE TABLE t1
(
ID int(11) unsigned NOT NULL AUTO_INCREMENT,
ChildID int(11) unsigned NOT NULL,
Number smallint(5) unsigned,
Title varchar(255) COMPRESSED,
Text mediumtext COMPRESSED,
UNIQUE INDEX(ChildID,Number),
PRIMARY KEY(ID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_general_ci
and I need to JOIN
it with other tables. After long experimentations, I found reading from this table is slow. Then, I simply focused on simple SELECT
.
SELECT * INTO OUTFILE '/tmp/test1.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n'
FROM t1 LIMIT 1000000
it takes over 700s with an output of 2.9GB file (a read speed of ~4MB/s, which is close to what was reported by iostat
). I moved the database to another HDD, but the same results.
I want to use other engines like Aria or partitioning, but each INSERT INTO SELECT
takes over 5 days.
- Is there any trick or tips for improving the
SELECT
performance from a large table? - How can we find the IO bottleneck? I believe my HDD has a higher I/O capability.
SELECT *
)? If you don't needText
, don't include it in the Join or the Outfile; it will run a lot faster.SELECT
is slow, it is meaningless to optimize theJOIN
query. What I found so far is that the uncompression process is the bottleneck as cannot keep up with theI/O
. Apparently, page compression is slow in writing and column compression in reading.