[tracker/sparql-refactor: 1/16] libtracker-fts: Backport changes from FTS3 upstream in BestIndex



commit 56b70634707e15c5aac6ecf5aea8101c2700f74c
Author: Jürg Billeter <j bitron ch>
Date:   Fri Mar 26 14:08:53 2010 +0100

    libtracker-fts: Backport changes from FTS3 upstream in BestIndex
    
    This fixes filtering with both, ID and MATCH constraints, which can
    happen when joining with unions.

 src/libtracker-fts/tracker-fts.c |   26 ++++++++++++++------------
 1 files changed, 14 insertions(+), 12 deletions(-)
---
diff --git a/src/libtracker-fts/tracker-fts.c b/src/libtracker-fts/tracker-fts.c
index 7100a3f..1b18aa4 100644
--- a/src/libtracker-fts/tracker-fts.c
+++ b/src/libtracker-fts/tracker-fts.c
@@ -3488,8 +3488,11 @@ static int fulltextCreate(sqlite3 *db, void *pAux,
 static int fulltextBestIndex(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
   fulltext_vtab *v = tracker_fts_vtab;
   int i;
+  int iCons = -1;                 /* Index of constraint to use */
   FTSTRACE(("FTS3 BestIndex\n"));
 
+  pInfo->idxNum = QUERY_GENERIC;
+  pInfo->estimatedCost = 500000;
   for(i=0; i<pInfo->nConstraint; ++i){
     const struct sqlite3_index_constraint *pConstraint;
     pConstraint = &pInfo->aConstraint[i];
@@ -3497,26 +3500,25 @@ static int fulltextBestIndex(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
       if( (pConstraint->iColumn==-1 || pConstraint->iColumn==v->nColumn+1) &&
           pConstraint->op==SQLITE_INDEX_CONSTRAINT_EQ ){
         pInfo->idxNum = QUERY_DOCID;      /* lookup by docid */
+        pInfo->estimatedCost = 1.0;
+        iCons = i;
         FTSTRACE(("FTS3 QUERY_DOCID\n"));
       } else if( pConstraint->iColumn>=0 && pConstraint->iColumn<=v->nColumn &&
                  pConstraint->op==SQLITE_INDEX_CONSTRAINT_MATCH ){
         /* full-text search */
         pInfo->idxNum = QUERY_FULLTEXT + pConstraint->iColumn;
+        pInfo->estimatedCost = 2.0;
+        iCons = i;
         FTSTRACE(("FTS3 QUERY_FULLTEXT %d\n", pConstraint->iColumn));
-      } else continue;
-
-      pInfo->aConstraintUsage[i].argvIndex = 1;
-      pInfo->aConstraintUsage[i].omit = 1;
-
-      /* An arbitrary value for now.
-       * TODO: Perhaps docid matches should be considered cheaper than
-       * full-text searches. */
-      pInfo->estimatedCost = 1.0;
-
-      return SQLITE_OK;
+        break;
+      }
     }
   }
-  pInfo->idxNum = QUERY_GENERIC;
+
+  if( iCons>=0 ){
+    pInfo->aConstraintUsage[iCons].argvIndex = 1;
+    pInfo->aConstraintUsage[iCons].omit = 1;
+  }
   return SQLITE_OK;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]