Lines Matching refs:pIdx
18963 SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
63401 Index *pIdx = (Index *)sqliteHashData(p);
63402 if( pIdx->tnum==(int)iRoot ){
63409 iTab = pIdx->pTable->tnum;
64804 static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){
64848 *pIdx = (int)(pSpace - data);
64878 *pIdx = top;
75683 Index *pIdx;
75705 Index *pIdx = p->pIdx; /* Index being probed */
75708 int nCol = pIdx->nColumn; /* Number of index columns including rowid */
75713 pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx);
76156 Index *pIdx, /* Index being probed */
76171 alloc.pIdx = pIdx;
76177 u8 aff = sqlite3IndexColumnAffinity(pParse->db, pIdx, iVal+i);
77541 SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse *pParse, Index *pIdx){
77545 assert( pIdx!=0 );
77546 pKeyInfo = sqlite3KeyInfoOfIndex(pParse, pIdx);
91427 Index *pIdx;
91445 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
91447 for(j=0; j<pIdx->nKeyCol; j++){
91449 if( pIdx->aiColumn[j]==iCol || pIdx->aiColumn[j]==XN_EXPR ){
99326 Index *pIdx; /* Iterator variable */
99358 for(pIdx=pTab->pIndex; pIdx && eType==0; pIdx=pIdx->pNext){
99361 if( pIdx->nColumn<nExpr ) continue;
99362 if( pIdx->pPartIdxWhere!=0 ) continue;
99365 testcase( pIdx->nColumn==BMS-2 );
99366 testcase( pIdx->nColumn==BMS-1 );
99367 if( pIdx->nColumn>=BMS-1 ) continue;
99369 if( pIdx->nKeyCol>nExpr
99370 ||(pIdx->nColumn>nExpr && !IsUniqueIndex(pIdx))
99385 if( pIdx->aiColumn[j]!=pRhs->iColumn ) continue;
99386 assert( pIdx->azColl[j] );
99387 if( pReq!=0 && sqlite3StrICmp(pReq->zName, pIdx->azColl[j])!=0 ){
99404 "USING INDEX %s FOR IN-OPERATOR",pIdx->zName));
99405 sqlite3VdbeAddOp3(v, OP_OpenRead, iTab, pIdx->tnum, iDb);
99406 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
99407 VdbeComment((v, "%s", pIdx->zName));
99409 eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];
100192 Index *pIdx, /* The index whose column is to be loaded */
100197 i16 iTabCol = pIdx->aiColumn[iIdxCol];
100199 assert( pIdx->aColExpr );
100200 assert( pIdx->aColExpr->nExpr>iIdxCol );
100202 sqlite3ExprCodeCopy(pParse, pIdx->aColExpr->a[iIdxCol].pExpr, regOut);
100205 sqlite3ExprCodeGetColumnOfTable(pParse->pVdbe, pIdx->pTable, iTabCur,
101961 Index *pIdx; /* The index to be tested for coverage */
101973 && sqlite3ColumnOfIndex(pWalker->u.pIdxCover->pIdx, pExpr->iColumn)<0
101994 Index *pIdx /* The index that might be used for coverage */
102000 xcov.pIdx = pIdx;
103539 Index *pIdx;
103544 while( (pIdx = pParse->pNewIndex)!=0 ){
103545 pParse->pNewIndex = pIdx->pNext;
103546 sqlite3FreeIndex(db, pIdx);
103595 Index *pIdx;
103655 for(pIdx=sParse.pNewTable->pIndex; pIdx; pIdx=pIdx->pNext){
103656 sqlite3WalkExprList(&sWalker, pIdx->aColExpr);
103658 for(pIdx=sParse.pNewIndex; pIdx; pIdx=pIdx->pNext){
103659 sqlite3WalkExprList(&sWalker, pIdx->aColExpr);
104989 Index *pIdx; /* An index to being analyzed */
105059 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
105066 if( pOnlyIdx && pOnlyIdx!=pIdx ) continue;
105067 if( pIdx->pPartIdxWhere==0 ) needTableCnt = 0;
105068 if( !HasRowid(pTab) && IsPrimaryKeyIndex(pIdx) ){
105069 nCol = pIdx->nKeyCol;
105073 nCol = pIdx->nColumn;
105074 zIdxName = pIdx->zName;
105075 nColTest = pIdx->uniqNotNull ? pIdx->nKeyCol-1 : nCol-1;
105121 assert( iDb==sqlite3SchemaToIndex(db, pIdx->pSchema) );
105122 sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pIdx->tnum, iDb);
105123 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
105124 VdbeComment((v, "%s", pIdx->zName));
105140 sqlite3VdbeAddOp2(v, OP_Integer, pIdx->nKeyCol, regStat4+2);
105176 if( nColTest==1 && pIdx->nKeyCol==1 && IsUniqueIndex(pIdx) ){
105184 char *pColl = (char*)sqlite3LocateCollSeq(pParse, pIdx->azColl[i]);
105224 Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
105228 k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
105229 assert( k>=0 && k<pIdx->nColumn );
105279 sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iTabCur, 0, regSample);
105282 sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iTabCur, i, regCol+i);
105398 Index *pIdx;
105426 if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
105427 analyzeTable(pParse, pIdx->pTable, pIdx);
105589 SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3 *db, Index *pIdx){
105591 if( pIdx->aSample ){
105593 for(j=0; j<pIdx->nSample; j++){
105594 IndexSample *p = &pIdx->aSample[j];
105597 sqlite3DbFree(db, pIdx->aSample);
105600 pIdx->nSample = 0;
105601 pIdx->aSample = 0;
105605 UNUSED_PARAMETER(pIdx);
105614 static void initAvgEq(Index *pIdx){
105615 if( pIdx ){
105616 IndexSample *aSample = pIdx->aSample;
105617 IndexSample *pFinal = &aSample[pIdx->nSample-1];
105620 if( pIdx->nSampleCol>1 ){
105625 nCol = pIdx->nSampleCol-1;
105626 pIdx->aAvgEq[nCol] = 1;
105629 int nSample = pIdx->nSample;
105637 if( !pIdx->aiRowEst || iCol>=pIdx->nKeyCol || pIdx->aiRowEst[iCol+1]==0 ){
105642 nRow = pIdx->aiRowEst[0];
105643 nDist100 = ((i64)100 * pIdx->aiRowEst[0]) / pIdx->aiRowEst[iCol+1];
105645 pIdx->nRowEst0 = nRow;
105652 if( i==(pIdx->nSample-1)
105664 pIdx->aAvgEq[iCol] = avgEq;
105678 Index *pIdx = sqlite3FindIndex(db, zName, zDb);
105679 if( pIdx==0 ){
105681 if( pTab && !HasRowid(pTab) ) pIdx = sqlite3PrimaryKeyIndex(pTab);
105683 return pIdx;
105725 Index *pIdx; /* Pointer to the index object */
105734 pIdx = findIndexOrPrimaryKey(db, zIndex, zDb);
105735 assert( pIdx==0 || bStat3 || pIdx->nSample==0 );
105738 if( pIdx==0 || pIdx->nSample ) continue;
105740 assert( !HasRowid(pIdx->pTable) || pIdx->nColumn==pIdx->nKeyCol+1 );
105741 if( !HasRowid(pIdx->pTable) && IsPrimaryKeyIndex(pIdx) ){
105742 nIdxCol = pIdx->nKeyCol;
105744 nIdxCol = pIdx->nColumn;
105747 pIdx->nSampleCol = nIdxCol;
105752 pIdx->aSample = sqlite3DbMallocZero(db, nByte);
105753 if( pIdx->aSample==0 ){
105757 pSpace = (tRowcnt*)&pIdx->aSample[nSample];
105758 pIdx->aAvgEq = pSpace; pSpace += nIdxCol;
105760 pIdx->aSample[i].anEq = pSpace; pSpace += nIdxCol;
105761 pIdx->aSample[i].anLt = pSpace; pSpace += nIdxCol;
105762 pIdx->aSample[i].anDLt = pSpace; pSpace += nIdxCol;
105764 assert( ((u8*)pSpace)-nByte==(u8*)(pIdx->aSample) );
105779 Index *pIdx; /* Pointer to the index object */
105784 pIdx = findIndexOrPrimaryKey(db, zIndex, zDb);
105785 if( pIdx==0 ) continue;
105788 nCol = pIdx->nSampleCol;
105790 if( pIdx!=pPrevIdx ){
105792 pPrevIdx = pIdx;
105794 pSample = &pIdx->aSample[pIdx->nSample];
105814 pIdx->nSample++;
105886 Index *pIdx = sqliteHashData(i);
105887 pIdx->hasStat1 = 0;
105889 sqlite3DeleteIndexSamples(db, pIdx);
105890 pIdx->aSample = 0;
105911 Index *pIdx = sqliteHashData(i);
105912 if( !pIdx->hasStat1 ) sqlite3DefaultRowEst(pIdx);
105923 Index *pIdx = sqliteHashData(i);
105924 sqlite3_free(pIdx->aiRowEst);
105925 pIdx->aiRowEst = 0;
107727 SQLITE_PRIVATE i16 sqlite3ColumnOfIndex(Index *pIdx, i16 iCol){
107729 for(i=0; i<pIdx->nColumn; i++){
107730 if( iCol==pIdx->aiColumn[i] ) return i;
108046 Index *pIdx;
108047 for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){
108048 assert( pIdx->nKeyCol==1 && pIdx->onError!=OE_None );
108049 if( pIdx->aiColumn[0]==p->nCol-1 ){
108050 pIdx->uniqNotNull = 1;
108348 Index *pIdx;
108356 for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){
108357 assert( pIdx->nKeyCol==1 );
108358 if( pIdx->aiColumn[0]==i ){
108359 pIdx->azColl[0] = p->aCol[i].zColl;
108458 static void identPut(char *z, int *pIdx, char *zSignedIdent){
108461 i = *pIdx;
108478 *pIdx = i;
108554 static int resizeIndexObject(sqlite3 *db, Index *pIdx, int N){
108557 if( pIdx->nColumn>=N ) return SQLITE_OK;
108558 assert( pIdx->isResized==0 );
108562 memcpy(zExtra, pIdx->azColl, sizeof(char*)*pIdx->nColumn);
108563 pIdx->azColl = (const char**)zExtra;
108565 memcpy(zExtra, pIdx->aiColumn, sizeof(i16)*pIdx->nColumn);
108566 pIdx->aiColumn = (i16*)zExtra;
108568 memcpy(zExtra, pIdx->aSortOrder, pIdx->nColumn);
108569 pIdx->aSortOrder = (u8*)zExtra;
108570 pIdx->nColumn = N;
108571 pIdx->isResized = 1;
108592 static void estimateIndexWidth(Index *pIdx){
108595 const Column *aCol = pIdx->pTable->aCol;
108596 for(i=0; i<pIdx->nColumn; i++){
108597 i16 x = pIdx->aiColumn[i];
108598 assert( x<pIdx->pTable->nCol );
108599 wIndex += x<0 ? 1 : aCol[pIdx->aiColumn[i]].szEst;
108601 pIdx->szIdxRow = sqlite3LogEst(wIndex*4);
108621 static void recomputeColumnsNotIndexed(Index *pIdx){
108624 for(j=pIdx->nColumn-1; j>=0; j--){
108625 int x = pIdx->aiColumn[j];
108632 pIdx->colNotIdxed = ~m;
108633 assert( (pIdx->colNotIdxed>>63)==1 );
108661 Index *pIdx;
108741 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
108743 if( IsPrimaryKeyIndex(pIdx) ) continue;
108745 if( !hasColumn(pIdx->aiColumn, pIdx->nKeyCol, pPk->aiColumn[i]) ) n++;
108749 pIdx->nColumn = pIdx->nKeyCol;
108752 if( resizeIndexObject(db, pIdx, pIdx->nKeyCol+n) ) return;
108753 for(i=0, j=pIdx->nKeyCol; i<nPk; i++){
108754 if( !hasColumn(pIdx->aiColumn, pIdx->nKeyCol, pPk->aiColumn[i]) ){
108755 pIdx->aiColumn[j] = pPk->aiColumn[i];
108756 pIdx->azColl[j] = pPk->azColl[i];
108760 assert( pIdx->nColumn>=pIdx->nKeyCol+n );
108761 assert( pIdx->nColumn>=j );
108842 Index *pIdx; /* An implied index of the table */
108905 for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){
108906 estimateIndexWidth(pIdx);
109350 Index *pIdx = sqliteHashData(pElem);
109351 if( pIdx->tnum==iFrom ){
109352 pIdx->tnum = iTo;
109414 Index *pIdx;
109420 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
109421 int iIdx = pIdx->tnum;
109422 assert( pIdx->pSchema==pTab->pSchema );
110352 Index *pIdx;
110353 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
110355 assert( IsUniqueIndex(pIdx) );
110356 assert( pIdx->idxType!=SQLITE_IDXTYPE_APPDEF );
110359 if( pIdx->nKeyCol!=pIndex->nKeyCol ) continue;
110360 for(k=0; k<pIdx->nKeyCol; k++){
110363 assert( pIdx->aiColumn[k]>=0 );
110364 if( pIdx->aiColumn[k]!=pIndex->aiColumn[k] ) break;
110365 z1 = pIdx->azColl[k];
110369 if( k==pIdx->nKeyCol ){
110370 if( pIdx->onError!=pIndex->onError ){
110378 if( !(pIdx->onError==OE_Default || pIndex->onError==OE_Default) ){
110382 if( pIdx->onError==OE_Default ){
110383 pIdx->onError = pIndex->onError;
110386 if( idxType==SQLITE_IDXTYPE_PRIMARYKEY ) pIdx->idxType = idxType;
110553 SQLITE_PRIVATE void sqlite3DefaultRowEst(Index *pIdx){
110556 LogEst *a = pIdx->aiRowLogEst;
110557 int nCopy = MIN(ArraySize(aVal), pIdx->nKeyCol);
110561 assert( !pIdx->hasStat1 );
110566 a[0] = pIdx->pTable->nRowLogEst;
110567 if( pIdx->pPartIdxWhere!=0 ) a[0] -= 10; assert( 10==sqlite3LogEst(2) );
110573 for(i=nCopy+1; i<=pIdx->nKeyCol; i++){
110578 if( IsUniqueIndex(pIdx) ) a[pIdx->nKeyCol] = 0;
110671 int *pIdx /* Write the index of a new slot here */
110674 sqlite3_int64 n = *pIdx = *pnEntry;
110679 *pIdx = -1;
111296 Index *pIdx /* The index that triggers the constraint */
111301 Table *pTab = pIdx->pTable;
111305 if( pIdx->aColExpr ){
111306 sqlite3_str_appendf(&errMsg, "index '%q'", pIdx->zName);
111308 for(j=0; j<pIdx->nKeyCol; j++){
111310 assert( pIdx->aiColumn[j]>=0 );
111311 zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
111320 IsPrimaryKeyIndex(pIdx) ? SQLITE_CONSTRAINT_PRIMARYKEY
111485 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
111487 int nCol = pIdx->nColumn;
111488 int nKey = pIdx->nKeyCol;
111491 if( pIdx->uniqNotNull ){
111499 const char *zColl = pIdx->azColl[i];
111502 pKey->aSortOrder[i] = pIdx->aSortOrder[i];
111506 if( pIdx->bNoQuery==0 ){
111514 pIdx->bNoQuery = 1;
112330 Index *pIdx; /* For looping over indices of the table */
112427 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
112506 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
112507 assert( pIdx->pSchema==pTab->pSchema );
112508 sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb);
112926 Index *pIdx; /* Current index */
112933 for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
112934 assert( iIdxCur+i!=iDataCur || pPk==pIdx );
112936 if( pIdx==pPk ) continue;
112938 VdbeModuleComment((v, "GenRowIdxDel for %s", pIdx->zName));
112939 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 1,
112942 pIdx->uniqNotNull ? pIdx->nKeyCol : pIdx->nColumn);
112944 pPrior = pIdx;
112981 Index *pIdx, /* The index for which to generate a key */
112995 if( pIdx->pPartIdxWhere ){
112998 sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, *piPartIdxLabel,
113005 nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn;
113010 && pPrior->aiColumn[j]==pIdx->aiColumn[j]
113016 sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iDataCur, j, regBase+j);
113027 if( pIdx->pTable->pSelect ){
113028 const char *zAff = sqlite3IndexAffinityStr(pParse->db, pIdx);
115267 Index *pIdx = 0; /* Value to return via *ppIdx */
115304 for(pIdx=pParent->pIndex; pIdx; pIdx=pIdx->pNext){
115305 if( pIdx->nKeyCol==nCol && IsUniqueIndex(pIdx) && pIdx->pPartIdxWhere==0 ){
115314 if( IsPrimaryKeyIndex(pIdx) ){
115328 i16 iCol = pIdx->aiColumn[i]; /* Index of column in parent tbl */
115339 if( sqlite3StrICmp(pIdx->azColl[i], zDfltColl) ) break;
115355 if( !pIdx ){
115365 *ppIdx = pIdx;
115399 Index *pIdx, /* Unique index on parent key columns in pTab */
115434 if( pIdx==0 ){
115469 sqlite3VdbeAddOp3(v, OP_OpenRead, iCur, pIdx->tnum, iDb);
115470 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
115489 int iParent = pIdx->aiColumn[i]+1+regData;
115490 assert( pIdx->aiColumn[i]>=0 );
115492 if( pIdx->aiColumn[i]==pTab->iPKey ){
115503 sqlite3IndexAffinityStr(pParse->db,pIdx), nCol);
115625 Index *pIdx, /* Index on parent covering the foreign key */
115639 assert( pIdx==0 || pIdx->pTable==pTab );
115640 assert( pIdx==0 || pIdx->nKeyCol==pFKey->nCol );
115641 assert( pIdx!=0 || pFKey->nCol==1 );
115642 assert( pIdx!=0 || HasRowid(pTab) );
115664 iCol = pIdx ? pIdx->aiColumn[i] : -1;
115698 assert( pIdx!=0 );
115699 for(i=0; i<pIdx->nKeyCol; i++){
115700 i16 iCol = pIdx->aiColumn[i];
115969 Index *pIdx = 0; /* Index on key columns in pTo */
115992 if( !pTo || sqlite3FkLocateIndex(pParse, pTo, pFKey, &pIdx, &aiFree) ){
116013 assert( pFKey->nCol==1 || (aiFree && pIdx) );
116025 assert( pIdx==0 || pIdx->aiColumn[i]>=0 );
116032 char *zCol = pTo->aCol[pIdx ? pIdx->aiColumn[i] : pTo->iPKey].zName;
116049 fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regOld, -1, bIgnore);
116060 fkLookupParent(pParse, iDb, pTo, pIdx, pFKey, aiCol, regNew, +1, bIgnore);
116069 Index *pIdx = 0; /* Foreign key index for pFKey */
116086 if( sqlite3FkLocateIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ){
116103 fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regNew, -1);
116107 fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regOld, 1);
116154 Index *pIdx = 0;
116155 sqlite3FkLocateIndex(pParse, pTab, p, &pIdx, 0);
116156 if( pIdx ){
116157 for(i=0; i<pIdx->nKeyCol; i++){
116158 assert( pIdx->aiColumn[i]>=0 );
116159 mask |= COLUMN_MASK(pIdx->aiColumn[i]);
116277 Index *pIdx = 0; /* Parent key index for this FK */
116286 if( sqlite3FkLocateIndex(pParse, pTab, pFKey, &pIdx, &aiCol) ) return 0;
116299 assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKey<pTab->nCol) );
116300 assert( pIdx==0 || pIdx->aiColumn[i]>=0 );
116302 pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zName);
116583 SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(sqlite3 *db, Index *pIdx){
116584 if( !pIdx->zColAff ){
116594 Table *pTab = pIdx->pTable;
116595 pIdx->zColAff = (char *)sqlite3DbMallocRaw(0, pIdx->nColumn+1);
116596 if( !pIdx->zColAff ){
116600 for(n=0; n<pIdx->nColumn; n++){
116601 i16 x = pIdx->aiColumn[n];
116603 pIdx->zColAff[n] = pTab->aCol[x].affinity;
116605 pIdx->zColAff[n] = SQLITE_AFF_INTEGER;
116609 assert( pIdx->aColExpr!=0 );
116610 aff = sqlite3ExprAffinity(pIdx->aColExpr->a[n].pExpr);
116612 pIdx->zColAff[n] = aff;
116615 pIdx->zColAff[n] = 0;
116618 return pIdx->zColAff;
117026 Index *pIdx; /* For looping over indices of the table */
117332 for(i=0, pIdx=pTab->pIndex; i<nIdx; pIdx=pIdx->pNext, i++){
117333 assert( pIdx );
117335 pParse->nMem += pIdx->nColumn;
117804 Index *pIdx; /* Pointer to one of the indices */
118126 for(ix=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, ix++){
118133 if( pUpIdx==pIdx ){
118141 if( bAffinityDone==0 && (pUpIdx==0 || pUpIdx==pIdx) ){
118145 VdbeNoopComment((v, "uniqueness check for %s", pIdx->zName));
118150 if( pIdx->pPartIdxWhere ){
118153 sqlite3ExprIfFalseDup(pParse, pIdx->pPartIdxWhere, addrUniqueOk,
118162 for(i=0; i<pIdx->nColumn; i++){
118163 int iField = pIdx->aiColumn[i];
118167 sqlite3ExprCodeCopy(pParse, pIdx->aColExpr->a[i].pExpr, regIdx+i);
118169 VdbeComment((v, "%s column %d", pIdx->zName, i));
118180 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
118181 VdbeComment((v, "for %s", pIdx->zName));
118183 if( pIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){
118184 sqlite3SetMakeRecordP5(v, pIdx->pTable);
118192 if( isUpdate && pPk==pIdx && pkChng==0 ){
118198 onError = pIdx->onError;
118210 if( pUpIdx==pIdx ){
118229 if( (ix==0 && pIdx->pNext==0) /* Condition 3 */
118230 && pPk==pIdx /* Condition 2 */
118245 regIdx, pIdx->nKeyCol); VdbeCoverage(v);
118248 regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField);
118263 if( pIdx!=pPk ){
118266 x = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[i]);
118282 int regCmp = (IsPrimaryKeyIndex(pIdx) ? regIdx : regR);
118313 sqlite3UniqueConstraint(pParse, onError, pIdx);
118318 sqlite3UpsertDoUpdate(pParse, pUpsert, pTab, pIdx, iIdxCur+ix);
118338 (pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), iThisCur);
118343 if( pUpIdx==pIdx ){
118406 Index *pIdx; /* An index being inserted or updated */
118421 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
118424 if( pIdx->pPartIdxWhere ){
118429 if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
118447 pIdx->uniqNotNull ? pIdx->nKeyCol: pIdx->nColumn);
118511 Index *pIdx;
118534 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
118536 assert( pIdx->pSchema==pTab->pSchema );
118537 if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
118542 sqlite3VdbeAddOp3(v, op, iIdxCur, pIdx->tnum, iDb);
118543 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
118545 VdbeComment((v, "%s", pIdx->zName));
122375 Index *pIdx;
122387 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
122389 pIdx->zName,
122390 pIdx->szIdxRow,
122391 pIdx->aiRowLogEst[0],
122392 pIdx->hasStat1);
122401 Index *pIdx;
122403 pIdx = sqlite3FindIndex(db, zRight, zDb);
122404 if( pIdx ){
122405 int iIdxDb = sqlite3SchemaToIndex(db, pIdx->pSchema);
122410 mx = pIdx->nColumn;
122414 mx = pIdx->nKeyCol;
122417 pTab = pIdx->pTable;
122421 i16 cnum = pIdx->aiColumn[i];
122426 pIdx->aSortOrder[i],
122427 pIdx->azColl[i],
122428 i<pIdx->nKeyCol);
122437 Index *pIdx;
122445 for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){
122449 pIdx->zName,
122450 IsUniqueIndex(pIdx),
122451 azOrigin[pIdx->idxType],
122452 pIdx->pPartIdxWhere!=0);
122565 Index *pIdx; /* Index in the parent table */
122601 pIdx = 0;
122603 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, 0);
122605 if( pIdx==0 ){
122608 sqlite3VdbeAddOp3(v, OP_OpenRead, i, pIdx->tnum, iTabDb);
122609 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
122622 pIdx = 0;
122625 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols);
122642 if( pIdx ){
122644 sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
122753 Index *pIdx; /* An index on pTab */
122756 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){ cnt++; }
122763 Index *pIdx;
122765 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
122766 aRoot[++cnt] = pIdx->tnum;
122790 Index *pIdx, *pPk;
122804 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
122857 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
122860 if( pPk==pIdx ) continue;
122861 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
122863 pPrior = pIdx;
122867 pIdx->nColumn); VdbeCoverage(v);
122872 jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName);
122879 if( IsUniqueIndex(pIdx) ){
122883 for(kk=0; kk<pIdx->nKeyCol; kk++){
122884 int iCol = pIdx->aiColumn[kk];
122894 pIdx->nKeyCol); VdbeCoverage(v);
122908 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
122909 if( pPk==pIdx ) continue;
122913 sqlite3VdbeLoadString(v, 4, pIdx->zName);
123225 Index *pIdx; /* An index of the table */
123251 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
123252 if( !pIdx->hasStat1 ){
129150 Index *pIdx;
129151 for(pIdx=pTab->pIndex;
129152 pIdx && sqlite3StrICmp(pIdx->zName, zIndexedBy);
129153 pIdx=pIdx->pNext
129155 if( !pIdx ){
129160 pFrom->pIBIndex = pIdx;
130065 Index *pIdx /* Index used to optimize scan, or NULL */
130068 int bCover = (pIdx!=0 && (HasRowid(pTab) || !IsPrimaryKeyIndex(pIdx)));
130072 bCover ? pIdx->zName : ""
131166 Index *pIdx; /* Iterator variable */
131184 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
131185 if( pIdx->bUnordered==0
131186 && pIdx->szIdxRow<pTab->szTabRow
131187 && pIdx->pPartIdxWhere==0
131188 && (!pBest || pIdx->szIdxRow<pBest->szIdxRow)
131190 pBest = pIdx;
132795 Index *pIdx, /* The index to check */
132800 i16 iIdxCol = pIdx->aiColumn[iCol];
132806 assert( pIdx->aColExpr!=0 );
132807 assert( pIdx->aColExpr->a[iCol].pExpr!=0 );
132808 return sqlite3ExprReferencesUpdatedColumn(pIdx->aColExpr->a[iCol].pExpr,
132825 Index *pIdx, /* The index to check */
132829 if( pIdx->pPartIdxWhere==0 ) return 0;
132830 return sqlite3ExprReferencesUpdatedColumn(pIdx->pPartIdxWhere,
132856 Index *pIdx; /* For looping over indices */
132960 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){
132961 if( pPk==pIdx ){
133059 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
133061 if( chngKey || hasFK>1 || pIdx==pPk
133062 || indexWhereClauseMightChange(pIdx,aXRef,chngRowid)
133065 pParse->nMem += pIdx->nColumn;
133068 for(i=0; i<pIdx->nKeyCol; i++){
133069 if( indexColumnIsBeingUpdated(pIdx, i, aXRef, chngRowid) ){
133071 pParse->nMem += pIdx->nColumn;
133072 if( onError==OE_Default && pIdx->onError==OE_Replace ){
133780 Index *pIdx; /* One of the indexes of pTab */
133830 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
133832 if( !IsUniqueIndex(pIdx) ) continue;
133833 if( pTarget->nExpr!=pIdx->nKeyCol ) continue;
133834 if( pIdx->pPartIdxWhere ){
133837 pIdx->pPartIdxWhere, iCursor)!=0 ){
133841 nn = pIdx->nKeyCol;
133844 sCol[0].u.zToken = (char*)pIdx->azColl[ii];
133845 if( pIdx->aiColumn[ii]==XN_EXPR ){
133846 assert( pIdx->aColExpr!=0 );
133847 assert( pIdx->aColExpr->nExpr>ii );
133848 pExpr = pIdx->aColExpr->a[ii].pExpr;
133855 sCol[1].iColumn = pIdx->aiColumn[ii];
133873 pUpsert->pUpsertIdx = pIdx;
133894 Index *pIdx, /* The UNIQUE constraint that failed */
133906 if( pIdx && iCur!=iDataCur ){
133922 k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[i]);
133924 VdbeComment((v, "%s.%s", pIdx->zName,
135141 Index *pIdx;
135157 pIdx = pNew->pIndex;
135158 if( pIdx ){
135159 assert( pIdx->pNext==0 );
135160 pTab->pIndex = pIdx;
135162 pIdx->pTable = pTab;
136127 Index *pIdx /* Must be compatible with this index, if not NULL */
136238 static const char *explainIndexColumnName(Index *pIdx, int i){
136239 i = pIdx->aiColumn[i];
136242 return pIdx->pTable->aCol[i].zName;
136255 Index *pIdx, /* Index to read column names from */
136269 sqlite3_str_appendall(pStr, explainIndexColumnName(pIdx, iTerm+i));
136373 Index *pIdx;
136376 pIdx = pLoop->u.btree.pIndex;
136378 if( !HasRowid(pItem->pTab) && IsPrimaryKeyIndex(pIdx) ){
136393 sqlite3_str_appendf(&str, zFmt, pIdx->zName);
136882 Index *pIdx; /* The index being used for this loop */
136895 pIdx = pLoop->u.btree.pIndex;
136896 assert( pIdx!=0 );
136904 zAff = sqlite3DbStrDup(pParse->db,sqlite3IndexAffinityStr(pParse->db,pIdx));
136912 VdbeComment((v, "begin skip-scan on %s", pIdx->zName));
136921 testcase( pIdx->aiColumn[j]==XN_EXPR );
136922 VdbeComment((v, "%s", explainIndexColumnName(pIdx, j)));
137021 Index *pIdx; /* The index used to access the table */
137032 assert( pHint->pIdx!=0 );
137035 && sqlite3ColumnOfIndex(pHint->pIdx, pExpr->iColumn)<0
137101 }else if( pHint->pIdx!=0 ){
137103 pExpr->iColumn = sqlite3ColumnOfIndex(pHint->pIdx, pExpr->iColumn);
137145 sHint.pIdx = pLoop->u.btree.pIndex;
137204 if( sHint.pIdx!=0 ){
137218 (sHint.pIdx ? sHint.iIdxCur : sHint.iTabCur), 0, 0,
137246 Index *pIdx, /* Index scan is using */
137254 assert( pIdx->aiColumn[pIdx->nColumn-1]==-1 );
137261 Table *pTab = pIdx->pTable;
137265 for(i=0; i<pIdx->nColumn-1; i++){
137266 assert( pIdx->aiColumn[i]<pTab->nCol );
137267 if( pIdx->aiColumn[i]>=0 ) ai[pIdx->aiColumn[i]+1] = i+1;
137345 Index *pIdx, /* The Index */
137354 aColExpr = pIdx->aColExpr;
137362 if( pIdx->aiColumn[iIdxCol]!=XN_EXPR ) continue;
137426 Index *pIdx = 0; /* Index used by loop (if any) */
137763 pIdx = pLoop->u.btree.pIndex;
137780 && (pIdx->nKeyCol>nEq)
137812 testcase( pIdx->aSortOrder[nEq]==SQLITE_SO_DESC );
137815 pLevel->iLikeRepCntr |= bRev ^ (pIdx->aSortOrder[nEq]==SQLITE_SO_DESC);
137819 j = pIdx->aiColumn[nEq];
137820 if( (j>=0 && pIdx->pTable->aCol[j].notNull==0) || j==XN_EXPR ){
137831 if( (nEq<pIdx->nKeyCol && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC))
137832 || (bRev && pIdx->nKeyCol==nEq)
137967 }else if( HasRowid(pIdx->pTable) ){
137977 codeDeferredSeek(pWInfo, pIdx, iCur, iIdxCur);
137980 Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
137983 k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
138006 whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
138013 if( pIdx->pPartIdxWhere ){
138014 whereApplyPartialIndexConstraints(pIdx->pPartIdxWhere, iCur, pWC);
138032 if( omitTable ) pIdx = 0;
138373 iLoop = (pIdx ? 1 : 2);
138394 if( iLoop==1 && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
139462 Index *pIdx;
139467 for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){
139468 if( pIdx->aColExpr==0 ) continue;
139469 for(i=0; i<pIdx->nKeyCol; i++){
139470 if( pIdx->aiColumn[i]!=XN_EXPR ) continue;
139471 if( sqlite3ExprCompareSkip(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){
140452 Index *pIdx /* Must be compatible with this index */
140464 if( pIdx ){
140466 iColumn = pIdx->aiColumn[j];
140468 pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr;
140469 pScan->zCollName = pIdx->azColl[j];
140472 }else if( iColumn==pIdx->pTable->iPKey ){
140475 pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
140476 pScan->zCollName = pIdx->azColl[j];
140516 Index *pIdx /* Must be compatible with this index, if not NULL */
140522 p = whereScanInit(&scan, pWC, iCur, iColumn, op, pIdx);
140548 Index *pIdx, /* Index to match column of */
140552 const char *zColl = pIdx->azColl[iCol];
140557 && p->iColumn==pIdx->aiColumn[iCol]
140573 static int indexColumnNotNull(Index *pIdx, int iCol){
140575 assert( pIdx!=0 );
140576 assert( iCol>=0 && iCol<pIdx->nColumn );
140577 j = pIdx->aiColumn[iCol];
140579 return pIdx->pTable->aCol[j].notNull;
140603 Index *pIdx;
140636 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
140637 if( !IsUniqueIndex(pIdx) ) continue;
140638 for(i=0; i<pIdx->nKeyCol; i++){
140639 if( 0==sqlite3WhereFindTerm(pWC, iBase, i, ~(Bitmask)0, WO_EQ, pIdx) ){
140640 if( findIndexCol(pParse, pDistinct, iBase, pIdx, i)<0 ) break;
140641 if( indexColumnNotNull(pIdx, i)==0 ) break;
140644 if( i==pIdx->nKeyCol ){
140800 Index *pIdx; /* Object describing the transient index */
140891 pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed);
140892 if( pIdx==0 ) goto end_auto_index_create;
140893 pLoop->u.btree.pIndex = pIdx;
140894 pIdx->zName = "auto-index";
140895 pIdx->pTable = pTable;
140907 pIdx->aiColumn[n] = pTerm->u.leftColumn;
140909 pIdx->azColl[n] = pColl ? pColl->zName : sqlite3StrBINARY;
140920 pIdx->aiColumn[n] = i;
140921 pIdx->azColl[n] = sqlite3StrBINARY;
140927 pIdx->aiColumn[n] = i;
140928 pIdx->azColl[n] = sqlite3StrBINARY;
140933 pIdx->aiColumn[n] = XN_ROWID;
140934 pIdx->azColl[n] = sqlite3StrBINARY;
140940 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
140962 pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0
141200 Index *pIdx, /* Index to consider domain of */
141205 IndexSample *aSample = pIdx->aSample;
141219 assert( pIdx->nSample>0 );
141220 assert( pRec->nField>0 && pRec->nField<=pIdx->nSampleCol );
141268 iSample = pIdx->nSample * nField;
141309 assert( i<pIdx->nSample );
141319 assert( i<=pIdx->nSample && i>=0 );
141321 assert( i==pIdx->nSample
141353 if( i>=pIdx->nSample ){
141354 iUpper = sqlite3LogEstToInt(pIdx->aiRowLogEst[0]);
141370 aStat[1] = pIdx->aAvgEq[nField-1];
141407 SQLITE_PRIVATE char sqlite3IndexColumnAffinity(sqlite3 *db, Index *pIdx, int iCol){
141408 assert( iCol>=0 && iCol<pIdx->nColumn );
141409 if( !pIdx->zColAff ){
141410 if( sqlite3IndexAffinityStr(db, pIdx)==0 ) return SQLITE_AFF_BLOB;
141412 return pIdx->zColAff[iCol];
142431 Index *pIdx, /* The index to be used for a inequality constraint */
142438 nCmp = MIN(nCmp, (pIdx->nColumn - nEq));
142459 || pLhs->iColumn!=pIdx->aiColumn[i+nEq]
142460 || pIdx->aSortOrder[i+nEq]!=pIdx->aSortOrder[nEq]
142467 idxaff = sqlite3TableColumnAffinity(pIdx->pTable, pLhs->iColumn);
142472 if( sqlite3StrICmp(pColl->zName, pIdx->azColl[i+nEq]) ) break;
144495 Index *pIdx;
144519 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
144522 if( !IsUniqueIndex(pIdx)
144523 || pIdx->pPartIdxWhere!=0
144524 || pIdx->nKeyCol>ArraySize(pLoop->aLTermSpace)
144526 opMask = pIdx->uniqNotNull ? (WO_EQ|WO_IS) : WO_EQ;
144527 for(j=0; j<pIdx->nKeyCol; j++){
144528 pTerm = sqlite3WhereFindTerm(pWC, iCur, j, 0, opMask, pIdx);
144533 if( j!=pIdx->nKeyCol ) continue;
144535 if( pIdx->isCovering || (pItem->colUsed & pIdx->colNotIdxed)==0 ){
144540 pLoop->u.btree.pIndex = pIdx;
145259 Index *pIdx;
145264 && (pIdx = pLoop->u.btree.pIndex)->hasStat1
145266 && pIdx->aiRowLogEst[n]>=36
145364 Index *pIdx = 0;
145416 pIdx = pLoop->u.btree.pIndex;
145418 pIdx = pLevel->u.pCovidx;
145420 if( pIdx
145421 && (pWInfo->eOnePass==ONEPASS_OFF || !HasRowid(pIdx->pTable))
145440 assert( pIdx->pTable==pTab );
145446 x = sqlite3ColumnOfIndex(pIdx, x);
189965 sqlite3_stmt *pIdx = pIter->pIdxIter;
189966 rc = sqlite3_bind_text(pIdx, 1, pIter->zTbl, -1, SQLITE_STATIC);
202012 static int sqlite3Fts5ExprFirst(Fts5Expr*, Fts5Index *pIdx, i64 iMin, int bDesc);
207067 static int sqlite3Fts5ExprFirst(Fts5Expr *p, Fts5Index *pIdx, i64 iFirst, int bDesc){
207071 p->pIndex = pIdx;
213581 Fts5Index *pIdx;
218844 Fts5Index *pIdx = pCtx->pStorage->pIndex;
218850 return sqlite3Fts5IndexWrite(pIdx, pCtx->iCol, pCtx->szCol-1, pToken, nToken);