From: teodor Date: Tue, 31 Oct 2006 15:02:12 +0000 (+0000) Subject: Small optimizing of query generation X-Git-Url: http://sigaev.ru/git/gitweb.cgi?a=commitdiff_plain;h=7449f76ea4361b57d6a875a566438fa37c330947;p=ftsbench.git Small optimizing of query generation --- diff --git a/ftsbench.h b/ftsbench.h index a05937d..128f00d 100644 --- a/ftsbench.h +++ b/ftsbench.h @@ -40,6 +40,15 @@ typedef struct { } StringBuf; void sb_add(StringBuf *b, char *s, int length); +#define sb_addchar(s, c) do { \ + if ( (s)->strlen < (s)->length ) \ + (s)->str[ (s)->strlen++ ] = (c); \ + else { \ + char __c = (c); \ + sb_add( (s), &__c, 1); \ + } \ +} while(0) + void printScheme(); /* rand.c */ diff --git a/mysqldriver.c b/mysqldriver.c index 2ad7cea..f815dd9 100644 --- a/mysqldriver.c +++ b/mysqldriver.c @@ -85,10 +85,9 @@ execQuery(ftsDB *adb, char **words, int flags) { db->b.strlen = 0; while( *words ) { - if ( db->flags & FLG_OR) - sb_add(&db->b, " ", 1); - else - sb_add(&db->b, " +", 2); + sb_addchar(&db->b, ' '); + if ( db->flags & FLG_AND) + sb_addchar(&db->b, '+'); sb_add(&db->b, *words, -1); words++; diff --git a/pgdriver.c b/pgdriver.c index 0c4c59d..0f01827 100644 --- a/pgdriver.c +++ b/pgdriver.c @@ -194,7 +194,6 @@ checkEmptyQuery(ftsPG *db, PGresult *res) { static void execQuery(ftsDB* adb, char ** words, int flags) { ftsPG *db = (ftsPG*)adb; - const char *paramValues[1]; int i = 0; PGresult *res; @@ -224,25 +223,25 @@ execQuery(ftsDB* adb, char ** words, int flags) { if ( i!= 0 ) sb_add(&db->b, (db->flags & FLG_OR) ? " | '" : " & '", 4); else - sb_add(&db->b, "'", 1); + sb_addchar(&db->b, '\''); while( *ptr ) { if (*ptr == '\'') - sb_add(&db->b, "'", 1); - sb_add(&db->b, ptr, 1); + sb_addchar(&db->b, '\''); + sb_addchar(&db->b, *ptr); ptr++; } - sb_add(&db->b, "'", 1); + sb_addchar(&db->b, '\''); i++; words++; } - paramValues[0] = db->b.str; + i = 1; res = PQexecPrepared( db->conn, "search_ftsbench", - 1, paramValues, - NULL, NULL, 0); + 1, (const char**)&(db->b.str), + &(db->b.strlen), &i, 0); if (PQresultStatus(res) != PGRES_TUPLES_OK) { /* skip error ' all words are a stop word' for GIN index -