mysql - Many very similar updates to an SQL table - optimization? -



mysql - Many very similar updates to an SQL table - optimization? -

i have c function follows, takes connection elsewhere, , performs (potentially large) number of (very similar) insertions particular table. code includes glib.h, my_global.h, assert.h , mysql.h (but isn't relevant here). code below:

char* make_table_cmd = "create or replace table graph (id int not null auto_increment primary key, weight int not null);"; char* add_row_cmd = "insert graph (weight) values (0);"; gboolean graph_make (mysql* conn_ptr, guint64 size) { assert(conn_ptr); if (!mysql_query(conn_ptr, make_table_cmd)) { gboolean loop_successful = true; (guint64 = 0; < size; i++) { if (mysql_query(conn_ptr, add_row_cmd)) { loop_successful = false; break; } } homecoming loop_successful; } else { homecoming false; } }

when tried remotely big plenty values warrant using database table (10,000 rows), took end of forever. based on profiling, function bottleneck, , i'm guessing add_row_cmds problem. there way can optimize this, given inherent similarity of rows?

disclaimer: i'm finish sql noob.

you can grab block of records insert in 1 pass so:

insert graph (weight) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);

depending on how many records have insert can process 1000 (for example) records each query instead of build query -> insert -> acknowledge -> repeat;

mysql c

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -