c - Table name length in sqlite affects performance. Why? -
i'm noticing length of table names affects performance during creation of tables. here code example reproduces problem:
#include <stdio.h> #include <assert.h> #include "sqlite3.h" int main() { int i, sr; char table_query[1000]; sqlite3* db; sr = sqlite3_open("test.db", &db); assert(sr == sqlite_ok); sr = sqlite3_exec(db, "pragma synchronous=off", null, null, null); assert(sr == sqlite_ok); sr = sqlite3_exec(db, "pragma journal_mode=off", null, null, null); assert(sr == sqlite_ok); sr = sqlite3_exec(db, "pragma temp_store=memory", null, null, null); assert(sr == sqlite_ok); sr = sqlite3_exec(db, "begin exclusive transaction;", null, null, null); assert(sr == sqlite_ok); (i = 0; < 10000; ++i) { #ifdef long_names sprintf(table_query, "create table `table_%d_aklkekabcdefghijk4c6f766520416c6c20546865205061696e204177617920496e636c204b796175202620416c626572742052656d69782020434452` (content);", i); #else sprintf(table_query, "create table `table_%d` (content);", i); #endif sr = sqlite3_exec(db, table_query, null, null, null); assert(sr == sqlite_ok); } sr = sqlite3_exec(db, "end transaction;", null, null, null); assert(sr == sqlite_ok); sr = sqlite3_close(db); assert(sr == sqlite_ok); return 0; }
to compile:
gcc main.c sqlite3.c -o3 -dlong_names -dndebug
gcc main.c sqlite3.c -o3 -dndebug
on machine, when using relatively short table names table_{table #}
, creation of database 10,000 tables takes approximately 14 seconds. these table names vary 7 max of 11 characters.
when using relatively long table names table_{table #}_{some unique identifying name adds 120 or characters}
, creation of database 10,000 tables takes approximately 60 seconds.
creating database long table names took on 4 times longer!
why case? expected behavior or bug?
and since creating tables long names negatively affects performance, leads me wonder if query performance on such database negatively affected. so answer seems believe answer "no" respect mysql, no references given.
thoughts?
p.s.: i'm using latest amalgamated version of sqlite (3.8)
with longer table names, resulting empty database file 4x larger, since longer table names take more space in schema. should come no surprise sqlite takes 4x longer write 4x content.
note table names stored once. once start adding content database, relative size difference between 2 decrease, asymptotically approaching 1.0. absolute difference in size between 2 databases should remain constant.
Comments
Post a Comment