Insertions are usually performed in large batches because indexes are updated after each insertion. Batching allows you to insert many records and then update indexes only once at the end, and not after each row.
However, in the case of an index with an automatic incremental primary key, the index must be expanded to even add a new row, so you do not save anything since you have no other indexes.
Batching also saves some overhead when parsing requests and blocking. However, you might also consider using parameterized queries (PDOs).
Inserting one record at a time using a PDO-parameterized query will also be very fast, since MySQL only has to parse the query once, and from then on it uses a small binary binary data string transfer.
You can lock the table before entering with LOCK TABLES
. This will save a little overhead on the table.
Also, since SHA1 will always be ASCII with six-character hexadecimal encoding, you should use CHAR(40)
instead of VARCHAR()
. This will speed up the process. Also, if the SHA1 index is indexed, use a single-byte character set instead of UTF8 to reduce the size of the index and speed it up.
source share