database performance - How can I write to MYSQL DB as if i were writing to a regular file -
i want write mysql db table same speed if writing regular binary file ofstream example.
normally, writing 100m bytes file using ofstream takes less 1 second.
while in mysql, inserted these 100m bytes in more 9 seconds long time ( used myisam table , multiple-row insert statements).
in other words, want configure mysql such makes no (checks,parsing,....etc), writing table if binary file
so, there method achieve that?
edit 1:
here table want populate,
create table frames ( f1 varchar(8) not null , f2 varchar(6) not null , f3 varchar(6) not null , f4 varchar(2) not null , f5 varchar(4), f6 varchar(16000), f7 varchar(4) not null );
edit 2:
here snippet code used insertion max defined 10000
for (int c = 0; c < 100; ++c) { string query("insert frames (f1,f2,f3,f4,f5,f6,f7) values"); (int = 1; <= max; ++i) { query += "('aaaaaaaa','000001','000002','05','5005','000000000100000000010000000001000000000100','mkje')"; query += (i==max) ? ";" : "," ; } if (mysql_query(conn, query.c_str() )) { fprintf(stderr, "%s\n", mysql_error(conn)); return(1); } }
thanks
you can use various tricks improving speed of insert. link mysql manual, covers bunch of tips.
but you'll never close speed of writing directly file. mysql doing lot of work behind scenes, parse sql, enforce access privileges, enforce data constraints, , convert data compact representations of data types, , organize data file efficiently, , update indexes.
if use innodb (the default) storage engine, have @ least primary key index update. innodb stores table data clustered index.
the way can same speed if appending file using csv storage engine, , append directly file. is, don't use sql @ all, write data file. if file in right location , has right name, data mysql table.
Comments
Post a Comment