3 ms·
Could you share some source code around your implementation? Selecting from a non-existing table should be a very quick operation. I suspect you might be doing
by bob1029 4y ago
Could you share some source code around your implementation? Selecting from a non-existing table should be a very quick operation. I suspect you might be doing something like creating a new connection per command if you are seeing this behavior.
- johnboiles 4y agoThere aren't connections in SQLite like there are for network-connected DBs (eg MySQL). My simple code is like this: sqlite3_initialize(); sqlite3 *db; sqlite3_open("/data/sqlite.db", &db); char *err = 0; sqlite3_exec(&db, "DROP TABLE table_name;", NULL, NULL, & err); // This takes ~5ms even when table_name does not exist
- brandmeyer 4y ago> There aren't connections in SQLite like there are for network-connected DBs (eg MySQL) The handle named `db` in your example is as expensive to create as a connection in the relative sense and should be optimized the same way in your application. It may be less expensive than a network database connection, but its still very expensive relative to any subsequent queries. The database file is opened, its first page is read, its schema is parsed from text (!), some memory is pre-allocated and so on every time you make that call. The sqlite3_exec call invokes the parser and query optimizer every time it is called. A better benchmark would be to compile a valid statement (sqlite3_prepare). The unit under test should just be sqlite_bind() for relevant parameters followed by sqlite_step(), and maybe (but not necessarily) sqlite_reset().