-2

can you explain to me, why MongoDB insert faster than MySQL insert? i use PHP 5.6 and MongoDB 3.2.12 and MySQL 5.6.25.

please give reference! book or journal

Community
  • 1
  • 1

1 Answers1

0

(I reopened because the "dup" MySQL vs MongoDB 1000 reads was about reads, not inserts.)

MySQL can be very slow or very fast on INSERTing. To be fair to MySQL, you should specify the specifics that lead to slow or fast.

  • MyISAM versus InnoDB -- MyISAM is dying, don't consider it in any comparison. https://www.percona.com/blog/2016/10/11/mysql-8-0-end-myisam/
  • Batch the rows being inserted. Inserting 100 rows in a single INSERT statement easily runs 10 times as fast as one row at a time.
  • LOAD DATA INFILE (from a .csv) is even faster. https://dev.mysql.com/doc/refman/5.6/en/load-data.html
  • Consider transactional flags in InnoDB to get some more speed.
  • Secondary indexes have some impact.
  • Inserting at the "end" of a table is faster than inserting at random locations -- think UUIDs or GUIDs. http://mysql.rjweb.org/doc.php/uuid
  • If the table is too big to be cached, UUID inserts eventually slow down to 1 row per IOP.
  • Keep in mind that the only reason for inserting a table is to later fetch it. So, the fetching patterns have some impact on the insertion optimizations.
  • Etc, etc.
Rick James
  • 135,179
  • 13
  • 127
  • 222