/ Check-in [650e1a79]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Remove some unreachable code.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fts3-prefix-search
Files: files | file ages | folders
SHA1: 650e1a79eda5a2134a1fbd305ab1f205a57c0892
User & Date: dan 2011-06-04 20:13:24
Context
2011-06-06
06:55
Clean up the code for processing FTS4 options a bit. check-in: 0425138a user: dan tags: fts3-prefix-search
2011-06-04
20:13
Remove some unreachable code. check-in: 650e1a79 user: dan tags: fts3-prefix-search
20:04
Allow the "order=DESC" and "order=ASC" parameters in FTS4 "CREATE VIRTUAL TABLE" statements. Tables created with "order=DESC" store all doclists in descending order, which allows optimizations normally applied to "ORDER BY docid ASC" queries to be used with "ORDER BY docid DESC" queries instead. check-in: f6a0193f user: dan tags: fts3-prefix-search
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts3/fts3.c.

   443    443     p++;
   444    444     *pp = p;
   445    445   
   446    446     sqlite3Fts3GetVarint(p, &iVal);
   447    447     *pVal = iVal;
   448    448   }
   449    449   
   450         -/*
   451         -** As long as *pp has not reached its end (pEnd), then do the same
   452         -** as fts3GetDeltaVarint(): read a single varint and add it to *pVal.
   453         -** But if we have reached the end of the varint, just set *pp=0 and
   454         -** leave *pVal unchanged.
   455         -*/
   456         -static void fts3GetDeltaVarint2(char **pp, char *pEnd, sqlite3_int64 *pVal){
   457         -  if( *pp>=pEnd ){
   458         -    *pp = 0;
   459         -  }else{
   460         -    fts3GetDeltaVarint(pp, pVal);
   461         -  }
   462         -}
   463         -
   464    450   /*
   465    451   ** The xDisconnect() virtual table method.
   466    452   */
   467    453   static int fts3DisconnectMethod(sqlite3_vtab *pVtab){
   468    454     Fts3Table *p = (Fts3Table *)pVtab;
   469    455     int i;
   470    456   
................................................................................
  1908   1894         res = 0;
  1909   1895       }
  1910   1896   
  1911   1897       return res;
  1912   1898     }
  1913   1899   }
  1914   1900   
  1915         -/*
  1916         -** Values that may be used as the first parameter to fts3DoclistMerge().
  1917         -*/
  1918         -#define MERGE_NOT        2        /* D + D -> D */
  1919         -#define MERGE_AND        3        /* D + D -> D */
  1920         -#define MERGE_OR         4        /* D + D -> D */
  1921         -#define MERGE_PHRASE     6        /* P + P -> D */
  1922         -#define MERGE_NEAR       8        /* P + P -> D */
  1923         -
  1924         -#define MERGE_POS_OR     5        /* P + P -> P */
  1925         -#define MERGE_POS_PHRASE 7        /* P + P -> P */
  1926         -#define MERGE_POS_NEAR   9        /* P + P -> P */
  1927         -
  1928         -/*
  1929         -** Merge the two doclists passed in buffer a1 (size n1 bytes) and a2
  1930         -** (size n2 bytes). The output is written to pre-allocated buffer aBuffer,
  1931         -** which is guaranteed to be large enough to hold the results. The number
  1932         -** of bytes written to aBuffer is stored in *pnBuffer before returning.
  1933         -**
  1934         -** If successful, SQLITE_OK is returned. Otherwise, if a malloc error
  1935         -** occurs while allocating a temporary buffer as part of the merge operation,
  1936         -** SQLITE_NOMEM is returned.
  1937         -*/
  1938         -static int fts3DoclistMerge(
  1939         -  int mergetype,                  /* One of the MERGE_XXX constants */
  1940         -  int nParam1,                    /* Used by MERGE_NEAR and MERGE_POS_NEAR */
  1941         -  int nParam2,                    /* Used by MERGE_NEAR and MERGE_POS_NEAR */
  1942         -  char *aBuffer,                  /* Pre-allocated output buffer */
  1943         -  int *pnBuffer,                  /* OUT: Bytes written to aBuffer */
  1944         -  char *a1,                       /* Buffer containing first doclist */
  1945         -  int n1,                         /* Size of buffer a1 */
  1946         -  char *a2,                       /* Buffer containing second doclist */
  1947         -  int n2,                         /* Size of buffer a2 */
  1948         -  int *pnDoc                      /* OUT: Number of docids in output */
  1949         -){
  1950         -  sqlite3_int64 i1 = 0;
  1951         -  sqlite3_int64 i2 = 0;
  1952         -  sqlite3_int64 iPrev = 0;
  1953         -
  1954         -  char *p = aBuffer;
  1955         -  char *p1 = a1;
  1956         -  char *p2 = a2;
  1957         -  char *pEnd1 = &a1[n1];
  1958         -  char *pEnd2 = &a2[n2];
  1959         -  int nDoc = 0;
  1960         -
  1961         -  assert( mergetype==MERGE_OR     || mergetype==MERGE_POS_OR 
  1962         -       || mergetype==MERGE_AND    || mergetype==MERGE_NOT
  1963         -       || mergetype==MERGE_PHRASE || mergetype==MERGE_POS_PHRASE
  1964         -       || mergetype==MERGE_NEAR   || mergetype==MERGE_POS_NEAR
  1965         -  );
  1966         -  assert( mergetype==MERGE_POS_PHRASE || mergetype==MERGE_POS_NEAR );
  1967         -
  1968         -  if( !aBuffer ){
  1969         -    *pnBuffer = 0;
  1970         -    return SQLITE_NOMEM;
  1971         -  }
  1972         -
  1973         -  /* Read the first docid from each doclist */
  1974         -  fts3GetDeltaVarint2(&p1, pEnd1, &i1);
  1975         -  fts3GetDeltaVarint2(&p2, pEnd2, &i2);
  1976         -
  1977         -  switch( mergetype ){
  1978         -    case MERGE_OR:
  1979         -    case MERGE_POS_OR:
  1980         -      while( p1 || p2 ){
  1981         -        if( p2 && p1 && i1==i2 ){
  1982         -          fts3PutDeltaVarint(&p, &iPrev, i1);
  1983         -          if( mergetype==MERGE_POS_OR ) fts3PoslistMerge(&p, &p1, &p2);
  1984         -          fts3GetDeltaVarint2(&p1, pEnd1, &i1);
  1985         -          fts3GetDeltaVarint2(&p2, pEnd2, &i2);
  1986         -        }else if( !p2 || (p1 && i1<i2) ){
  1987         -          fts3PutDeltaVarint(&p, &iPrev, i1);
  1988         -          if( mergetype==MERGE_POS_OR ) fts3PoslistCopy(&p, &p1);
  1989         -          fts3GetDeltaVarint2(&p1, pEnd1, &i1);
  1990         -        }else{
  1991         -          fts3PutDeltaVarint(&p, &iPrev, i2);
  1992         -          if( mergetype==MERGE_POS_OR ) fts3PoslistCopy(&p, &p2);
  1993         -          fts3GetDeltaVarint2(&p2, pEnd2, &i2);
  1994         -        }
  1995         -      }
  1996         -      break;
  1997         -
  1998         -    case MERGE_AND:
  1999         -      while( p1 && p2 ){
  2000         -        if( i1==i2 ){
  2001         -          fts3PutDeltaVarint(&p, &iPrev, i1);
  2002         -          fts3GetDeltaVarint2(&p1, pEnd1, &i1);
  2003         -          fts3GetDeltaVarint2(&p2, pEnd2, &i2);
  2004         -          nDoc++;
  2005         -        }else if( i1<i2 ){
  2006         -          fts3GetDeltaVarint2(&p1, pEnd1, &i1);
  2007         -        }else{
  2008         -          fts3GetDeltaVarint2(&p2, pEnd2, &i2);
  2009         -        }
  2010         -      }
  2011         -      break;
  2012         -
  2013         -    case MERGE_NOT:
  2014         -      while( p1 ){
  2015         -        if( p2 && i1==i2 ){
  2016         -          fts3GetDeltaVarint2(&p1, pEnd1, &i1);
  2017         -          fts3GetDeltaVarint2(&p2, pEnd2, &i2);
  2018         -        }else if( !p2 || i1<i2 ){
  2019         -          fts3PutDeltaVarint(&p, &iPrev, i1);
  2020         -          fts3GetDeltaVarint2(&p1, pEnd1, &i1);
  2021         -        }else{
  2022         -          fts3GetDeltaVarint2(&p2, pEnd2, &i2);
  2023         -        }
  2024         -      }
  2025         -      break;
  2026         -
  2027         -    case MERGE_POS_PHRASE:
  2028         -    case MERGE_PHRASE: {
  2029         -      char **ppPos = (mergetype==MERGE_PHRASE ? 0 : &p);
  2030         -      while( p1 && p2 ){
  2031         -        if( i1==i2 ){
  2032         -          char *pSave = p;
  2033         -          sqlite3_int64 iPrevSave = iPrev;
  2034         -          fts3PutDeltaVarint(&p, &iPrev, i1);
  2035         -          if( 0==fts3PoslistPhraseMerge(ppPos, nParam1, 0, 1, &p1, &p2) ){
  2036         -            p = pSave;
  2037         -            iPrev = iPrevSave;
  2038         -          }else{
  2039         -            nDoc++;
  2040         -          }
  2041         -          fts3GetDeltaVarint2(&p1, pEnd1, &i1);
  2042         -          fts3GetDeltaVarint2(&p2, pEnd2, &i2);
  2043         -        }else if( i1<i2 ){
  2044         -          fts3PoslistCopy(0, &p1);
  2045         -          fts3GetDeltaVarint2(&p1, pEnd1, &i1);
  2046         -        }else{
  2047         -          fts3PoslistCopy(0, &p2);
  2048         -          fts3GetDeltaVarint2(&p2, pEnd2, &i2);
  2049         -        }
  2050         -      }
  2051         -      break;
  2052         -    }
  2053         -
  2054         -    default: assert( mergetype==MERGE_POS_NEAR || mergetype==MERGE_NEAR ); {
  2055         -      char *aTmp = 0;
  2056         -      char **ppPos = 0;
  2057         -
  2058         -      if( mergetype==MERGE_POS_NEAR ){
  2059         -        ppPos = &p;
  2060         -        aTmp = sqlite3_malloc(2*(n1+n2+1));
  2061         -        if( !aTmp ){
  2062         -          return SQLITE_NOMEM;
  2063         -        }
  2064         -      }
  2065         -
  2066         -      while( p1 && p2 ){
  2067         -        if( i1==i2 ){
  2068         -          char *pSave = p;
  2069         -          sqlite3_int64 iPrevSave = iPrev;
  2070         -          fts3PutDeltaVarint(&p, &iPrev, i1);
  2071         -
  2072         -          if( !fts3PoslistNearMerge(ppPos, aTmp, nParam1, nParam2, &p1, &p2) ){
  2073         -            iPrev = iPrevSave;
  2074         -            p = pSave;
  2075         -          }
  2076         -
  2077         -          fts3GetDeltaVarint2(&p1, pEnd1, &i1);
  2078         -          fts3GetDeltaVarint2(&p2, pEnd2, &i2);
  2079         -        }else if( i1<i2 ){
  2080         -          fts3PoslistCopy(0, &p1);
  2081         -          fts3GetDeltaVarint2(&p1, pEnd1, &i1);
  2082         -        }else{
  2083         -          fts3PoslistCopy(0, &p2);
  2084         -          fts3GetDeltaVarint2(&p2, pEnd2, &i2);
  2085         -        }
  2086         -      }
  2087         -      sqlite3_free(aTmp);
  2088         -      break;
  2089         -    }
  2090         -  }
  2091         -
  2092         -  if( pnDoc ) *pnDoc = nDoc;
  2093         -  *pnBuffer = (int)(p-aBuffer);
  2094         -  return SQLITE_OK;
  2095         -}
  2096         -
  2097   1901   /* 
  2098   1902   ** A pointer to an instance of this structure is used as the context 
  2099   1903   ** argument to sqlite3Fts3SegReaderIterate()
  2100   1904   */
  2101   1905   typedef struct TermSelect TermSelect;
  2102   1906   struct TermSelect {
  2103   1907     int isReqPos;
................................................................................
  2249   2053   
  2250   2054   /*
  2251   2055   ** This function merges two doclists according to the requirements of a
  2252   2056   ** NEAR operator.
  2253   2057   */
  2254   2058   static int fts3DoclistNearMerge(
  2255   2059     int bDescIdx,
  2256         -  int mergetype,                  /* MERGE_POS_NEAR or MERGE_NEAR */
  2257   2060     int nNear,                      /* Parameter to NEAR operator */
  2258   2061     int nTokenLeft,                 /* Number of tokens in LHS phrase arg */
  2259   2062     char *aLeft,                    /* Doclist for LHS (incl. positions) */
  2260   2063     int nLeft,                      /* Size of LHS doclist in bytes */
  2261   2064     int nTokenRight,                /* As nTokenLeft */
  2262   2065     char *aRight,                   /* As aLeft */
  2263   2066     int nRight,                     /* As nRight */
................................................................................
  2332   2135   ** other doclists (except the aaOutput[0] one) and return SQLITE_OK.
  2333   2136   **
  2334   2137   ** If an OOM error occurs, return SQLITE_NOMEM. In this case it is
  2335   2138   ** the responsibility of the caller to free any doclists left in the
  2336   2139   ** TermSelect.aaOutput[] array.
  2337   2140   */
  2338   2141   static int fts3TermSelectMerge(Fts3Table *p, TermSelect *pTS){
  2339         -  int mergetype = (pTS->isReqPos ? MERGE_POS_OR : MERGE_OR);
  2340   2142     char *aOut = 0;
  2341   2143     int nOut = 0;
  2342   2144     int i;
  2343   2145   
  2344   2146     /* Loop through the doclists in the aaOutput[] array. Merge them all
  2345   2147     ** into a single doclist.
  2346   2148     */
................................................................................
  2402   2204       pTS->anOutput[0] = nDoclist;
  2403   2205       if( pTS->aaOutput[0] ){
  2404   2206         memcpy(pTS->aaOutput[0], aDoclist, nDoclist);
  2405   2207       }else{
  2406   2208         return SQLITE_NOMEM;
  2407   2209       }
  2408   2210     }else{
  2409         -    int mergetype = (pTS->isReqPos ? MERGE_POS_OR : MERGE_OR);
  2410   2211       char *aMerge = aDoclist;
  2411   2212       int nMerge = nDoclist;
  2412   2213       int iOut;
  2413   2214   
  2414   2215       for(iOut=0; iOut<SizeofArray(pTS->aaOutput); iOut++){
  2415   2216         if( pTS->aaOutput[iOut]==0 ){
  2416   2217           assert( iOut>0 );
................................................................................
  3812   3613         sqlite3_free(pRight->doclist.aAll);
  3813   3614         pRight->doclist.aAll = 0;
  3814   3615         pRight->doclist.nAll = 0;
  3815   3616       }else if( pRight->doclist.aAll ){
  3816   3617         char *aOut;                 /* Buffer in which to assemble new doclist */
  3817   3618         int nOut;                   /* Size of buffer aOut in bytes */
  3818   3619     
  3819         -      *pRc = fts3DoclistNearMerge(bDescIdx, MERGE_POS_NEAR, nNear, 
         3620  +      *pRc = fts3DoclistNearMerge(bDescIdx, nNear, 
  3820   3621             pLeft->nToken, pLeft->doclist.aAll, pLeft->doclist.nAll,
  3821   3622             pRight->nToken, pRight->doclist.aAll, pRight->doclist.nAll,
  3822   3623             &aOut, &nOut
  3823   3624         );
  3824   3625         sqlite3_free(pRight->doclist.aAll);
  3825   3626         pRight->doclist.aAll = aOut;
  3826   3627         pRight->doclist.nAll = nOut;