Small optimizing of query generation
authorteodor <teodor>
Tue, 31 Oct 2006 15:02:12 +0000 (15:02 +0000)
committerteodor <teodor>
Tue, 31 Oct 2006 15:02:12 +0000 (15:02 +0000)
ftsbench.h
mysqldriver.c
pgdriver.c

index a05937d..128f00d 100644 (file)
@@ -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 */
index 2ad7cea..f815dd9 100644 (file)
@@ -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++;
index 0c4c59d..0f01827 100644 (file)
@@ -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 -