Lines Matching refs:pIter
52023 WalIterator *pIter = 0; /* Wal iterator context */
52038 rc = walIteratorInit(pWal, &pIter);
52042 assert( pIter );
52104 while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
52184 walIteratorFree(pIter);
54770 BtLock *pIter;
54797 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
54798 /* The condition (pIter->eLock!=eLock) in the following if(...)
54801 ** (eLock==WRITE_LOCK || pIter->eLock==WRITE_LOCK)
54807 assert( pIter->eLock==READ_LOCK || pIter->eLock==WRITE_LOCK );
54808 assert( eLock==READ_LOCK || pIter->pBtree==p || pIter->eLock==READ_LOCK);
54809 if( pIter->pBtree!=p && pIter->iTable==iTab && pIter->eLock!=eLock ){
54810 sqlite3ConnectionBlocked(p->db, pIter->pBtree->db);
54843 BtLock *pIter;
54861 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
54862 if( pIter->iTable==iTable && pIter->pBtree==p ){
54863 pLock = pIter;
55597 u8 *pIter; /* For scanning through pCell */
55607 pIter = pCell;
55611 ** pIter += getVarint32(pIter, nPayload);
55615 nPayload = *pIter;
55617 u8 *pEnd = &pIter[8];
55620 nPayload = (nPayload<<7) | (*++pIter & 0x7f);
55621 }while( (*pIter)>=0x80 && pIter<pEnd );
55623 pIter++;
55627 ** pIter += getVarint(pIter, (u64*)&pInfo->nKey);
55631 iKey = *pIter;
55633 u8 *pEnd = &pIter[7];
55636 iKey = (iKey<<7) | (*++pIter & 0x7f);
55637 if( (*pIter)<0x80 ) break;
55638 if( pIter>=pEnd ){
55639 iKey = (iKey<<8) | *++pIter;
55644 pIter++;
55648 pInfo->pPayload = pIter;
55655 pInfo->nSize = nPayload + (u16)(pIter - pCell);
55668 u8 *pIter; /* For scanning through pCell */
55675 pIter = pCell + pPage->childPtrSize;
55676 nPayload = *pIter;
55678 u8 *pEnd = &pIter[8];
55681 nPayload = (nPayload<<7) | (*++pIter & 0x7f);
55682 }while( *(pIter)>=0x80 && pIter<pEnd );
55684 pIter++;
55687 pInfo->pPayload = pIter;
55694 pInfo->nSize = nPayload + (u16)(pIter - pCell);
55723 u8 *pIter = pCell + pPage->childPtrSize; /* For looping over bytes of pCell */
55737 nSize = *pIter;
55739 pEnd = &pIter[8];
55742 nSize = (nSize<<7) | (*++pIter & 0x7f);
55743 }while( *(pIter)>=0x80 && pIter<pEnd );
55745 pIter++;
55747 /* pIter now points at the 64-bit integer key value, a variable length
55748 ** integer. The following block moves pIter to point at the first byte
55750 pEnd = &pIter[9];
55751 while( (*pIter++)&0x80 && pIter<pEnd );
55756 nSize += (u32)(pIter - pCell);
55766 nSize += 4 + (u16)(pIter - pCell);
55772 u8 *pIter = pCell + 4; /* For looping over bytes of pCell */
55787 pEnd = pIter + 9;
55788 while( (*pIter++)&0x80 && pIter<pEnd );
55789 assert( debuginfo.nSize==(u16)(pIter - pCell) || CORRUPT_DB );
55790 return (u16)(pIter - pCell);
57650 BtLock *pIter;
57651 for(pIter=pBt->pLock; pIter; pIter=pIter->pNext){
57652 if( pIter->pBtree!=p ){
57653 pBlock = pIter->pBtree->db;
140274 char *pIter; /* Used to iterate through aAll */
140278 pIter = pDL->pNextDocid;
140280 pIter = pDL->aAll;
140283 if( pIter>=pEnd ){
140288 pIter += sqlite3Fts3GetVarint(pIter, &iDelta);
140294 pDL->pList = pIter;
140295 fts3PoslistCopy(0, &pIter);
140296 pDL->nList = (int)(pIter - pDL->pList);
140298 /* pIter now points just past the 0x00 that terminates the position-
140300 ** edited in place by fts3EvalNearTrim(), then pIter may not actually
140302 ** with this case by advancing pIter past the zero-padding added by
140304 while( pIter<pEnd && *pIter==0 ) pIter++;
140306 pDL->pNextDocid = pIter;
140307 assert( pIter>=&pDL->aAll[pDL->nAll] || *pIter );
141641 char *pIter;
141654 pIter = pPhrase->doclist.pList;
141706 pIter = pPh->pOrPoslist;
141710 (pIter >= (pPh->doclist.aAll + pPh->doclist.nAll));
141711 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){
141714 &pIter, &iDocid, &bEof
141718 bEof = !pPh->doclist.nAll || (pIter && pIter<=pPh->doclist.aAll);
141719 while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)>0 ) && bEof==0 ){
141723 &pIter, &iDocid, &dummy, &bEof
141727 pPh->pOrPoslist = pIter;
141733 pIter = pPhrase->pOrPoslist;
141735 pIter = 0;
141738 if( pIter==0 ) return SQLITE_OK;
141740 if( *pIter==0x01 ){
141741 pIter++;
141742 pIter += fts3GetVarint32(pIter, &iThis);
141747 fts3ColumnlistCopy(0, &pIter);
141748 if( *pIter==0x00 ) return SQLITE_OK;
141749 pIter++;
141750 pIter += fts3GetVarint32(pIter, &iThis);
141752 if( *pIter==0x00 ){
141753 pIter = 0;
141756 *ppOut = ((iCol==iThis)?pIter:0);
143097 Fts3Expr *pIter = pNotBranch;
143098 while( pIter->pLeft ){
143099 pIter = pIter->pLeft;
143101 pIter->pLeft = pRet;
143102 pRet->pParent = pIter;
148066 SegmentNode *pIter;
148069 for(pIter=pTree->pLeftmost; pIter && rc==SQLITE_OK; pIter=pIter->pRight){
148070 int nStart = fts3TreeFinishNode(pIter, iHeight, iNextLeaf);
148071 int nWrite = pIter->nData - nStart;
148073 rc = fts3WriteSegment(p, iNextFree, &pIter->aData[nStart], nWrite);
148075 iNextLeaf += (pIter->nEntry+1);
151941 char *pIter = *ppIter;
151942 if( pIter ){
151946 if( 0==(*pIter & 0xFE) ){
151948 pIter = 0;
151951 fts3GetDeltaPosition(&pIter, &iIter);
151955 *ppIter = pIter;
151962 static int fts3SnippetNextCandidate(SnippetIter *pIter){
151965 if( pIter->iCurrent<0 ){
151970 pIter->iCurrent = 0;
151975 for(i=0; i<pIter->nPhrase; i++){
151976 SnippetPhrase *pPhrase = &pIter->aPhrase[i];
151977 fts3SnippetAdvance(&pPhrase->pHead, &pPhrase->iHead, pIter->nSnippet);
151983 for(i=0; i<pIter->nPhrase; i++){
151984 SnippetPhrase *pPhrase = &pIter->aPhrase[i];
151993 pIter->iCurrent = iStart = iEnd - pIter->nSnippet + 1;
151994 for(i=0; i<pIter->nPhrase; i++){
151995 SnippetPhrase *pPhrase = &pIter->aPhrase[i];
152006 ** iterator pIter.
152009 SnippetIter *pIter, /* Snippet iterator */
152016 int iStart = pIter->iCurrent; /* First token of snippet */
152022 for(i=0; i<pIter->nPhrase; i++){
152023 SnippetPhrase *pPhrase = &pIter->aPhrase[i];
152028 while( iCsr<(iStart+pIter->nSnippet) ){
152458 char *pIter = pPhrase->doclist.pList;
152469 int nHit = fts3ColumnlistCount(&pIter);
152477 assert( *pIter==0x00 || *pIter==0x01 );
152478 if( *pIter!=0x01 ) break;
152479 pIter++;
152480 pIter += fts3GetVarint32(pIter, &iCol);
152683 static int fts3LcsIteratorAdvance(LcsIterator *pIter){
152684 char *pRead = pIter->pRead;
152693 pIter->iPos += (int)(iRead-2);
152696 pIter->pRead = pRead;
152726 LcsIterator *pIter = &aIter[i];
152727 nToken -= pIter->pExpr->pPhrase->nToken;
152728 pIter->iPosOffset = nToken;
152752 LcsIterator *pIter = &aIter[i];
152753 if( pIter->pRead==0 ){
152757 if( pAdv==0 || pIter->iPos<pAdv->iPos ){
152758 pAdv = pIter;
152760 if( nThisLcs==0 || pIter->iPos==pIter[-1].iPos ){
158129 UBreakIterator *pIter; /* ICU break-iterator object */
158242 pCsr->pIter = ubrk_open(UBRK_WORD, p->zLocale, pCsr->aChar, iOut, &status);
158249 ubrk_first(pCsr->pIter);
158259 ubrk_close(pCsr->pIter);
158285 iStart = ubrk_current(pCsr->pIter);
158286 iEnd = ubrk_next(pCsr->pIter);
159505 static void rbuObjIterFreeCols(RbuObjIter *pIter){
159507 for(i=0; i<pIter->nTblCol; i++){
159508 sqlite3_free(pIter->azTblCol[i]);
159509 sqlite3_free(pIter->azTblType[i]);
159511 sqlite3_free(pIter->azTblCol);
159512 pIter->azTblCol = 0;
159513 pIter->azTblType = 0;
159514 pIter->aiSrcOrder = 0;
159515 pIter->abTblPk = 0;
159516 pIter->abNotNull = 0;
159517 pIter->nTblCol = 0;
159518 pIter->eType = 0; /* Invalid value */
159525 static void rbuObjIterClearStatements(RbuObjIter *pIter){
159528 sqlite3_finalize(pIter->pSelect);
159529 sqlite3_finalize(pIter->pInsert);
159530 sqlite3_finalize(pIter->pDelete);
159531 sqlite3_finalize(pIter->pTmpInsert);
159532 pUp = pIter->pRbuUpdate;
159540 pIter->pSelect = 0;
159541 pIter->pInsert = 0;
159542 pIter->pDelete = 0;
159543 pIter->pRbuUpdate = 0;
159544 pIter->pTmpInsert = 0;
159545 pIter->nCol = 0;
159552 static void rbuObjIterFinalize(RbuObjIter *pIter){
159553 rbuObjIterClearStatements(pIter);
159554 sqlite3_finalize(pIter->pTblIter);
159555 sqlite3_finalize(pIter->pIdxIter);
159556 rbuObjIterFreeCols(pIter);
159557 memset(pIter, 0, sizeof(RbuObjIter));
159568 static int rbuObjIterNext(sqlite3rbu *p, RbuObjIter *pIter){
159573 rbuObjIterClearStatements(pIter);
159574 if( pIter->zIdx==0 ){
159585 if( pIter->bCleanup ){
159586 rbuObjIterFreeCols(pIter);
159587 pIter->bCleanup = 0;
159588 rc = sqlite3_step(pIter->pTblIter);
159590 rc = resetAndCollectError(pIter->pTblIter, &p->zErrmsg);
159591 pIter->zTbl = 0;
159593 pIter->zTbl = (const char*)sqlite3_column_text(pIter->pTblIter, 0);
159594 pIter->zDataTbl = (const char*)sqlite3_column_text(pIter->pTblIter,1);
159595 rc = (pIter->zDataTbl && pIter->zTbl) ? SQLITE_OK : SQLITE_NOMEM;
159598 if( pIter->zIdx==0 ){
159599 sqlite3_stmt *pIdx = pIter->pIdxIter;
159600 rc = sqlite3_bind_text(pIdx, 1, pIter->zTbl, -1, SQLITE_STATIC);
159603 rc = sqlite3_step(pIter->pIdxIter);
159605 rc = resetAndCollectError(pIter->pIdxIter, &p->zErrmsg);
159606 pIter->bCleanup = 1;
159607 pIter->zIdx = 0;
159609 pIter->zIdx = (const char*)sqlite3_column_text(pIter->pIdxIter, 0);
159610 pIter->iTnum = sqlite3_column_int(pIter->pIdxIter, 1);
159611 pIter->bUnique = sqlite3_column_int(pIter->pIdxIter, 2);
159612 rc = pIter->zIdx ? SQLITE_OK : SQLITE_NOMEM;
159620 rbuObjIterFinalize(pIter);
159668 static int rbuObjIterFirst(sqlite3rbu *p, RbuObjIter *pIter){
159670 memset(pIter, 0, sizeof(RbuObjIter));
159672 rc = prepareAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg,
159679 rc = prepareAndCollectError(p->dbMain, &pIter->pIdxIter, &p->zErrmsg,
159686 pIter->bCleanup = 1;
159688 return rbuObjIterNext(p, pIter);
159768 ** Allocate and zero the pIter->azTblCol[] and abTblPk[] arrays so that
159772 static void rbuAllocateIterArrays(sqlite3rbu *p, RbuObjIter *pIter, int nCol){
159778 pIter->azTblCol = azNew;
159779 pIter->azTblType = &azNew[nCol];
159780 pIter->aiSrcOrder = (int*)&pIter->azTblType[nCol];
159781 pIter->abTblPk = (u8*)&pIter->aiSrcOrder[nCol];
159782 pIter->abNotNull = (u8*)&pIter->abTblPk[nCol];
159783 pIter->abIndexed = (u8*)&pIter->abNotNull[nCol];
159951 ** the pIter->abIndexed[] array.
159953 static void rbuObjIterCacheIndexedCols(sqlite3rbu *p, RbuObjIter *pIter){
159958 memcpy(pIter->abIndexed, pIter->abTblPk, sizeof(u8)*pIter->nTblCol);
159960 sqlite3_mprintf("PRAGMA main.index_list = %Q", pIter->zTbl)
159973 if( iCid>=0 ) pIter->abIndexed[iCid] = 1;
159980 if( bIndex==0 ) pIter->abIndexed = 0;
159985 ** If they are not already populated, populate the pIter->azTblCol[],
159986 ** pIter->abTblPk[], pIter->nTblCol and pIter->bRowid variables according to
159993 static int rbuObjIterCacheTableInfo(sqlite3rbu *p, RbuObjIter *pIter){
159994 if( pIter->azTblCol==0 ){
160003 assert( pIter->eType==0 );
160004 rbuTableType(p, pIter->zTbl, &pIter->eType, &iTnum, &pIter->iPkTnum);
160005 if( p->rc==SQLITE_OK && pIter->eType==RBU_PK_NOTABLE ){
160007 p->zErrmsg = sqlite3_mprintf("no such table: %s", pIter->zTbl);
160010 if( pIter->zIdx==0 ) pIter->iTnum = iTnum;
160012 assert( pIter->eType==RBU_PK_NONE || pIter->eType==RBU_PK_IPK
160013 || pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_WITHOUT_ROWID
160014 || pIter->eType==RBU_PK_VTAB
160021 sqlite3_mprintf("SELECT * FROM '%q'", pIter->zDataTbl)
160025 rbuAllocateIterArrays(p, pIter, nCol);
160031 pIter->aiSrcOrder[pIter->nTblCol] = pIter->nTblCol;
160032 pIter->azTblCol[pIter->nTblCol++] = zCopy;
160042 && bRbuRowid!=(pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
160046 "table %q %s rbu_rowid column", pIter->zDataTbl,
160056 sqlite3_mprintf("PRAGMA table_info(%Q)", pIter->zTbl)
160062 for(i=iOrder; i<pIter->nTblCol; i++){
160063 if( 0==strcmp(zName, pIter->azTblCol[i]) ) break;
160065 if( i==pIter->nTblCol ){
160068 pIter->zDataTbl, zName
160076 SWAP(int, pIter->aiSrcOrder[i], pIter->aiSrcOrder[iOrder]);
160077 SWAP(char*, pIter->azTblCol[i], pIter->azTblCol[iOrder]);
160080 pIter->azTblType[iOrder] = rbuStrndup(zType, &p->rc);
160081 pIter->abTblPk[iOrder] = (iPk!=0);
160082 pIter->abNotNull[iOrder] = (u8)bNotNull || (iPk!=0);
160088 rbuObjIterCacheIndexedCols(p, pIter);
160089 assert( pIter->eType!=RBU_PK_VTAB || pIter->abIndexed==0 );
160098 ** column names currently stored in the pIter->azTblCol[] array.
160102 RbuObjIter *pIter /* Object iterator for column names */
160107 for(i=0; i<pIter->nTblCol; i++){
160108 const char *z = pIter->azTblCol[i];
160141 RbuObjIter *pIter, /* Object iterator for column names */
160161 sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", pIter->zIdx)
160175 if( pIter->eType==RBU_PK_IPK ){
160177 for(i=0; pIter->abTblPk[i]==0; i++);
160178 assert( i<pIter->nTblCol );
160179 zCol = pIter->azTblCol[i];
160185 zCol = pIter->azTblCol[iCid];
160186 zType = pIter->azTblType[iCid];
160190 if( pIter->bUnique==0 || sqlite3_column_int(pXInfo, 5) ){
160243 RbuObjIter *pIter,
160247 if( p->rc==SQLITE_OK && pIter->abIndexed ){
160250 for(i=0; i<pIter->nTblCol; i++){
160251 if( pIter->abIndexed[i] ){
160252 const char *zCol = pIter->azTblCol[i];
160265 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
160284 pIter
160287 if( pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE ){
160288 zList = rbuMPrintf(p, "_rowid_ = ?%d", pIter->nTblCol+1);
160289 }else if( pIter->eType==RBU_PK_EXTERNAL ){
160292 for(i=0; i<pIter->nTblCol; i++){
160293 if( pIter->abTblPk[i] ){
160305 for(i=0; i<pIter->nTblCol; i++){
160306 if( pIter->abTblPk[i] ){
160307 const char *zCol = pIter->azTblCol[i];
160348 RbuObjIter *pIter,
160355 if( (int)strlen(zMask)!=pIter->nTblCol ){
160359 for(i=0; i<pIter->nTblCol; i++){
160360 char c = zMask[pIter->aiSrcOrder[i]];
160363 zList, zSep, pIter->azTblCol[i], i+1
160369 zList, zSep, pIter->azTblCol[i], pIter->azTblCol[i], i+1
160375 zList, zSep, pIter->azTblCol[i], pIter->azTblCol[i], i+1
160427 static char *rbuWithoutRowidPK(sqlite3rbu *p, RbuObjIter *pIter){
160429 assert( pIter->zIdx==0 );
160432 sqlite3_stmt *pXList = 0; /* PRAGMA index_list = (pIter->zTbl) */
160436 sqlite3_mprintf("PRAGMA main.index_list = %Q", pIter->zTbl)
160486 static void rbuCreateImposterTable2(sqlite3rbu *p, RbuObjIter *pIter){
160487 if( p->rc==SQLITE_OK && pIter->eType==RBU_PK_EXTERNAL ){
160488 int tnum = pIter->iPkTnum; /* Root page of PK index */
160522 iCid, pIter->azTblType[iCid], zCollate
160560 static void rbuCreateImposterTable(sqlite3rbu *p, RbuObjIter *pIter){
160561 if( p->rc==SQLITE_OK && pIter->eType!=RBU_PK_VTAB ){
160562 int tnum = pIter->iTnum;
160568 for(iCol=0; p->rc==SQLITE_OK && iCol<pIter->nTblCol; iCol++){
160570 const char *zCol = pIter->azTblCol[iCol];
160574 p->dbMain, "main", pIter->zTbl, zCol, 0, &zColl, 0, 0, 0
160577 if( pIter->eType==RBU_PK_IPK && pIter->abTblPk[iCol] ){
160583 zSql, zComma, zCol, pIter->azTblType[iCol], zPk, zColl,
160584 (pIter->abNotNull[iCol] ? " NOT NULL" : "")
160589 if( pIter->eType==RBU_PK_WITHOUT_ROWID ){
160590 char *zPk = rbuWithoutRowidPK(p, pIter);
160598 pIter->zTbl, zSql,
160599 (pIter->eType==RBU_PK_WITHOUT_ROWID ? " WITHOUT ROWID" : "")
160618 RbuObjIter *pIter,
160622 int bRbuRowid = (pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE);
160623 char *zBind = rbuObjIterGetBindlist(p, pIter->nTblCol + 1 + bRbuRowid);
160625 assert( pIter->pTmpInsert==0 );
160627 p->dbRbu, &pIter->pTmpInsert, &p->zErrmsg, sqlite3_mprintf(
160629 p->zStateDb, pIter->zDataTbl, zCollist, zRbuRowid, zBind
160663 RbuObjIter *pIter,
160666 assert( pIter->bCleanup==0 );
160667 if( pIter->pSelect==0 && rbuObjIterCacheTableInfo(p, pIter)==SQLITE_OK ){
160668 const int tnum = pIter->iTnum;
160671 const char *zIdx = pIter->zIdx;
160680 const char *zTbl = pIter->zTbl;
160687 assert( pIter->eType!=RBU_PK_VTAB );
160689 p, pIter, &zImposterCols, &zImposterPK, &zWhere, &nBind
160703 pIter->nCol = nBind;
160706 p->dbMain, &pIter->pInsert, &p->zErrmsg,
160714 p->dbMain, &pIter->pDelete, &p->zErrmsg,
160722 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
160725 zCollist, p->zStateDb, pIter->zDataTbl,
160735 zCollist, pIter->zDataTbl,
160736 zCollist, p->zStateDb, pIter->zDataTbl,
160740 p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, zSql);
160748 int bRbuRowid = (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE);
160749 const char *zTbl = pIter->zTbl; /* Table this step applies to */
160752 char *zBindings = rbuObjIterGetBindlist(p, pIter->nTblCol + bRbuRowid);
160753 char *zWhere = rbuObjIterGetWhere(p, pIter);
160754 char *zOldlist = rbuObjIterGetOldlist(p, pIter, "old");
160755 char *zNewlist = rbuObjIterGetOldlist(p, pIter, "new");
160757 zCollist = rbuObjIterGetCollist(p, pIter);
160758 pIter->nCol = pIter->nTblCol;
160761 rbuCreateImposterTable(p, pIter);
160762 rbuCreateImposterTable2(p, pIter);
160763 zWrite = (pIter->eType==RBU_PK_VTAB ? "" : "rbu_imp_");
160767 p->rc = prepareFreeAndCollectError(p->dbMain, &pIter->pInsert, pz,
160777 p->rc = prepareFreeAndCollectError(p->dbMain, &pIter->pDelete, pz,
160784 if( pIter->abIndexed ){
160786 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
160794 , p->zStateDb, pIter->zDataTbl
160795 , (pIter->eType==RBU_PK_EXTERNAL ? ", 0 AS rbu_rowid" : "")
160796 , pIter->zDataTbl
160819 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
160829 rbuObjIterPrepareTmpInsert(p, pIter, zCollist, zRbuRowid);
160834 p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz,
160838 pIter->zDataTbl, zLimit
160858 ** table object that pIter currently points to, assuming that the
160866 RbuObjIter *pIter, /* Object iterator */
160881 for(pp=&pIter->pRbuUpdate; *pp; pp=&((*pp)->pNext)){
160885 pUp->pNext = pIter->pRbuUpdate;
160886 pIter->pRbuUpdate = pUp;
160895 for(pp=&pIter->pRbuUpdate; *pp!=pUp; pp=&((*pp)->pNext));
160900 pUp = (RbuUpdateStmt*)rbuMalloc(p, sizeof(RbuUpdateStmt)+pIter->nTblCol+1);
160904 char *zWhere = rbuObjIterGetWhere(p, pIter);
160905 char *zSet = rbuObjIterGetSetlist(p, pIter, zMask);
160909 memcpy(pUp->zMask, zMask, pIter->nTblCol);
160910 pUp->pNext = pIter->pRbuUpdate;
160911 pIter->pRbuUpdate = pUp;
160916 if( pIter->eType!=RBU_PK_VTAB ) zPrefix = "rbu_imp_";
160918 zPrefix, pIter->zTbl, zSet, zWhere
161388 RbuObjIter *pIter = &p->objiter;
161394 assert( eType!=RBU_UPDATE || pIter->zIdx==0 );
161396 if( pIter->zIdx==0 && eType==RBU_IDX_DELETE ){
161409 assert( eType!=RBU_DELETE || pIter->zIdx==0 );
161412 pWriter = pIter->pDelete;
161414 pWriter = pIter->pInsert;
161417 for(i=0; i<pIter->nCol; i++){
161422 && pIter->zIdx==0 && pIter->eType==RBU_PK_IPK && pIter->abTblPk[i]
161423 && sqlite3_column_type(pIter->pSelect, i)==SQLITE_NULL
161430 if( eType==RBU_DELETE && pIter->abTblPk[i]==0 ){
161434 pVal = sqlite3_column_value(pIter->pSelect, i);
161438 if( pIter->zIdx==0
161439 && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
161446 ** Hence column_value(pIter->nCol+1).
161448 assertColumnName(pIter->pSelect, pIter->nCol+1, "rbu_rowid");
161449 pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
161450 p->rc = sqlite3_bind_value(pWriter, pIter->nCol+1, pVal);
161460 rbuGetUpdateStmt(p, pIter, zMask, &pUpdate);
161462 for(i=0; p->rc==SQLITE_OK && i<pIter->nCol; i++){
161463 char c = zMask[pIter->aiSrcOrder[i]];
161464 pVal = sqlite3_column_value(pIter->pSelect, i);
161465 if( pIter->abTblPk[i] || c!='.' ){
161470 && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
161473 assertColumnName(pIter->pSelect, pIter->nCol+1, "rbu_rowid");
161474 pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
161475 p->rc = sqlite3_bind_value(pUpdate, pIter->nCol+1, pVal);
161568 RbuObjIter *pIter = &p->objiter;
161569 while( p->rc==SQLITE_OK && pIter->zTbl ){
161571 if( pIter->bCleanup ){
161575 if( pIter->abIndexed ){
161577 "DELETE FROM %s.'rbu_tmp_%q'", p->zStateDb, pIter->zDataTbl
161581 rbuObjIterPrepareAll(p, pIter, 0);
161585 int rc = sqlite3_step(pIter->pSelect);
161591 p->rc = sqlite3_reset(pIter->pSelect);
161596 rbuObjIterNext(p, pIter);
161600 assert( pIter->zTbl==0 );
161770 RbuObjIter *pIter = &p->objiter;
161773 while( rc==SQLITE_OK && pIter->zTbl && (pIter->bCleanup
161774 || rbuStrCompare(pIter->zIdx, pState->zIdx)
161775 || rbuStrCompare(pIter->zTbl, pState->zTbl)
161777 rc = rbuObjIterNext(p, pIter);
161780 if( rc==SQLITE_OK && !pIter->zTbl ){
166439 pIter /* Iterator object to initialize */
166490 ** sqlite3Fts5IndexQuery(p, "token", 5, 0, 0, &pIter);
166491 ** 0==sqlite3Fts5IterEof(pIter);
166492 ** sqlite3Fts5IterNext(pIter)
166494 ** i64 iRowid = sqlite3Fts5IterRowid(pIter);
166519 static int sqlite3Fts5IterPoslistBuffer(Fts5IndexIter *pIter, Fts5Buffer *pBuf);
168117 static int fts5CInstIterNext(CInstIter *pIter){
168119 pIter->iStart = -1;
168120 pIter->iEnd = -1;
168122 while( rc==SQLITE_OK && pIter->iInst<pIter->nInst ){
168124 rc = pIter->pApi->xInst(pIter->pFts, pIter->iInst, &ip, &ic, &io);
168126 if( ic==pIter->iCol ){
168127 int iEnd = io - 1 + pIter->pApi->xPhraseSize(pIter->pFts, ip);
168128 if( pIter->iStart<0 ){
168129 pIter->iStart = io;
168130 pIter->iEnd = iEnd;
168131 }else if( io<=pIter->iEnd ){
168132 if( iEnd>pIter->iEnd ) pIter->iEnd = iEnd;
168137 pIter->iInst++;
168152 CInstIter *pIter
168156 memset(pIter, 0, sizeof(CInstIter));
168157 pIter->pApi = pApi;
168158 pIter->pFts = pFts;
168159 pIter->iCol = iCol;
168160 rc = pApi->xInstCount(pFts, &pIter->nInst);
168163 rc = fts5CInstIterNext(pIter);
168827 static int sqlite3Fts5PoslistReaderNext(Fts5PoslistReader *pIter){
168828 if( sqlite3Fts5PoslistNext64(pIter->a, pIter->n, &pIter->i, &pIter->iPos) ){
168829 pIter->bEof = 1;
168831 return pIter->bEof;
168836 Fts5PoslistReader *pIter /* Iterator object to initialize */
168838 memset(pIter, 0, sizeof(*pIter));
168839 pIter->a = a;
168840 pIter->n = n;
168841 sqlite3Fts5PoslistReaderNext(pIter);
168842 return pIter->bEof;
169877 Fts5IndexIter *pIter; /* Iterator for this term */
170081 if( 0==sqlite3Fts5IterEof(p->pIter) ){
170082 i64 iRowid = sqlite3Fts5IterRowid(p->pIter);
170113 Fts5IndexIter *pIter = p->pIter;
170114 if( sqlite3Fts5IterEof(pIter)==0 && sqlite3Fts5IterRowid(pIter)==iRowid ){
170118 rc = sqlite3Fts5IterPoslist(pIter, pColset, &a, &n, &dummy);
170224 rc = sqlite3Fts5IterPoslist(pTerm->pIter, pColset, &a, &n, &dummy);
170444 if( sqlite3Fts5IterEof(p->pIter)==0 ){
170445 i64 ii = sqlite3Fts5IterRowid(p->pIter);
170450 rc = sqlite3Fts5IterNextFrom(p->pIter, iFrom);
170452 rc = sqlite3Fts5IterNext(p->pIter);
170455 if( sqlite3Fts5IterEof(p->pIter)==0 ){
170468 Fts5IndexIter *pIter = pTerm->pIter;
170472 rc = sqlite3Fts5IterNextFrom(pIter, iFrom);
170474 rc = sqlite3Fts5IterNext(pIter);
170477 pNode->bEof = (rc || sqlite3Fts5IterEof(pIter));
170484 ** Advance iterator pIter until it points to a value equal to or laster
170493 Fts5IndexIter *pIter, /* Iterator to advance */
170502 iRowid = sqlite3Fts5IterRowid(pIter);
170504 int rc = sqlite3Fts5IterNextFrom(pIter, iLast);
170505 if( rc || sqlite3Fts5IterEof(pIter) ){
170510 iRowid = sqlite3Fts5IterRowid(pIter);
170530 if( sqlite3Fts5IterEof(p->pIter)==0 ){
170531 i64 iRowid = sqlite3Fts5IterRowid(p->pIter);
170533 rc = sqlite3Fts5IterNextFrom(p->pIter, iLast);
170568 pPhrase->aTerm[0].pIter, &pPhrase->poslist
170592 Fts5IndexIter *pIter = pPhrase->aTerm[0].pIter;
170600 rc = sqlite3Fts5IterPoslist(pIter, pColset,
170643 iLast = sqlite3Fts5IterRowid(pLeft->aTerm[0].pIter);
170661 Fts5IndexIter *pIter = pPhrase->aTerm[j].pIter;
170662 i64 iRowid = sqlite3Fts5IterRowid(pIter);
170665 if( fts5ExprAdvanceto(pIter, bDesc, &iLast, &rc, &pNode->bEof) ){
170700 if( p->pIter ){
170701 sqlite3Fts5IterClose(p->pIter);
170702 p->pIter = 0;
170709 &p->pIter
170711 assert( rc==SQLITE_OK || p->pIter==0 );
170712 if( p->pIter && 0==sqlite3Fts5IterEof(p->pIter) ){
170885 Fts5IndexIter *pIter = pNode->pNear->apPhrase[0]->aTerm[0].pIter;
170887 rc = sqlite3Fts5IterNextFrom(pIter, iFrom);
170889 rc = sqlite3Fts5IterNext(pIter);
170891 if( rc==SQLITE_OK && sqlite3Fts5IterEof(pIter)==0 ){
171133 sqlite3Fts5IterClose(pTerm->pIter);
171137 sqlite3Fts5IterClose(pSyn->pIter);
172415 Fts5HashEntry *pIter;
172416 for(pIter=pHash->aSlot[iSlot]; pIter; pIter=pIter->pHashNext){
172417 if( pTerm==0 || 0==memcmp(pIter->zKey, pTerm, nTerm) ){
172418 Fts5HashEntry *pEntry = pIter;
173707 static int fts5DlidxIterNextR(Fts5Index *p, Fts5DlidxIter *pIter, int iLvl){
173708 Fts5DlidxLvl *pLvl = &pIter->aLvl[iLvl];
173710 assert( iLvl<pIter->nLvl );
173712 if( (iLvl+1) < pIter->nLvl ){
173713 fts5DlidxIterNextR(p, pIter, iLvl+1);
173718 FTS5_DLIDX_ROWID(pIter->iSegid, iLvl, pLvl[1].iLeafPgno)
173725 return pIter->aLvl[0].bEof;
173727 static int fts5DlidxIterNext(Fts5Index *p, Fts5DlidxIter *pIter){
173728 return fts5DlidxIterNextR(p, pIter, 0);
173739 ** When this function is called pIter->iLeafPgno is the page number the
173742 static int fts5DlidxIterFirst(Fts5DlidxIter *pIter){
173744 for(i=0; i<pIter->nLvl; i++){
173745 fts5DlidxLvlNext(&pIter->aLvl[i]);
173747 return pIter->aLvl[0].bEof;
173751 static int fts5DlidxIterEof(Fts5Index *p, Fts5DlidxIter *pIter){
173752 return p->rc!=SQLITE_OK || pIter->aLvl[0].bEof;
173755 static void fts5DlidxIterLast(Fts5Index *p, Fts5DlidxIter *pIter){
173759 for(i=pIter->nLvl-1; p->rc==SQLITE_OK && i>=0; i--){
173760 Fts5DlidxLvl *pLvl = &pIter->aLvl[i];
173769 FTS5_DLIDX_ROWID(pIter->iSegid, i-1, pLvl->iLeafPgno)
173827 static int fts5DlidxIterPrevR(Fts5Index *p, Fts5DlidxIter *pIter, int iLvl){
173828 Fts5DlidxLvl *pLvl = &pIter->aLvl[iLvl];
173830 assert( iLvl<pIter->nLvl );
173832 if( (iLvl+1) < pIter->nLvl ){
173833 fts5DlidxIterPrevR(p, pIter, iLvl+1);
173838 FTS5_DLIDX_ROWID(pIter->iSegid, iLvl, pLvl[1].iLeafPgno)
173848 return pIter->aLvl[0].bEof;
173850 static int fts5DlidxIterPrev(Fts5Index *p, Fts5DlidxIter *pIter){
173851 return fts5DlidxIterPrevR(p, pIter, 0);
173857 static void fts5DlidxIterFree(Fts5DlidxIter *pIter){
173858 if( pIter ){
173860 for(i=0; i<pIter->nLvl; i++){
173861 fts5DataRelease(pIter->aLvl[i].pData);
173863 sqlite3_free(pIter);
173873 Fts5DlidxIter *pIter = 0;
173881 pNew = (Fts5DlidxIter*)sqlite3_realloc(pIter, nByte);
173887 pIter = pNew;
173893 pIter->nLvl = i+1;
173898 pIter->iSegid = iSegid;
173900 fts5DlidxIterFirst(pIter);
173902 fts5DlidxIterLast(p, pIter);
173907 fts5DlidxIterFree(pIter);
173908 pIter = 0;
173911 return pIter;
173914 static i64 fts5DlidxIterRowid(Fts5DlidxIter *pIter){
173915 return pIter->aLvl[0].iRowid;
173917 static int fts5DlidxIterPgno(Fts5DlidxIter *pIter){
173918 return pIter->aLvl[0].iLeafPgno;
173926 Fts5SegIter *pIter /* Iterator to advance to next page */
173929 Fts5StructureSegment *pSeg = pIter->pSeg;
173930 fts5DataRelease(pIter->pLeaf);
173931 pIter->iLeafPgno++;
173932 if( pIter->pNextLeaf ){
173933 pIter->pLeaf = pIter->pNextLeaf;
173934 pIter->pNextLeaf = 0;
173935 }else if( pIter->iLeafPgno<=pSeg->pgnoLast ){
173936 pIter->pLeaf = fts5DataRead(p,
173937 FTS5_SEGMENT_ROWID(pSeg->iSegid, pIter->iLeafPgno)
173940 pIter->pLeaf = 0;
173942 pLeaf = pIter->pLeaf;
173945 pIter->iPgidxOff = pLeaf->szLeaf;
173947 pIter->iEndofDoclist = pLeaf->nn+1;
173949 pIter->iPgidxOff += fts5GetVarint32(&pLeaf->p[pIter->iPgidxOff],
173950 pIter->iEndofDoclist
173983 static void fts5SegIterLoadNPos(Fts5Index *p, Fts5SegIter *pIter){
173985 int iOff = pIter->iLeafOffset; /* Offset to read at */
173987 ASSERT_SZLEAF_OK(pIter->pLeaf);
173988 fts5FastGetVarint32(pIter->pLeaf->p, iOff, nSz);
173989 pIter->bDel = (nSz & 0x0001);
173990 pIter->nPos = nSz>>1;
173991 pIter->iLeafOffset = iOff;
173995 static void fts5SegIterLoadRowid(Fts5Index *p, Fts5SegIter *pIter){
173996 u8 *a = pIter->pLeaf->p; /* Buffer to read data from */
173997 int iOff = pIter->iLeafOffset;
173999 ASSERT_SZLEAF_OK(pIter->pLeaf);
174000 if( iOff>=pIter->pLeaf->szLeaf ){
174001 fts5SegIterNextPage(p, pIter);
174002 if( pIter->pLeaf==0 ){
174007 a = pIter->pLeaf->p;
174009 iOff += sqlite3Fts5GetVarint(&a[iOff], (u64*)&pIter->iRowid);
174010 pIter->iLeafOffset = iOff;
174028 static void fts5SegIterLoadTerm(Fts5Index *p, Fts5SegIter *pIter, int nKeep){
174029 u8 *a = pIter->pLeaf->p; /* Buffer to read data from */
174030 int iOff = pIter->iLeafOffset; /* Offset to read at */
174034 pIter->term.n = nKeep;
174035 fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
174037 pIter->iTermLeafOffset = iOff;
174038 pIter->iTermLeafPgno = pIter->iLeafPgno;
174039 pIter->iLeafOffset = iOff;
174041 if( pIter->iPgidxOff>=pIter->pLeaf->nn ){
174042 pIter->iEndofDoclist = pIter->pLeaf->nn+1;
174045 pIter->iPgidxOff += fts5GetVarint32(&a[pIter->iPgidxOff], nExtra);
174046 pIter->iEndofDoclist += nExtra;
174049 fts5SegIterLoadRowid(p, pIter);
174053 ** Initialize the iterator object pIter to iterate through the entries in
174063 Fts5SegIter *pIter /* Object to populate */
174069 ** The caller will see the (pIter->pLeaf==0) and assume the iterator is
174071 assert( pIter->pLeaf==0 );
174076 memset(pIter, 0, sizeof(*pIter));
174077 pIter->pSeg = pSeg;
174078 pIter->iLeafPgno = pSeg->pgnoFirst-1;
174079 fts5SegIterNextPage(p, pIter);
174083 pIter->iLeafOffset = 4;
174084 assert_nc( pIter->pLeaf->nn>4 );
174085 assert( fts5LeafFirstTermOff(pIter->pLeaf)==4 );
174086 pIter->iPgidxOff = pIter->pLeaf->szLeaf+1;
174087 fts5SegIterLoadTerm(p, pIter, 0);
174088 fts5SegIterLoadNPos(p, pIter);
174107 static void fts5SegIterReverseInitPage(Fts5Index *p, Fts5SegIter *pIter){
174108 int n = pIter->pLeaf->szLeaf;
174109 int i = pIter->iLeafOffset;
174110 u8 *a = pIter->pLeaf->p;
174113 if( n>pIter->iEndofDoclist ){
174114 n = pIter->iEndofDoclist;
174117 ASSERT_SZLEAF_OK(pIter->pLeaf);
174127 pIter->iRowid += iDelta;
174129 if( iRowidOffset>=pIter->nRowidOffset ){
174130 int nNew = pIter->nRowidOffset + 8;
174131 int *aNew = (int*)sqlite3_realloc(pIter->aRowidOffset, nNew*sizeof(int));
174136 pIter->aRowidOffset = aNew;
174137 pIter->nRowidOffset = nNew;
174140 pIter->aRowidOffset[iRowidOffset++] = pIter->iLeafOffset;
174141 pIter->iLeafOffset = i;
174143 pIter->iRowidOffset = iRowidOffset;
174144 fts5SegIterLoadNPos(p, pIter);
174150 static void fts5SegIterReverseNewPage(Fts5Index *p, Fts5SegIter *pIter){
174151 assert( pIter->flags & FTS5_SEGITER_REVERSE );
174152 assert( pIter->flags & FTS5_SEGITER_ONETERM );
174154 fts5DataRelease(pIter->pLeaf);
174155 pIter->pLeaf = 0;
174156 while( p->rc==SQLITE_OK && pIter->iLeafPgno>pIter->iTermLeafPgno ){
174158 pIter->iLeafPgno--;
174160 pIter->pSeg->iSegid, pIter->iLeafPgno
174165 ** In this case leaf pIter->pLeaf==0, this iterator is at EOF. */
174166 if( pIter->iLeafPgno==pIter->iTermLeafPgno
174167 && pIter->iTermLeafOffset<pNew->szLeaf
174169 pIter->pLeaf = pNew;
174170 pIter->iLeafOffset = pIter->iTermLeafOffset;
174175 pIter->pLeaf = pNew;
174176 pIter->iLeafOffset = iRowidOff;
174180 if( pIter->pLeaf ){
174181 u8 *a = &pIter->pLeaf->p[pIter->iLeafOffset];
174182 pIter->iLeafOffset += fts5GetVarint(a, (u64*)&pIter->iRowid);
174190 if( pIter->pLeaf ){
174191 pIter->iEndofDoclist = pIter->pLeaf->nn+1;
174192 fts5SegIterReverseInitPage(p, pIter);
174201 static int fts5MultiIterIsEmpty(Fts5Index *p, Fts5IndexIter *pIter){
174202 Fts5SegIter *pSeg = &pIter->aSeg[pIter->aFirst[1].iFirst];
174207 ** Advance iterator pIter to the next entry.
174215 Fts5SegIter *pIter, /* Iterator to advance */
174220 if( pIter->flags & FTS5_SEGITER_REVERSE ){
174221 assert( pIter->pNextLeaf==0 );
174222 if( pIter->iRowidOffset>0 ){
174223 u8 *a = pIter->pLeaf->p;
174229 pIter->iRowidOffset--;
174230 pIter->iLeafOffset = iOff = pIter->aRowidOffset[pIter->iRowidOffset];
174234 pIter->iRowid -= iDelta;
174235 fts5SegIterLoadNPos(p, pIter);
174237 fts5SegIterReverseNewPage(p, pIter);
174240 Fts5Data *pLeaf = pIter->pLeaf;
174250 iOff = pIter->iLeafOffset + pIter->nPos;
174254 assert_nc( iOff<=pIter->iEndofDoclist );
174255 if( iOff>=pIter->iEndofDoclist ){
174263 pIter->iRowid += iDelta;
174266 pIter->iLeafOffset = iOff;
174268 }else if( pIter->pSeg==0 ){
174272 if( 0==(pIter->flags & FTS5_SEGITER_ONETERM) ){
174277 fts5DataRelease(pIter->pLeaf);
174278 pIter->pLeaf = 0;
174280 pIter->pLeaf->p = (u8*)pList;
174281 pIter->pLeaf->nn = nList;
174282 pIter->pLeaf->szLeaf = nList;
174283 pIter->iEndofDoclist = nList+1;
174284 sqlite3Fts5BufferSet(&p->rc, &pIter->term, strlen(zTerm), (u8*)zTerm);
174285 pIter->iLeafOffset = fts5GetVarint(pList, (u64*)&pIter->iRowid);
174292 fts5SegIterNextPage(p, pIter);
174293 pLeaf = pIter->pLeaf;
174297 iOff += sqlite3Fts5GetVarint(&pLeaf->p[iOff], (u64*)&pIter->iRowid);
174298 pIter->iLeafOffset = iOff;
174301 pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
174302 pIter->iEndofDoclist
174308 pIter->iPgidxOff = pLeaf->szLeaf + fts5GetVarint32(
174311 pIter->iLeafOffset = iOff;
174312 pIter->iEndofDoclist = iOff;
174323 if( pIter->pLeaf ){
174325 if( pIter->flags & FTS5_SEGITER_ONETERM ){
174326 fts5DataRelease(pIter->pLeaf);
174327 pIter->pLeaf = 0;
174329 fts5SegIterLoadTerm(p, pIter, nKeep);
174330 fts5SegIterLoadNPos(p, pIter);
174334 fts5SegIterLoadNPos(p, pIter);
174344 ** Iterator pIter currently points to the first rowid in a doclist. This
174348 static void fts5SegIterReverse(Fts5Index *p, Fts5SegIter *pIter){
174349 Fts5DlidxIter *pDlidx = pIter->pDlidx;
174354 int iSegid = pIter->pSeg->iSegid;
174358 Fts5Data *pLeaf = pIter->pLeaf; /* Current leaf data */
174363 pIter->iLeafOffset -= sqlite3Fts5GetVarintLen(pIter->nPos*2+pIter->bDel);
174368 if( pIter->iEndofDoclist>=pLeaf->szLeaf ){
174370 Fts5StructureSegment *pSeg = pIter->pSeg;
174374 for(pgno=pIter->iLeafPgno+1; !p->rc && pgno<=pSeg->pgnoLast; pgno++){
174394 ** pIter->iLeafOffset is already set to point to the position-list size
174403 fts5DataRelease(pIter->pLeaf);
174404 pIter->pLeaf = pLast;
174405 pIter->iLeafPgno = pgnoLast;
174407 iOff += fts5GetVarint(&pLast->p[iOff], (u64*)&pIter->iRowid);
174408 pIter->iLeafOffset = iOff;
174411 pIter->iEndofDoclist = pLast->nn+1;
174413 pIter->iEndofDoclist = fts5LeafFirstTermOff(pLast);
174418 fts5SegIterReverseInitPage(p, pIter);
174422 ** Iterator pIter currently points to the first rowid of a doclist.
174425 ** doclist-index from disk and initialize an iterator at (pIter->pDlidx).
174427 static void fts5SegIterLoadDlidx(Fts5Index *p, Fts5SegIter *pIter){
174428 int iSeg = pIter->pSeg->iSegid;
174429 int bRev = (pIter->flags & FTS5_SEGITER_REVERSE);
174430 Fts5Data *pLeaf = pIter->pLeaf; /* Current leaf data */
174432 assert( pIter->flags & FTS5_SEGITER_ONETERM );
174433 assert( pIter->pDlidx==0 );
174438 if( pIter->iTermLeafPgno==pIter->iLeafPgno
174439 && pIter->iEndofDoclist<pLeaf->szLeaf
174444 pIter->pDlidx = fts5DlidxIterInit(p, bRev, iSeg, pIter->iTermLeafPgno);
174469 Fts5SegIter *pIter, /* Iterator to seek */
174473 const u8 *a = pIter->pLeaf->p;
174474 int szLeaf = pIter->pLeaf->szLeaf;
174475 int n = pIter->pLeaf->nn;
174534 fts5DataRelease(pIter->pLeaf);
174535 pIter->pLeaf = 0;
174539 fts5SegIterNextPage(p, pIter);
174540 if( pIter->pLeaf==0 ) return;
174541 a = pIter->pLeaf->p;
174542 if( fts5LeafIsTermless(pIter->pLeaf)==0 ){
174543 fts5GetVarint32(&pIter->pLeaf->p[pIter->pLeaf->szLeaf], iOff);
174544 if( iOff<4 || iOff>=pIter->pLeaf->szLeaf ){
174557 pIter->iLeafOffset = iOff + nNew;
174558 pIter->iTermLeafOffset = pIter->iLeafOffset;
174559 pIter->iTermLeafPgno = pIter->iLeafPgno;
174561 fts5BufferSet(&p->rc, &pIter->term, nKeep, pTerm);
174562 fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
174565 pIter->iEndofDoclist = pIter->pLeaf->nn+1;
174569 pIter->iEndofDoclist = iTermOff + nExtra;
174571 pIter->iPgidxOff = iPgidx;
174573 fts5SegIterLoadRowid(p, pIter);
174574 fts5SegIterLoadNPos(p, pIter);
174578 ** Initialize the object pIter to point to term pTerm/nTerm within segment
174590 Fts5SegIter *pIter /* Object to populate */
174601 memset(pIter, 0, sizeof(*pIter));
174602 pIter->pSeg = pSeg;
174629 pIter->iLeafPgno = iPg - 1;
174630 fts5SegIterNextPage(p, pIter);
174632 if( pIter->pLeaf ){
174633 fts5LeafSeek(p, bGe, pIter, pTerm, nTerm);
174637 pIter->flags |= FTS5_SEGITER_ONETERM;
174638 if( pIter->pLeaf ){
174640 pIter->flags |= FTS5_SEGITER_REVERSE;
174643 fts5SegIterLoadDlidx(p, pIter);
174646 fts5SegIterReverse(p, pIter);
174660 || pIter->pLeaf==0 /* 2 */
174661 || fts5BufferCompareBlob(&pIter->term, pTerm, nTerm)==0 /* 3 */
174662 || (bGe && fts5BufferCompareBlob(&pIter->term, pTerm, nTerm)>0) /* 4 */
174667 ** Initialize the object pIter to point to term pTerm/nTerm within the
174678 Fts5SegIter *pIter /* Object to populate */
174693 pIter->flags |= FTS5_SEGITER_ONETERM;
174701 sqlite3Fts5BufferSet(&p->rc, &pIter->term, n, z);
174706 pIter->pLeaf = pLeaf;
174707 pIter->iLeafOffset = fts5GetVarint(pLeaf->p, (u64*)&pIter->iRowid);
174708 pIter->iEndofDoclist = pLeaf->nn+1;
174711 pIter->flags |= FTS5_SEGITER_REVERSE;
174712 fts5SegIterReverseInitPage(p, pIter);
174714 fts5SegIterLoadNPos(p, pIter);
174722 static void fts5SegIterClear(Fts5SegIter *pIter){
174723 fts5BufferFree(&pIter->term);
174724 fts5DataRelease(pIter->pLeaf);
174725 fts5DataRelease(pIter->pNextLeaf);
174726 fts5DlidxIterFree(pIter->pDlidx);
174727 sqlite3_free(pIter->aRowidOffset);
174728 memset(pIter, 0, sizeof(Fts5SegIter));
174740 Fts5IndexIter *pIter,
174745 int i1 = p1 - pIter->aSeg;
174746 int i2 = p2 - pIter->aSeg;
174761 res = ((p1->iRowid > p2->iRowid)==pIter->bRev) ? -1 : 1;
174778 ** statement used to verify that the contents of the pIter->aFirst[] array
174781 static void fts5AssertMultiIterSetup(Fts5Index *p, Fts5IndexIter *pIter){
174783 Fts5SegIter *pFirst = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
174786 assert( (pFirst->pLeaf==0)==pIter->bEof );
174788 /* Check that pIter->iSwitchRowid is set correctly. */
174789 for(i=0; i<pIter->nSeg; i++){
174790 Fts5SegIter *p1 = &pIter->aSeg[i];
174794 || p1->iRowid==pIter->iSwitchRowid
174795 || (p1->iRowid<pIter->iSwitchRowid)==pIter->bRev
174799 for(i=0; i<pIter->nSeg; i+=2){
174800 Fts5SegIter *p1 = &pIter->aSeg[i];
174801 Fts5SegIter *p2 = &pIter->aSeg[i+1];
174802 Fts5CResult *pRes = &pIter->aFirst[(pIter->nSeg + i) / 2];
174803 fts5AssertComparisonResult(pIter, p1, p2, pRes);
174806 for(i=1; i<(pIter->nSeg / 2); i+=2){
174807 Fts5SegIter *p1 = &pIter->aSeg[ pIter->aFirst[i*2].iFirst ];
174808 Fts5SegIter *p2 = &pIter->aSeg[ pIter->aFirst[i*2+1].iFirst ];
174809 Fts5CResult *pRes = &pIter->aFirst[i];
174810 fts5AssertComparisonResult(pIter, p1, p2, pRes);
174819 ** Do the comparison necessary to populate pIter->aFirst[iOut].
174822 ** in the pIter->aSeg[] array that is (a) not at EOF, and (b) pointing
174826 static int fts5MultiIterDoCompare(Fts5IndexIter *pIter, int iOut){
174832 Fts5CResult *pRes = &pIter->aFirst[iOut];
174834 assert( iOut<pIter->nSeg && iOut>0 );
174835 assert( pIter->bRev==0 || pIter->bRev==1 );
174837 if( iOut>=(pIter->nSeg/2) ){
174838 i1 = (iOut - pIter->nSeg/2) * 2;
174841 i1 = pIter->aFirst[iOut*2].iFirst;
174842 i2 = pIter->aFirst[iOut*2+1].iFirst;
174844 p1 = &pIter->aSeg[i1];
174845 p2 = &pIter->aSeg[i2];
174862 res = ((p1->iRowid > p2->iRowid)==pIter->bRev) ? -1 : +1;
174882 Fts5SegIter *pIter, /* Iterator to advance */
174885 assert( iLeafPgno>pIter->iLeafPgno );
174887 if( iLeafPgno>pIter->pSeg->pgnoLast ){
174890 fts5DataRelease(pIter->pNextLeaf);
174891 pIter->pNextLeaf = 0;
174892 pIter->iLeafPgno = iLeafPgno-1;
174893 fts5SegIterNextPage(p, pIter);
174894 assert( p->rc!=SQLITE_OK || pIter->iLeafPgno==iLeafPgno );
174898 u8 *a = pIter->pLeaf->p;
174899 int n = pIter->pLeaf->szLeaf;
174901 iOff = fts5LeafFirstRowidOff(pIter->pLeaf);
174905 iOff += fts5GetVarint(&a[iOff], (u64*)&pIter->iRowid);
174906 pIter->iLeafOffset = iOff;
174907 fts5SegIterLoadNPos(p, pIter);
174920 Fts5SegIter *pIter, /* Iterator to advance */
174923 int bRev = (pIter->flags & FTS5_SEGITER_REVERSE);
174924 Fts5DlidxIter *pDlidx = pIter->pDlidx;
174925 int iLeafPgno = pIter->iLeafPgno;
174928 assert( pIter->flags & FTS5_SEGITER_ONETERM );
174929 assert( pIter->pDlidx );
174930 assert( pIter->pLeaf );
174937 assert_nc( iLeafPgno>=pIter->iLeafPgno || p->rc );
174938 if( iLeafPgno>pIter->iLeafPgno ){
174939 fts5SegIterGotoPage(p, pIter, iLeafPgno);
174943 assert( pIter->pNextLeaf==0 );
174944 assert( iMatch<pIter->iRowid );
174950 assert( fts5DlidxIterEof(p, pDlidx) || iLeafPgno<=pIter->iLeafPgno );
174952 if( iLeafPgno<pIter->iLeafPgno ){
174953 pIter->iLeafPgno = iLeafPgno+1;
174954 fts5SegIterReverseNewPage(p, pIter);
174960 if( bMove ) fts5SegIterNext(p, pIter, 0);
174961 if( pIter->pLeaf==0 ) break;
174962 if( bRev==0 && pIter->iRowid>=iMatch ) break;
174963 if( bRev!=0 && pIter->iRowid<=iMatch ) break;
174972 static void fts5MultiIterFree(Fts5Index *p, Fts5IndexIter *pIter){
174973 if( pIter ){
174975 for(i=0; i<pIter->nSeg; i++){
174976 fts5SegIterClear(&pIter->aSeg[i]);
174978 fts5StructureRelease(pIter->pStruct);
174979 fts5BufferFree(&pIter->poslist);
174980 sqlite3_free(pIter);
174986 Fts5IndexIter *pIter, /* Iterator to update aFirst[] array for */
174991 for(i=(pIter->nSeg+iChanged)/2; i>=iMinset && p->rc==SQLITE_OK; i=i/2){
174993 if( (iEq = fts5MultiIterDoCompare(pIter, i)) ){
174994 fts5SegIterNext(p, &pIter->aSeg[iEq], 0);
174995 i = pIter->nSeg + iEq;
175001 ** Sub-iterator iChanged of iterator pIter has just been advanced. It still
175003 ** attempts to update the contents of the pIter->aFirst[] accordingly.
175012 Fts5IndexIter *pIter, /* Iterator to update aFirst[] array for */
175015 Fts5SegIter *pNew = &pIter->aSeg[iChanged];
175017 if( pNew->iRowid==pIter->iSwitchRowid
175018 || (pNew->iRowid<pIter->iSwitchRowid)==pIter->bRev
175021 Fts5SegIter *pOther = &pIter->aSeg[iChanged ^ 0x0001];
175022 pIter->iSwitchRowid = pIter->bRev ? SMALLEST_INT64 : LARGEST_INT64;
175023 for(i=(pIter->nSeg+iChanged)/2; 1; i=i/2){
175024 Fts5CResult *pRes = &pIter->aFirst[i];
175032 }else if( (pOther->iRowid>pNew->iRowid)==pIter->bRev ){
175033 pIter->iSwitchRowid = pOther->iRowid;
175035 }else if( (pOther->iRowid>pIter->iSwitchRowid)==pIter->bRev ){
175036 pIter->iSwitchRowid = pOther->iRowid;
175039 pRes->iFirst = (pNew - pIter->aSeg);
175042 pOther = &pIter->aSeg[ pIter->aFirst[i ^ 0x0001].iFirst ];
175050 ** Set the pIter->bEof variable based on the state of the sub-iterators.
175052 static void fts5MultiIterSetEof(Fts5IndexIter *pIter){
175053 Fts5SegIter *pSeg = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
175054 pIter->bEof = pSeg->pLeaf==0;
175055 pIter->iSwitchRowid = pSeg->iRowid;
175067 Fts5IndexIter *pIter,
175074 int iFirst = pIter->aFirst[1].iFirst;
175076 Fts5SegIter *pSeg = &pIter->aSeg[iFirst];
175085 || fts5MultiIterAdvanceRowid(p, pIter, iFirst)
175087 fts5MultiIterAdvanced(p, pIter, iFirst, 1);
175088 fts5MultiIterSetEof(pIter);
175090 fts5AssertMultiIterSetup(p, pIter);
175093 }while( pIter->bSkipEmpty && fts5MultiIterIsEmpty(p, pIter) );
175170 Fts5SegIter *pIter = &pNew->aSeg[iIter++];
175171 fts5SegIterHashInit(p, pTerm, nTerm, flags, pIter);
175176 Fts5SegIter *pIter = &pNew->aSeg[iIter++];
175178 fts5SegIterInit(p, pSeg, pIter);
175180 fts5SegIterSeekInit(p, &buf, pTerm, nTerm, flags, pSeg, pIter);
175230 Fts5SegIter *pIter = &pNew->aSeg[1];
175233 pIter->flags = FTS5_SEGITER_ONETERM;
175235 pIter->pLeaf = pData;
175236 pIter->iLeafOffset = fts5GetVarint(pData->p, (u64*)&pIter->iRowid);
175237 pIter->iEndofDoclist = pData->nn;
175241 pIter->flags |= FTS5_SEGITER_REVERSE;
175242 fts5SegIterReverseInitPage(p, pIter);
175244 fts5SegIterLoadNPos(p, pIter);
175261 static int fts5MultiIterEof(Fts5Index *p, Fts5IndexIter *pIter){
175263 || (pIter->aSeg[ pIter->aFirst[1].iFirst ].pLeaf==0)==pIter->bEof
175265 return (p->rc || pIter->bEof);
175273 static i64 fts5MultiIterRowid(Fts5IndexIter *pIter){
175274 assert( pIter->aSeg[ pIter->aFirst[1].iFirst ].pLeaf );
175275 return pIter->aSeg[ pIter->aFirst[1].iFirst ].iRowid;
175283 Fts5IndexIter *pIter,
175288 fts5MultiIterNext(p, pIter, 1, iMatch);
175289 if( fts5MultiIterEof(p, pIter) ) break;
175290 iRowid = fts5MultiIterRowid(pIter);
175291 if( pIter->bRev==0 && iRowid>=iMatch ) break;
175292 if( pIter->bRev!=0 && iRowid<=iMatch ) break;
175300 static const u8 *fts5MultiIterTerm(Fts5IndexIter *pIter, int *pn){
175301 Fts5SegIter *p = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
175875 ** Iterator pIter was used to iterate through the input segments of on an
175879 static void fts5TrimSegments(Fts5Index *p, Fts5IndexIter *pIter){
175883 for(i=0; i<pIter->nSeg; i++){
175884 Fts5SegIter *pSeg = &pIter->aSeg[i];
175957 Fts5IndexIter *pIter = 0; /* Iterator to read input data */
176008 for(fts5MultiIterNew(p, pStruct, 0, 0, 0, 0, iLvl, nInput, &pIter);
176009 fts5MultiIterEof(p, pIter)==0;
176010 fts5MultiIterNext(p, pIter, 0, 0)
176012 Fts5SegIter *pSegIter = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
176020 pTerm = fts5MultiIterTerm(pIter, &nTerm);
176034 fts5WriteAppendRowid(p, &writer, fts5MultiIterRowid(pIter), nPos);
176044 if( fts5MultiIterEof(p, pIter) ){
176066 fts5TrimSegments(p, pIter);
176070 fts5MultiIterFree(p, pIter);
176522 ** Iterator pIter currently points to a valid entry (not EOF). This
176658 static void fts5DoclistIterNext(Fts5DoclistIter *pIter){
176659 u8 *p = pIter->aPoslist + pIter->nSize + pIter->nPoslist;
176661 assert( pIter->aPoslist );
176662 if( p>=pIter->aEof ){
176663 pIter->aPoslist = 0;
176668 pIter->iRowid += iDelta;
176673 pIter->nSize = fts5GetVarint32(p, nPos);
176674 pIter->nPoslist = (nPos>>1);
176676 pIter->nPoslist = ((int)(p[0])) >> 1;
176677 pIter->nSize = 1;
176680 pIter->aPoslist = p;
176686 Fts5DoclistIter *pIter
176688 memset(pIter, 0, sizeof(*pIter));
176689 pIter->aPoslist = pBuf->p;
176690 pIter->aEof = &pBuf->p[pBuf->n];
176691 fts5DoclistIterNext(pIter);
177153 static int sqlite3Fts5IterEof(Fts5IndexIter *pIter){
177154 assert( pIter->pIndex->rc==SQLITE_OK );
177155 return pIter->bEof;
177161 static int sqlite3Fts5IterNext(Fts5IndexIter *pIter){
177162 assert( pIter->pIndex->rc==SQLITE_OK );
177163 fts5MultiIterNext(pIter->pIndex, pIter, 0, 0);
177164 return fts5IndexReturn(pIter->pIndex);
177170 static int sqlite3Fts5IterNextScan(Fts5IndexIter *pIter){
177171 Fts5Index *p = pIter->pIndex;
177173 assert( pIter->pIndex->rc==SQLITE_OK );
177175 fts5MultiIterNext(p, pIter, 0, 0);
177177 Fts5SegIter *pSeg = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
177181 pIter->bEof = 1;
177185 return fts5IndexReturn(pIter->pIndex);
177193 static int sqlite3Fts5IterNextFrom(Fts5IndexIter *pIter, i64 iMatch){
177194 fts5MultiIterNextFrom(pIter->pIndex, pIter, iMatch);
177195 return fts5IndexReturn(pIter->pIndex);
177201 static i64 sqlite3Fts5IterRowid(Fts5IndexIter *pIter){
177202 return fts5MultiIterRowid(pIter);
177208 static const char *sqlite3Fts5IterTerm(Fts5IndexIter *pIter, int *pn){
177210 const char *z = (const char*)fts5MultiIterTerm(pIter, &n);
177245 Fts5IndexIter *pIter,
177251 Fts5SegIter *pSeg = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
177252 assert( pIter->pIndex->rc==SQLITE_OK );
177256 if( pColset==0 || pIter->bFiltered ){
177263 fts5BufferZero(&pIter->poslist);
177264 fts5IndexExtractColset(pColset, pPos, pSeg->nPos, &pIter->poslist);
177265 *pp = pIter->poslist.p;
177266 *pn = pIter->poslist.n;
177269 fts5BufferZero(&pIter->poslist);
177270 fts5SegiterPoslist(pIter->pIndex, pSeg, pColset, &pIter->poslist);
177271 *pp = pIter->poslist.p;
177272 *pn = pIter->poslist.n;
177274 return fts5IndexReturn(pIter->pIndex);
177282 static int sqlite3Fts5IterPoslistBuffer(Fts5IndexIter *pIter, Fts5Buffer *pBuf){
177283 Fts5Index *p = pIter->pIndex;
177284 Fts5SegIter *pSeg = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
177294 static void sqlite3Fts5IterClose(Fts5IndexIter *pIter){
177295 if( pIter ){
177296 Fts5Index *pIndex = pIter->pIndex;
177297 fts5MultiIterFree(pIter->pIndex, pIter);
177788 Fts5IndexIter *pIter; /* Used to iterate through entire index */
177822 for(fts5MultiIterNew(p, pStruct, 0, 0, 0, 0, -1, 0, &pIter);
177823 fts5MultiIterEof(p, pIter)==0;
177824 fts5MultiIterNext(p, pIter, 0, 0)
177829 i64 iRowid = fts5MultiIterRowid(pIter);
177830 char *z = (char*)fts5MultiIterTerm(pIter, &n);
177836 fts5SegiterPoslist(p, &pIter->aSeg[pIter->aFirst[1].iFirst] , 0, &poslist);
177845 fts5MultiIterFree(p, pIter);
180109 Fts5PhraseIter *pIter,
180112 if( pIter->a>=pIter->b ){
180117 pIter->a += fts5GetVarint32(pIter->a, iVal);
180119 pIter->a += fts5GetVarint32(pIter->a, iVal);
180122 pIter->a += fts5GetVarint32(pIter->a, iVal);
180131 Fts5PhraseIter *pIter,
180135 int n = fts5CsrPoslist(pCsr, iPhrase, &pIter->a);
180136 pIter->b = &pIter->a[n];
180139 fts5ApiPhraseNext(pCtx, pIter, piCol, piOff);
183843 Fts5IndexIter *pIter; /* Term/rowid iterator object */
184084 sqlite3Fts5IterClose(pCsr->pIter);
184085 pCsr->pIter = 0;
184119 if( sqlite3Fts5IterEof(pCsr->pIter) ){
184125 zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm);
184139 rc = sqlite3Fts5IterPoslist(pCsr->pIter, 0, &pPos, &nPos, &dummy);
184157 rc = sqlite3Fts5IterNextScan(pCsr->pIter);
184160 zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm);
184162 if( sqlite3Fts5IterEof(pCsr->pIter) ) break;
184192 rc = sqlite3Fts5IndexQuery(pCsr->pIndex, 0, 0, flags, 0, &pCsr->pIter);