InnoDB
Tables
InnoDB
InnoDB
InnoDB
Monitor
InnoDB
must
flush the log to disk at each transaction commit, if that transaction
made modifications to the database. Since the rotation speed of a disk
is typically
at most 167 revolutions/second, that constrains the number of commits
to the same 167/second if the disk does not fool the operating system.
innodb_flush_log_at_trx_commit
to 0. InnoDB
tries to flush the log once per second anyway,
though the flush is not guaranteed.
InnoDB
has written the log files full, it has to write the modified contents
of the buffer pool to disk in a checkpoint. Small log files will cause many
unnecessary disk writes. The drawback in big log files is that recovery
time will be longer.
fdatasync
and other similar methods is surprisingly slow.
The default method InnoDB
uses is the fdatasync
function.
If you are not satisfied with the database write performance, you may
try setting innodb_flush_method
in `my.cnf'
to O_DSYNC
, though O_DSYNC
seems to be slower on most systems.
InnoDB
, make sure that MySQL does not have
autocommit=1
on. Then every insert requires a log flush to disk.
Put before your plain SQL import file line
SET AUTOCOMMIT=0;and after it
COMMIT;If you use the `mysqldump' option
--opt
, you will get dump
files which are fast to import also to an InnoDB
table, even without wrapping
them to the above SET AUTOCOMMIT=0; ... COMMIT;
wrappers.
InnoDB
uses the insert buffer
to save disk I/O in inserts, but in a corresponding rollback no such
mechanism is used. A disk-bound rollback can take 30 times the time
of the corresponding insert. Killing the database process will not
help because the rollback will start again at the database startup. The
only way to get rid of a runaway rollback is to increase the buffer pool
so that the rollback becomes CPU-bound and runs fast, or delete the whole
InnoDB
database.
DROP TABLE
or TRUNCATE
(from MySQL-4.0 up) to empty a
table, not DELETE FROM yourtable
.
INSERT
to reduce
communication overhead between the client and the server if you need
to insert many rows:
INSERT INTO yourtable VALUES (1, 2), (5, 5);This tip is of course valid for inserts into any table type, not just
InnoDB
.