Skip to content

Commit

Permalink
SQLite doesn't use the FTS index for equal ops, so force it to do a FTS
Browse files Browse the repository at this point in the history
search first. Drops run time by a factor of 6 for "whatis man".
Found by Abhinav Upadhyay.

From Joerg. (Diff imported from NetBSD CVS repo)
  • Loading branch information
abhinav-upadhyay committed Dec 23, 2012
1 parent 57ca0e7 commit 9f32431
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions whatis.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $NetBSD: whatis.c,v 1.2 2012/02/07 19:17:16 joerg Exp $ */
/* $NetBSD: whatis.c,v 1.3 2012/02/20 18:27:30 joerg Exp $ */
/*-
* Copyright (c) 2012 Joerg Sonnenberger <[email protected]>
* All rights reserved.
Expand Down Expand Up @@ -29,7 +29,7 @@
*/

#include <sys/cdefs.h>
__RCSID("$NetBSD: whatis.c,v 1.2 2012/02/07 19:17:16 joerg Exp $");
__RCSID("$NetBSD: whatis.c,v 1.3 2012/02/20 18:27:30 joerg Exp $");

#include <err.h>
#include <stdio.h>
Expand All @@ -49,7 +49,7 @@ static int
whatis(sqlite3 *db, const char *cmd)
{
static const char sqlstr[] = "SELECT name, section, name_desc"
" FROM mandb WHERE name=?"
" FROM mandb WHERE name MATCH ? AND name=?"
" ORDER BY section, name";
sqlite3_stmt *stmt = NULL;
int retval;
Expand All @@ -58,6 +58,8 @@ whatis(sqlite3 *db, const char *cmd)
errx(EXIT_FAILURE, "Unable to query database");
if (sqlite3_bind_text(stmt, 1, cmd, -1, NULL) != SQLITE_OK)
errx(EXIT_FAILURE, "Unable to query database");
if (sqlite3_bind_text(stmt, 2, cmd, -1, NULL) != SQLITE_OK)
errx(EXIT_FAILURE, "Unable to query database");
retval = 1;
while (sqlite3_step(stmt) == SQLITE_ROW) {
printf("%s(%s) - %s\n", sqlite3_column_text(stmt, 0),
Expand Down

0 comments on commit 9f32431

Please sign in to comment.