Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to speed up insert performance in CockroachDB

Tags:

cockroachdb

Is there a way to optimize the insertion of a lot of data into an empty CockroachDB table?

like image 843
Alex Robinson Avatar asked Apr 11 '17 19:04

Alex Robinson


People also ask

How can I improve my insert query performance?

To optimize insert speed, combine many small operations into a single large operation. Ideally, you make a single connection, send the data for many new rows at once, and delay all index updates and consistency checking until the very end.

Is CockroachDB fast?

CockroachDB can process 1.68M tpmC with 140,000 warehouses, resulting in an efficiency score of 95%.

Which is faster update or insert?

In SQL, i think inserting would be faster for the simple reason that while inserting you don't have to look up for anything, however for updating , first of all you would have to find the tuple of the data and then perform the update operation. Hence insert is better than update.


1 Answers

To optimize inserting data into CockroachDB tables, there are a few pieces of guidance:

  • Create the table without any secondary indexes, insert your data, and then add any secondary indexes you want.
  • Insert 500 rows per INSERT statement. That number might vary a bit depending on the size of your rows, but is a good guideline to optimize the speed at which you can write data.
  • Use the IMPORT statement to bulk import CSV files into a single table. This is the fastest way to get data into CockroachDB.

If you're moving from PostgreSQL to CockroachDB, you can also use pg_dump to create a COPY statement, which CockroachDB is optimized to ingest. It's a slightly more involved process, but you can find the details about how to do it in CockroachDB's import documentation.

like image 73
Alex Robinson Avatar answered Sep 19 '22 17:09

Alex Robinson