/ Check-in [f85f9103]
Login

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

Overview
Comment:In fts3, when filtering lists for hits in a specific column, edit the list in place in the same way as it is for NEAR filtering. Fix for [38b1ae018f].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f85f9103cffa5c8ba6a63a68beb90817147ba080
User & Date: dan 2013-03-25 11:38:44
Context
2013-03-25
12:02
Add a second test for [38b1ae018f]. check-in: 5062db67 user: dan tags: trunk
11:38
In fts3, when filtering lists for hits in a specific column, edit the list in place in the same way as it is for NEAR filtering. Fix for [38b1ae018f]. check-in: f85f9103 user: dan tags: trunk
2013-03-24
22:56
Remove the SQLITE_OMIT_MERGE_SORT compile-time option and its related code. The merge sorter is now a required component. check-in: 8b44d6fb user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to ext/fts3/fts3_write.c.

  1478   1478       ** size of the previous offset-list.
  1479   1479       */
  1480   1480       if( ppOffsetList ){
  1481   1481         *ppOffsetList = pReader->pOffsetList;
  1482   1482         *pnOffsetList = (int)(p - pReader->pOffsetList - 1);
  1483   1483       }
  1484   1484   
         1485  +    /* List may have been edited in place by fts3EvalNearTrim() */
  1485   1486       while( p<pEnd && *p==0 ) p++;
  1486   1487     
  1487   1488       /* If there are no more entries in the doclist, set pOffsetList to
  1488   1489       ** NULL. Otherwise, set Fts3SegReader.iDocid to the next docid and
  1489   1490       ** Fts3SegReader.pOffsetList to point to the next offset list before
  1490   1491       ** returning.
  1491   1492       */
................................................................................
  2493   2494   ** When this function is called, buffer *ppList (size *pnList bytes) contains 
  2494   2495   ** a position list that may (or may not) feature multiple columns. This
  2495   2496   ** function adjusts the pointer *ppList and the length *pnList so that they
  2496   2497   ** identify the subset of the position list that corresponds to column iCol.
  2497   2498   **
  2498   2499   ** If there are no entries in the input position list for column iCol, then
  2499   2500   ** *pnList is set to zero before returning.
         2501  +**
         2502  +** If parameter bZero is non-zero, then any part of the input list following
         2503  +** the end of the output list is zeroed before returning.
  2500   2504   */
  2501   2505   static void fts3ColumnFilter(
  2502   2506     int iCol,                       /* Column to filter on */
         2507  +  int bZero,                      /* Zero out anything following *ppList */
  2503   2508     char **ppList,                  /* IN/OUT: Pointer to position list */
  2504   2509     int *pnList                     /* IN/OUT: Size of buffer *ppList in bytes */
  2505   2510   ){
  2506   2511     char *pList = *ppList;
  2507   2512     int nList = *pnList;
  2508   2513     char *pEnd = &pList[nList];
  2509   2514     int iCurrent = 0;
................................................................................
  2524   2529       if( nList==0 ){
  2525   2530         break;
  2526   2531       }
  2527   2532       p = &pList[1];
  2528   2533       p += sqlite3Fts3GetVarint32(p, &iCurrent);
  2529   2534     }
  2530   2535   
         2536  +  if( bZero && &pList[nList]!=pEnd ){
         2537  +    memset(&pList[nList], 0, pEnd - &pList[nList]);
         2538  +  }
  2531   2539     *ppList = pList;
  2532   2540     *pnList = nList;
  2533   2541   }
  2534   2542   
  2535   2543   /*
  2536   2544   ** Cache data in the Fts3MultiSegReader.aBuffer[] buffer (overwriting any
  2537   2545   ** existing data). Grow the buffer if required.
................................................................................
  2596   2604           && apSegment[j]->iDocid==iDocid
  2597   2605         ){
  2598   2606           rc = fts3SegReaderNextDocid(p, apSegment[j], 0, 0);
  2599   2607           j++;
  2600   2608         }
  2601   2609         if( rc!=SQLITE_OK ) return rc;
  2602   2610         fts3SegReaderSort(pMsr->apSegment, nMerge, j, xCmp);
         2611  +
         2612  +      if( nList>0 && fts3SegReaderIsPending(apSegment[0]) ){
         2613  +        rc = fts3MsrBufferData(pMsr, pList, nList+1);
         2614  +        if( rc!=SQLITE_OK ) return rc;
         2615  +        assert( (pMsr->aBuffer[nList] & 0xFE)==0x00 );
         2616  +        pList = pMsr->aBuffer;
         2617  +      }
  2603   2618   
  2604   2619         if( pMsr->iColFilter>=0 ){
  2605         -        fts3ColumnFilter(pMsr->iColFilter, &pList, &nList);
         2620  +        fts3ColumnFilter(pMsr->iColFilter, 1, &pList, &nList);
  2606   2621         }
  2607   2622   
  2608   2623         if( nList>0 ){
  2609         -        if( fts3SegReaderIsPending(apSegment[0]) ){
  2610         -          rc = fts3MsrBufferData(pMsr, pList, nList+1);
  2611         -          if( rc!=SQLITE_OK ) return rc;
  2612         -          *paPoslist = pMsr->aBuffer;
  2613         -          assert( (pMsr->aBuffer[nList] & 0xFE)==0x00 );
  2614         -        }else{
  2615   2624             *paPoslist = pList;
  2616         -        }
  2617   2625           *piDocid = iDocid;
  2618   2626           *pnPoslist = nList;
  2619   2627           break;
  2620   2628         }
  2621   2629       }
  2622   2630     }
  2623   2631   
................................................................................
  2852   2860               && apSegment[j]->iDocid==iDocid
  2853   2861           ){
  2854   2862             fts3SegReaderNextDocid(p, apSegment[j], 0, 0);
  2855   2863             j++;
  2856   2864           }
  2857   2865   
  2858   2866           if( isColFilter ){
  2859         -          fts3ColumnFilter(pFilter->iCol, &pList, &nList);
         2867  +          fts3ColumnFilter(pFilter->iCol, 0, &pList, &nList);
  2860   2868           }
  2861   2869   
  2862   2870           if( !isIgnoreEmpty || nList>0 ){
  2863   2871   
  2864   2872             /* Calculate the 'docid' delta value to write into the merged 
  2865   2873             ** doclist. */
  2866   2874             sqlite3_int64 iDelta;

Changes to test/fts3near.test.

   576    576   } {}
   577    577   do_test fts3near-6.5 {
   578    578     execsql {
   579    579       SELECT docid FROM t1 WHERE content MATCH 'abbrev NEAR/10000 zygosis'
   580    580     }
   581    581   } {3}
   582    582   
          583  +# Ticket 38b1ae018f.
          584  +#
          585  +do_execsql_test fts3near-7.1 {
          586  +  CREATE VIRTUAL TABLE x USING fts4(y,z);
          587  +  INSERT INTO x VALUES('aaa bbb ccc ddd', 'bbb ddd aaa ccc');
          588  +  SELECT * FROM x where y MATCH 'bbb NEAR/6 aaa';
          589  +} {{aaa bbb ccc ddd} {bbb ddd aaa ccc}}
          590  +
   583    591   
   584    592   finish_test