diff options
author | 2012-06-08 15:06:28 +0000 | |
---|---|---|
committer | 2012-06-08 15:06:28 +0000 | |
commit | 23b47a76c2d0b34fa0a6e8bdea1f0c5db87aac33 (patch) | |
tree | ca48bf7ba1b8a55db313063e5089d4297b961e46 | |
parent | 79a1f1f69a34b41fb34f94a2b9af98185d4ca2e2 (diff) | |
download | mandoc-23b47a76c2d0b34fa0a6e8bdea1f0c5db87aac33.tar.gz mandoc-23b47a76c2d0b34fa0a6e8bdea1f0c5db87aac33.tar.zst mandoc-23b47a76c2d0b34fa0a6e8bdea1f0c5db87aac33.zip |
Turn off sqlite3 synchronous mode when creating a new database.
This makes it run about 5x faster.
While here, wrap some sqlite3 statements in #defines to extract errors.
(Really, the warning/error/etc. macros should be functionified.)
-rw-r--r-- | mandocdb.c | 82 | ||||
-rw-r--r-- | mansearch.c | 14 |
2 files changed, 56 insertions, 40 deletions
@@ -1,4 +1,4 @@ -/* $Id: mandocdb.c,v 1.51 2012/06/08 12:05:27 kristaps Exp $ */ +/* $Id: mandocdb.c,v 1.52 2012/06/08 15:06:28 kristaps Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011, 2012 Ingo Schwarze <schwarze@openbsd.org> @@ -60,6 +60,25 @@ fprintf(stderr, ": %s\n", (_f)); \ } while (/* CONSTCOND */ 0) +#define SQL_EXEC(_v) \ + if (SQLITE_OK != sqlite3_exec(db, (_v), NULL, NULL, NULL)) \ + fprintf(stderr, "%s\n", sqlite3_errmsg(db)) +#define SQL_BIND_TEXT(_s, _i, _v) \ + if (SQLITE_OK != sqlite3_bind_text \ + ((_s), (_i)++, (_v), -1, SQLITE_STATIC)) \ + fprintf(stderr, "%s\n", sqlite3_errmsg(db)) +#define SQL_BIND_INT(_s, _i, _v) \ + if (SQLITE_OK != sqlite3_bind_int \ + ((_s), (_i)++, (_v))) \ + fprintf(stderr, "%s\n", sqlite3_errmsg(db)) +#define SQL_BIND_INT64(_s, _i, _v) \ + if (SQLITE_OK != sqlite3_bind_int64 \ + ((_s), (_i)++, (_v))) \ + fprintf(stderr, "%s\n", sqlite3_errmsg(db)) +#define SQL_STEP(_s) \ + if (SQLITE_DONE != sqlite3_step((_s))) \ + fprintf(stderr, "%s\n", sqlite3_errmsg(db)) + enum op { OP_DEFAULT = 0, /* new dbs from dir list or default config */ OP_CONFFILE, /* new databases from custom config file */ @@ -479,6 +498,14 @@ main(int argc, char *argv[]) goto out; if (0 == dbopen(dirs.paths[j], 0)) goto out; + + /* + * Since we're opening up a new database, we can + * turn off synchronous mode for much better + * performance. + */ + SQL_EXEC("PRAGMA synchronous = OFF"); + if (0 == ofmerge(mc, mp, dirs.paths[j])) goto out; dbclose(dirs.paths[j], 0); @@ -1768,6 +1795,7 @@ dbindex(struct mchars *mc, int form, struct str *key; const char *desc; int64_t recno; + size_t i; DEBUG(of->file, base, "Adding to index"); @@ -1783,23 +1811,15 @@ dbindex(struct mchars *mc, int form, desc = key->utf8; } - sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL, NULL); - - sqlite3_bind_text - (stmts[STMT_INSERT_DOC], 1, - of->file, -1, SQLITE_STATIC); - sqlite3_bind_text - (stmts[STMT_INSERT_DOC], 2, - of->sec, -1, SQLITE_STATIC); - sqlite3_bind_text - (stmts[STMT_INSERT_DOC], 3, - of->arch, -1, SQLITE_STATIC); - sqlite3_bind_text - (stmts[STMT_INSERT_DOC], 4, - desc, -1, SQLITE_STATIC); - sqlite3_bind_int - (stmts[STMT_INSERT_DOC], 5, form); - sqlite3_step(stmts[STMT_INSERT_DOC]); + SQL_EXEC("BEGIN TRANSACTION"); + + i = 1; + SQL_BIND_TEXT(stmts[STMT_INSERT_DOC], i, of->file); + SQL_BIND_TEXT(stmts[STMT_INSERT_DOC], i, of->sec); + SQL_BIND_TEXT(stmts[STMT_INSERT_DOC], i, of->arch); + SQL_BIND_TEXT(stmts[STMT_INSERT_DOC], i, desc); + SQL_BIND_INT(stmts[STMT_INSERT_DOC], i, form); + SQL_STEP(stmts[STMT_INSERT_DOC]); recno = sqlite3_last_insert_rowid(db); sqlite3_reset(stmts[STMT_INSERT_DOC]); @@ -1807,34 +1827,30 @@ dbindex(struct mchars *mc, int form, assert(key->of == of); if (NULL == key->utf8) utf8key(mc, key); - sqlite3_bind_int64 - (stmts[STMT_INSERT_KEY], 1, key->mask); - sqlite3_bind_text - (stmts[STMT_INSERT_KEY], 2, - key->utf8, -1, SQLITE_STATIC); - sqlite3_bind_int64 - (stmts[STMT_INSERT_KEY], 3, recno); - sqlite3_step(stmts[STMT_INSERT_KEY]); + i = 1; + SQL_BIND_INT64(stmts[STMT_INSERT_KEY], i, key->mask); + SQL_BIND_TEXT(stmts[STMT_INSERT_KEY], i, key->utf8); + SQL_BIND_INT64(stmts[STMT_INSERT_KEY], i, recno); + SQL_STEP(stmts[STMT_INSERT_KEY]); sqlite3_reset(stmts[STMT_INSERT_KEY]); } - sqlite3_exec(db, "COMMIT TRANSACTION", NULL, NULL, NULL); - + SQL_EXEC("END TRANSACTION"); } static void dbprune(const char *base) { struct of *of; + size_t i; if (nodb) return; for (of = ofs; NULL != of; of = of->next) { - sqlite3_bind_text - (stmts[STMT_DELETE], 1, - of->file, -1, SQLITE_STATIC); - sqlite3_step(stmts[STMT_DELETE]); + i = 1; + SQL_BIND_TEXT(stmts[STMT_DELETE], i, of->file); + SQL_STEP(stmts[STMT_DELETE]); sqlite3_reset(stmts[STMT_DELETE]); DEBUG(of->file, base, "Deleted from index"); } @@ -1901,7 +1917,7 @@ dbopen(const char *base, int real) if ( ! real) remove(file); - ofl = SQLITE_OPEN_PRIVATECACHE | SQLITE_OPEN_READWRITE | + ofl = SQLITE_OPEN_READWRITE | (0 == real ? SQLITE_OPEN_EXCLUSIVE : 0); rc = sqlite3_open_v2(file, &db, ofl, NULL); diff --git a/mansearch.c b/mansearch.c index ad18f942..e3502b99 100644 --- a/mansearch.c +++ b/mansearch.c @@ -1,4 +1,4 @@ -/* $Id: mansearch.c,v 1.2 2012/06/08 14:14:30 kristaps Exp $ */ +/* $Id: mansearch.c,v 1.3 2012/06/08 15:06:28 kristaps Exp $ */ /* * Copyright (c) 2012 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -38,11 +38,11 @@ #include "mandocdb.h" #include "mansearch.h" -#define BIND_TEXT(_db, _s, _i, _v) \ +#define SQL_BIND_TEXT(_db, _s, _i, _v) \ if (SQLITE_OK != sqlite3_bind_text \ ((_s), (_i)++, (_v), -1, SQLITE_STATIC)) \ fprintf(stderr, "%s\n", sqlite3_errmsg((_db))) -#define BIND_INT64(_db, _s, _i, _v) \ +#define SQL_BIND_INT64(_db, _s, _i, _v) \ if (SQLITE_OK != sqlite3_bind_int64 \ ((_s), (_i)++, (_v))) \ fprintf(stderr, "%s\n", sqlite3_errmsg((_db))) @@ -208,13 +208,13 @@ mansearch(const struct manpaths *paths, fprintf(stderr, "%s\n", sqlite3_errmsg(db)); if (NULL != arch) - BIND_TEXT(db, s, j, arch); + SQL_BIND_TEXT(db, s, j, arch); if (NULL != sec) - BIND_TEXT(db, s, j, arch); + SQL_BIND_TEXT(db, s, j, arch); for (ep = e; NULL != ep; ep = ep->next) { - BIND_TEXT(db, s, j, ep->v); - BIND_INT64(db, s, j, ep->bits); + SQL_BIND_TEXT(db, s, j, ep->v); + SQL_BIND_INT64(db, s, j, ep->bits); } memset(&htab, 0, sizeof(struct ohash)); |