Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Fix the xColumnSize() extension API. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | fts5 |
Files: | files | file ages | folders |
SHA1: |
19504c4108472d2ad1281221642b8bd0 |
User & Date: | dan 2014-07-21 11:44:47.659 |
Context
2014-07-21
| ||
14:22 | Add the xTokenize extension API. (check-in: 8c6b0aff34 user: dan tags: fts5) | |
11:44 | Fix the xColumnSize() extension API. (check-in: 19504c4108 user: dan tags: fts5) | |
2014-07-19
| ||
20:27 | Add simple tests for the xColumnText() extension api. (check-in: 1e9053abda user: dan tags: fts5) | |
Changes
Changes to ext/fts5/fts5.c.
︙ | ︙ | |||
615 616 617 618 619 620 621 | static int fts5ApiColumnCount(Fts5Context *pCtx){ Fts5Cursor *pCsr = (Fts5Cursor*)pCtx; return ((Fts5Table*)(pCsr->base.pVtab))->pConfig->nCol; } static int fts5ApiColumnAvgSize(Fts5Context *pCtx, int iCol, int *pnToken){ | | > | | 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 | static int fts5ApiColumnCount(Fts5Context *pCtx){ Fts5Cursor *pCsr = (Fts5Cursor*)pCtx; return ((Fts5Table*)(pCsr->base.pVtab))->pConfig->nCol; } static int fts5ApiColumnAvgSize(Fts5Context *pCtx, int iCol, int *pnToken){ Fts5Cursor *pCsr = (Fts5Cursor*)pCtx; Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab); return sqlite3Fts5StorageAvgsize(pTab->pStorage, iCol, pnToken); } static int fts5ApiTokenize( Fts5Context *pCtx, const char *pText, int nText, void *pUserData, int (*xToken)(void*, const char*, int, int, int, int) |
︙ | ︙ |
Changes to ext/fts5/fts5Int.h.
︙ | ︙ | |||
263 264 265 266 267 268 269 270 271 272 273 274 275 276 | int sqlite3Fts5IndexIntegrityCheck(Fts5Index*, u64 cksum); /* Called during startup to register a UDF with SQLite */ int sqlite3Fts5IndexInit(sqlite3*); void sqlite3Fts5IndexPgsz(Fts5Index *p, int pgsz); /* ** End of interface to code in fts5_index.c. **************************************************************************/ /************************************************************************** ** Interface to code in fts5_storage.c. fts5_storage.c contains contains ** code to access the data stored in the %_content and %_docsize tables. | > > > | 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | int sqlite3Fts5IndexIntegrityCheck(Fts5Index*, u64 cksum); /* Called during startup to register a UDF with SQLite */ int sqlite3Fts5IndexInit(sqlite3*); void sqlite3Fts5IndexPgsz(Fts5Index *p, int pgsz); int sqlite3Fts5IndexGetAverages(Fts5Index *p, Fts5Buffer *pBuf); int sqlite3Fts5IndexSetAverages(Fts5Index *p, const u8*, int); /* ** End of interface to code in fts5_index.c. **************************************************************************/ /************************************************************************** ** Interface to code in fts5_storage.c. fts5_storage.c contains contains ** code to access the data stored in the %_content and %_docsize tables. |
︙ | ︙ | |||
293 294 295 296 297 298 299 | int sqlite3Fts5StorageIntegrity(Fts5Storage *p); int sqlite3Fts5StorageStmt(Fts5Storage *p, int eStmt, sqlite3_stmt **); void sqlite3Fts5StorageStmtRelease(Fts5Storage *p, int eStmt, sqlite3_stmt*); int sqlite3Fts5StorageDocsize(Fts5Storage *p, i64 iRowid, int *aCol); | | | 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | int sqlite3Fts5StorageIntegrity(Fts5Storage *p); int sqlite3Fts5StorageStmt(Fts5Storage *p, int eStmt, sqlite3_stmt **); void sqlite3Fts5StorageStmtRelease(Fts5Storage *p, int eStmt, sqlite3_stmt*); int sqlite3Fts5StorageDocsize(Fts5Storage *p, i64 iRowid, int *aCol); int sqlite3Fts5StorageAvgsize(Fts5Storage *p, int iCol, int *pnAvg); /* ** End of interface to code in fts5_storage.c. **************************************************************************/ |
︙ | ︙ |
Changes to ext/fts5/fts5_aux.c.
︙ | ︙ | |||
39 40 41 42 43 44 45 46 47 48 49 | int i; if( nVal>=1 ){ zReq = (const char*)sqlite3_value_text(apVal[0]); } memset(&s, 0, sizeof(Fts5Buffer)); if( zReq==0 ){ sqlite3Fts5BufferAppendPrintf(&rc, &s, "columncount "); } | > > > > > > > > > > > > > > < | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | int i; if( nVal>=1 ){ zReq = (const char*)sqlite3_value_text(apVal[0]); } memset(&s, 0, sizeof(Fts5Buffer)); nCol = pApi->xColumnCount(pFts); if( zReq==0 ){ sqlite3Fts5BufferAppendPrintf(&rc, &s, "columnavgsize "); } if( 0==zReq || 0==sqlite3_stricmp(zReq, "columnavgsize") ){ if( zReq==0 && nCol>1 ) sqlite3Fts5BufferAppendPrintf(&rc, &s, "{"); for(i=0; rc==SQLITE_OK && i<nCol; i++){ int colsz = 0; rc = pApi->xColumnAvgSize(pFts, i, &colsz); sqlite3Fts5BufferAppendPrintf(&rc, &s, "%s%d", i==0?"":" ", colsz); } if( zReq==0 && nCol>1 ) sqlite3Fts5BufferAppendPrintf(&rc, &s, "}"); } if( zReq==0 ){ sqlite3Fts5BufferAppendPrintf(&rc, &s, "columncount "); } if( 0==zReq || 0==sqlite3_stricmp(zReq, "columncount") ){ sqlite3Fts5BufferAppendPrintf(&rc, &s, "%d", nCol); } if( zReq==0 ){ sqlite3Fts5BufferAppendPrintf(&rc, &s, "columnsize "); } |
︙ | ︙ |
Changes to ext/fts5/fts5_index.c.
︙ | ︙ | |||
730 731 732 733 734 735 736 | static void fts5DataReference(Fts5Data *pData){ pData->nRef++; } /* ** INSERT OR REPLACE a record into the %_data table. */ | | | 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 | static void fts5DataReference(Fts5Data *pData){ pData->nRef++; } /* ** INSERT OR REPLACE a record into the %_data table. */ static void fts5DataWrite(Fts5Index *p, i64 iRowid, const u8 *pData, int nData){ if( p->rc!=SQLITE_OK ) return; if( p->pWriter==0 ){ int rc; Fts5Config *pConfig = p->pConfig; char *zSql = sqlite3_mprintf( "REPLACE INTO '%q'.%Q(id, block) VALUES(?,?)", pConfig->zDb, p->zDataTbl |
︙ | ︙ | |||
2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 | if( rc==SQLITE_OK ){ memset(&s, 0, sizeof(Fts5Structure)); for(i=0; i<pConfig->nPrefix+1; i++){ fts5StructureWrite(p, i, &s); } rc = p->rc; } } if( rc ){ sqlite3Fts5IndexClose(p, 0); *pp = 0; } return rc; | > | 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 | if( rc==SQLITE_OK ){ memset(&s, 0, sizeof(Fts5Structure)); for(i=0; i<pConfig->nPrefix+1; i++){ fts5StructureWrite(p, i, &s); } rc = p->rc; } sqlite3Fts5IndexSetAverages(p, (const u8*)"", 0); } if( rc ){ sqlite3Fts5IndexClose(p, 0); *pp = 0; } return rc; |
︙ | ︙ | |||
3614 3615 3616 3617 3618 3619 3620 3621 | fts5StructureRelease(pIter->pStruct); fts5BufferFree(&pIter->poslist); } fts5CloseReader(pIter->pIndex); sqlite3_free(pIter); } } | > > > > > > > > > > > > > > > > > > > | 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 | fts5StructureRelease(pIter->pStruct); fts5BufferFree(&pIter->poslist); } fts5CloseReader(pIter->pIndex); sqlite3_free(pIter); } } /* ** Read the "averages" record into the buffer supplied as the second ** argument. Return SQLITE_OK if successful, or an SQLite error code ** if an error occurs. */ int sqlite3Fts5IndexGetAverages(Fts5Index *p, Fts5Buffer *pBuf){ fts5DataReadOrBuffer(p, pBuf, FTS5_AVERAGES_ROWID); return p->rc; } /* ** Replace the current "averages" record with the contents of the buffer ** supplied as the second argument. */ int sqlite3Fts5IndexSetAverages(Fts5Index *p, const u8 *pData, int nData){ fts5DataWrite(p, FTS5_AVERAGES_ROWID, pData, nData); return p->rc; } |
Changes to ext/fts5/fts5_storage.c.
︙ | ︙ | |||
13 14 15 16 17 18 19 20 21 22 23 24 25 26 | */ #include "fts5Int.h" struct Fts5Storage { Fts5Config *pConfig; Fts5Index *pIndex; sqlite3_stmt *aStmt[9]; }; #if FTS5_STMT_SCAN_ASC!=0 # error "FTS5_STMT_SCAN_ASC mismatch" #endif | > > | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | */ #include "fts5Int.h" struct Fts5Storage { Fts5Config *pConfig; Fts5Index *pIndex; i64 nTotalRow; /* Total number of rows in FTS table */ i64 *aTotalSize; /* Total sizes of each column */ sqlite3_stmt *aStmt[9]; }; #if FTS5_STMT_SCAN_ASC!=0 # error "FTS5_STMT_SCAN_ASC mismatch" #endif |
︙ | ︙ | |||
164 165 166 167 168 169 170 171 | Fts5Index *pIndex, int bCreate, Fts5Storage **pp, char **pzErr /* OUT: Error message */ ){ int rc; Fts5Storage *p; /* New object */ | > > > | | > | 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | Fts5Index *pIndex, int bCreate, Fts5Storage **pp, char **pzErr /* OUT: Error message */ ){ int rc; Fts5Storage *p; /* New object */ int nByte; /* Bytes of space to allocate */ nByte = sizeof(Fts5Storage) /* Fts5Storage object */ + pConfig->nCol * sizeof(i64); /* Fts5Storage.aTotalSize[] */ *pp = p = (Fts5Storage*)sqlite3_malloc(nByte); if( !p ) return SQLITE_NOMEM; memset(p, 0, nByte); p->aTotalSize = (i64*)&p[1]; p->pConfig = pConfig; p->pIndex = pIndex; if( bCreate ){ int i; char *zDefn = sqlite3_malloc(32 + pConfig->nCol * 10); if( zDefn==0 ){ |
︙ | ︙ | |||
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | for(iCol=1; iCol<=pConfig->nCol; iCol++){ rc = sqlite3Fts5Tokenize(pConfig, (const char*)sqlite3_column_text(pSeek, iCol), sqlite3_column_bytes(pSeek, iCol), (void*)&ctx, fts5StorageInsertCallback ); } } rc2 = sqlite3_reset(pSeek); if( rc==SQLITE_OK ) rc = rc2; } return rc; } | > > | 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | for(iCol=1; iCol<=pConfig->nCol; iCol++){ rc = sqlite3Fts5Tokenize(pConfig, (const char*)sqlite3_column_text(pSeek, iCol), sqlite3_column_bytes(pSeek, iCol), (void*)&ctx, fts5StorageInsertCallback ); p->aTotalSize[iCol-1] -= (i64)ctx.szCol; } p->nTotalRow--; } rc2 = sqlite3_reset(pSeek); if( rc==SQLITE_OK ) rc = rc2; } return rc; } |
︙ | ︙ | |||
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | sqlite3_bind_int64(pReplace, 1, iRowid); sqlite3_bind_blob(pReplace, 2, pBuf->p, pBuf->n, SQLITE_STATIC); sqlite3_step(pReplace); rc = sqlite3_reset(pReplace); } return rc; } /* ** Insert a new row into the FTS table. */ int sqlite3Fts5StorageInsert( Fts5Storage *p, /* Storage module to write to */ sqlite3_value **apVal, /* Array of values passed to xUpdate() */ int eConflict, /* on conflict clause */ i64 *piRowid /* OUT: rowid of new record */ ){ Fts5Config *pConfig = p->pConfig; int rc = SQLITE_OK; /* Return code */ sqlite3_stmt *pInsert; /* Statement used to write %_content table */ int eStmt; /* Type of statement used on %_content */ int i; /* Counter variable */ Fts5InsertCtx ctx; /* Tokenization callback context object */ Fts5Buffer buf; /* Buffer used to build up %_docsize blob */ memset(&buf, 0, sizeof(Fts5Buffer)); /* Insert the new row into the %_content table. */ | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | | | | > | 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | sqlite3_bind_int64(pReplace, 1, iRowid); sqlite3_bind_blob(pReplace, 2, pBuf->p, pBuf->n, SQLITE_STATIC); sqlite3_step(pReplace); rc = sqlite3_reset(pReplace); } return rc; } /* ** Load the contents of the "averages" record from disk into the ** p->nTotalRow and p->aTotalSize[] variables. ** ** Return SQLITE_OK if successful, or an SQLite error code if an error ** occurs. */ static int fts5StorageLoadTotals(Fts5Storage *p){ int nCol = p->pConfig->nCol; Fts5Buffer buf; int rc; memset(&buf, 0, sizeof(buf)); memset(p->aTotalSize, 0, sizeof(i64) * nCol); p->nTotalRow = 0; rc = sqlite3Fts5IndexGetAverages(p->pIndex, &buf); if( rc==SQLITE_OK && buf.n ){ int i = 0; int iCol; i += getVarint(&buf.p[i], (u64*)&p->nTotalRow); for(iCol=0; i<buf.n && iCol<nCol; iCol++){ i += getVarint(&buf.p[i], (u64*)&p->aTotalSize[iCol]); } } sqlite3_free(buf.p); return rc; } /* ** Store the current contents of the p->nTotalRow and p->aTotalSize[] ** variables in the "averages" record on disk. ** ** Return SQLITE_OK if successful, or an SQLite error code if an error ** occurs. */ static int fts5StorageSaveTotals(Fts5Storage *p){ int nCol = p->pConfig->nCol; int i; Fts5Buffer buf; int rc = SQLITE_OK; memset(&buf, 0, sizeof(buf)); sqlite3Fts5BufferAppendVarint(&rc, &buf, p->nTotalRow); for(i=0; i<nCol; i++){ sqlite3Fts5BufferAppendVarint(&rc, &buf, p->aTotalSize[i]); } if( rc==SQLITE_OK ){ rc = sqlite3Fts5IndexSetAverages(p->pIndex, buf.p, buf.n); } sqlite3_free(buf.p); return rc; } /* ** Insert a new row into the FTS table. */ int sqlite3Fts5StorageInsert( Fts5Storage *p, /* Storage module to write to */ sqlite3_value **apVal, /* Array of values passed to xUpdate() */ int eConflict, /* on conflict clause */ i64 *piRowid /* OUT: rowid of new record */ ){ Fts5Config *pConfig = p->pConfig; int rc = SQLITE_OK; /* Return code */ sqlite3_stmt *pInsert; /* Statement used to write %_content table */ int eStmt; /* Type of statement used on %_content */ int i; /* Counter variable */ Fts5InsertCtx ctx; /* Tokenization callback context object */ Fts5Buffer buf; /* Buffer used to build up %_docsize blob */ memset(&buf, 0, sizeof(Fts5Buffer)); rc = fts5StorageLoadTotals(p); /* Insert the new row into the %_content table. */ if( rc==SQLITE_OK ){ if( eConflict==SQLITE_REPLACE ){ eStmt = FTS5_STMT_REPLACE_CONTENT; if( sqlite3_value_type(apVal[1])==SQLITE_INTEGER ){ rc = fts5StorageDeleteFromIndex(p, sqlite3_value_int64(apVal[1])); } }else{ eStmt = FTS5_STMT_INSERT_CONTENT; } } if( rc==SQLITE_OK ){ rc = fts5StorageGetStmt(p, eStmt, &pInsert); } for(i=1; rc==SQLITE_OK && i<=pConfig->nCol+1; i++){ rc = sqlite3_bind_value(pInsert, i, apVal[i]); } |
︙ | ︙ | |||
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | rc = sqlite3Fts5Tokenize(pConfig, (const char*)sqlite3_value_text(apVal[ctx.iCol+2]), sqlite3_value_bytes(apVal[ctx.iCol+2]), (void*)&ctx, fts5StorageInsertCallback ); sqlite3Fts5BufferAppendVarint(&rc, &buf, ctx.szCol); } /* Write the %_docsize record */ if( rc==SQLITE_OK ){ rc = fts5StorageInsertDocsize(p, *piRowid, &buf); } sqlite3_free(buf.p); return rc; } /* ** Context object used by sqlite3Fts5StorageIntegrity(). */ | > > > > > > > | 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | rc = sqlite3Fts5Tokenize(pConfig, (const char*)sqlite3_value_text(apVal[ctx.iCol+2]), sqlite3_value_bytes(apVal[ctx.iCol+2]), (void*)&ctx, fts5StorageInsertCallback ); sqlite3Fts5BufferAppendVarint(&rc, &buf, ctx.szCol); p->aTotalSize[ctx.iCol] += (i64)ctx.szCol; } p->nTotalRow++; /* Write the %_docsize record */ if( rc==SQLITE_OK ){ rc = fts5StorageInsertDocsize(p, *piRowid, &buf); } sqlite3_free(buf.p); /* Write the averages record */ if( rc==SQLITE_OK ){ rc = fts5StorageSaveTotals(p); } return rc; } /* ** Context object used by sqlite3Fts5StorageIntegrity(). */ |
︙ | ︙ | |||
534 535 536 537 538 539 540 | if( bCorrupt && rc==SQLITE_OK ){ rc = SQLITE_CORRUPT_VTAB; } } return rc; } | | > > > > > > > > > | | 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 | if( bCorrupt && rc==SQLITE_OK ){ rc = SQLITE_CORRUPT_VTAB; } } return rc; } int sqlite3Fts5StorageAvgsize(Fts5Storage *p, int iCol, int *pnAvg){ int rc = fts5StorageLoadTotals(p); if( rc==SQLITE_OK ){ int nAvg = 1; if( p->nTotalRow ){ nAvg = (int)((p->aTotalSize[iCol] + (p->nTotalRow/2)) / p->nTotalRow); if( nAvg<1 ) nAvg = 1; *pnAvg = nAvg; } } return rc; } |
Changes to test/fts5aa.test.
︙ | ︙ | |||
125 126 127 128 129 130 131 132 133 134 135 136 137 138 | do_execsql_test 5.$i.1 { INSERT INTO t1 VALUES($x, $y) } do_execsql_test 5.$i.2 { INSERT INTO t1(t1) VALUES('integrity-check') } if {[set_test_counter errors]} break } #------------------------------------------------------------------------- # reset_db do_execsql_test 6.0 { CREATE VIRTUAL TABLE t1 USING fts5(x,y); INSERT INTO t1(t1) VALUES('pgsz=32'); } do_execsql_test 6.1 { | > | 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | do_execsql_test 5.$i.1 { INSERT INTO t1 VALUES($x, $y) } do_execsql_test 5.$i.2 { INSERT INTO t1(t1) VALUES('integrity-check') } if {[set_test_counter errors]} break } #------------------------------------------------------------------------- # breakpoint reset_db do_execsql_test 6.0 { CREATE VIRTUAL TABLE t1 USING fts5(x,y); INSERT INTO t1(t1) VALUES('pgsz=32'); } do_execsql_test 6.1 { |
︙ | ︙ |
Changes to test/fts5ae.test.
︙ | ︙ | |||
124 125 126 127 128 129 130 | do_execsql_test 4.1 { SELECT rowid, fts5_test(t4, 'poslist') FROM t4 WHERE t4 MATCH 'a OR b AND c'; } { 1 {0.5 {} {}} } #------------------------------------------------------------------------- | | | 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | do_execsql_test 4.1 { SELECT rowid, fts5_test(t4, 'poslist') FROM t4 WHERE t4 MATCH 'a OR b AND c'; } { 1 {0.5 {} {}} } #------------------------------------------------------------------------- # Test that the xColumnSize() and xColumnAvgsize() APIs work. # reset_db do_execsql_test 5.1 { CREATE VIRTUAL TABLE t5 USING fts5(x, y); INSERT INTO t5 VALUES('a b c d', 'e f g h i j'); INSERT INTO t5 VALUES('', 'a'); |
︙ | ︙ | |||
151 152 153 154 155 156 157 158 159 160 161 | SELECT rowid, fts5_test(t5, 'columntext') FROM t5 WHERE t5 MATCH 'a' ORDER BY rowid DESC; } { 3 {a {}} 2 {{} a} 1 {{a b c d} {e f g h i j}} } finish_test | > > > > > > > > > > > > > > > > > > > > | 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | SELECT rowid, fts5_test(t5, 'columntext') FROM t5 WHERE t5 MATCH 'a' ORDER BY rowid DESC; } { 3 {a {}} 2 {{} a} 1 {{a b c d} {e f g h i j}} } do_execsql_test 5.3 { SELECT rowid, fts5_test(t5, 'columnavgsize') FROM t5 WHERE t5 MATCH 'a' ORDER BY rowid DESC; } { 3 {2 2} 2 {2 2} 1 {2 2} } do_execsql_test 5.4 { INSERT INTO t5 VALUES('x y z', 'v w x y z'); SELECT rowid, fts5_test(t5, 'columnavgsize') FROM t5 WHERE t5 MATCH 'a' ORDER BY rowid DESC; } { 3 {2 3} 2 {2 3} 1 {2 3} } finish_test |