From: drh Date: Tue, 29 Sep 2015 17:20:14 +0000 (+0000) Subject: Use symbolic names XN_ROWID and XN_EXPR in place of the (-1) and (-2) X-Git-Tag: version-3.9.0~48 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4b92f98ccc298dfcd00c323fa912a22876a4e245;p=thirdparty%2Fsqlite.git Use symbolic names XN_ROWID and XN_EXPR in place of the (-1) and (-2) magic numbers in Index.aiColumn[]. Add asserts to help verify that Index.aiColumn[] is always used correctly. Fix one place in FK processing where Index.aiColumn[] was not being used correctly. FossilOrigin-Name: 7d272aa62cd4cbbf4b5d04e3b918de27671e8301 --- diff --git a/manifest b/manifest index 35e142bdf3..cbc2fc7692 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\ssqlite3_index_info.idxFlags\sfield,\sallowing\sxBestIndex()\simplementations\sto\sspecify\sto\sSQLite\sthat\sa\sstrategy\smay\svisit\sat\smost\sone\srow.\sAdd\ssupport\sfor\sthis\sto\sfts3/4.\sOmit\sthe\sstatement\sjournal\sfrom\svirtual\stable\sUPDATE\sand\sDELETE\soperations\sthat\sare\sguaranteed\snot\sto\saffect\smore\sthan\sone\srow. -D 2015-09-29T16:47:53.132 +C Use\ssymbolic\snames\sXN_ROWID\sand\sXN_EXPR\sin\splace\sof\sthe\s(-1)\sand\s(-2)\nmagic\snumbers\sin\sIndex.aiColumn[].\s\sAdd\sasserts\sto\shelp\sverify\sthat\nIndex.aiColumn[]\sis\salways\sused\scorrectly.\s\sFix\sone\splace\sin\sFK\sprocessing\nwhere\sIndex.aiColumn[]\swas\snot\sbeing\sused\scorrectly. +D 2015-09-29T17:20:14.958 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2143eeef6d0cc26006ae5fc4bb242a4a8b973412 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -285,22 +285,22 @@ F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 F src/btree.c 164583151135a3764672c2c25aa8e4fa06bdb12b F src/btree.h 40189aefdc2b830d25c8b58fd7d56538481bfdd7 F src/btreeInt.h 8177c9ab90d772d6d2c6c517e05bed774b7c92c0 -F src/build.c 361f58b73aad7804f5706bf62d210bd9cd608041 +F src/build.c 0549b56722f15c146ca21f82a33838365c2031f0 F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c addcd8160b081131005d5bc2d34adf20c1c5c92f F src/ctime.c 5a0b735dc95604766f5dac73973658eef782ee8b F src/date.c fb1c99172017dcc8e237339132c91a21a0788584 F src/dbstat.c e637e7a7ff40ef32132a418c6fdf1cfb63aa27c7 -F src/delete.c 46bb5e217f83af68574ccb613421485578c41ba8 -F src/expr.c 3a76afcdac925294c39903b7002ddb9e5fd29863 +F src/delete.c 35c939eb8bacc9dd8a6715964e5f69feb8c20e44 +F src/expr.c 36381822e617cb3586d4be1af2cbc3dd5f2b84eb F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb -F src/fkey.c 83e1baba999bed3144ea5a2143fc922edf51135f +F src/fkey.c 31900763094a3736a5fc887469202eb579fef2d0 F src/func.c ecdd69ec6a1e406f04cc73324be2ebbf6354197f F src/global.c 508e4087f7b41d688e4762dcf4d4fe28cfbc87f9 F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 -F src/insert.c 81d6bf397c05b4e8ddc4af2ff6637c113ee7e37a +F src/insert.c a9b7f200081fa1b482a4ccac05165e10371ae9e0 F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c d344a95d60c24e2f490ee59db9784b1b17439012 @@ -333,7 +333,7 @@ F src/parse.y f599aa5e871a493330d567ced93de696f61f48f7 F src/pcache.c 24be750c79272e0ca7b6e007bc94999700f3e5ef F src/pcache.h 9968603796240cdf83da7e7bef76edf90619cea9 F src/pcache1.c e822007159d53a7ea7aa040d6e28964ddb6de083 -F src/pragma.c 577f70c3899ee6fc2e5a4c37158c69c1c23f71e7 +F src/pragma.c 234814978bcd35bce6e2874dfb2f5b5e28e7fb38 F src/pragma.h 631a91c8b0e6ca8f051a1d8a4a0da4150e04620a F src/prepare.c 82e5db1013846a819f198336fed72c44c974e7b1 F src/printf.c 0c4bcdd1c2e2521024f0a69cb5eb334f86b3652a @@ -345,7 +345,7 @@ F src/shell.c a11b20da4c6630e0e8f83c47ce36f717dd0422f0 F src/sqlite.h.in 4b76d74d69af48c534c58fb723137dc6944bdedc F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3ext.h 64350bf36833a56ad675e27392a913f417c5c308 -F src/sqliteInt.h b6516bb2727876348b4e05aadd12237797626270 +F src/sqliteInt.h 681f38fc0decba6edcf3bad230e76fa5bf55a7bf F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c f266ad8a2892d659b74f0f50cb6a88b6e7c12179 F src/table.c 51b46b2a62d1b3a959633d593b89bab5e2c9155e @@ -399,7 +399,7 @@ F src/threads.c bbfb74450643cb5372a43ad4f6cffd7e9dfcecb0 F src/tokenize.c 83c6ed569423a3af83a83973b444cf7123be33a6 F src/treeview.c 154f0acc622fa3514de8777dcedf4c8a8802b4ce F src/trigger.c 322f23aad694e8f31d384dcfa386d52a48d3c52f -F src/update.c d8f0afe1a1c66b97cbd87e5236f4e71d35ab4840 +F src/update.c a134027f59c7eb6e63ed18e2d5dd8ef0ce7f8ff8 F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c fc612367108b74573c5fd13a85d0a23027f438bd F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 @@ -408,7 +408,7 @@ F src/vdbe.h 4bc88bd0e06f8046ee6ab7487c0015e85ad949ad F src/vdbeInt.h 8b867eac234e28627ffcace3cd4b4b79bbec664b F src/vdbeapi.c 020681b943e77766b32ae1cddf86d7831b7374ca F src/vdbeaux.c fd00b489ab3f44f2dca1e4344faf289b7bfcf649 -F src/vdbeblob.c 1d7b97115e7bbac4c318db416d2ca83fc779544a +F src/vdbeblob.c 565fabd302f5fca3bdf3d56cac330483616a39b6 F src/vdbemem.c 19b3036aa4d676e7103b0fb5efd6327da455f915 F src/vdbesort.c f5009e7a35e3065635d8918b9a31f498a499976b F src/vdbetrace.c 8befe829faff6d9e6f6e4dee5a7d3f85cc85f1a0 @@ -417,9 +417,9 @@ F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb F src/wal.c 18b0ed49830cf04fe2d68224b41838a73ac6cd24 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 2e14d17f592d176b6dc879c33fbdec4fbccaa2ba -F src/where.c b7f928b6b8ce091f385ba5ac2394928608431550 +F src/where.c 4c4646675e794ac71e701289edefd7cd81bac844 F src/whereInt.h 7892bb54cf9ca0ae5c7e6094491b94c9286dc647 -F src/wherecode.c a87238178f8c300fd27afec54326ea8d0a18baa2 +F src/wherecode.c a32bf1f304f6328e3eefcb82e70bd86836cff343 F src/whereexpr.c 2473e4350e30f9b55d1c6a8f66ca23c689f23f1d F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd @@ -1389,7 +1389,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 77948b5eceab92a77c39d0864ac15ad453a76fd7 0e317dda5dfd35b742afd70dacb5bfb39aa3fc4a -R d39a034a4821b5c42018f04d74a8aeb2 -U dan -Z 28a594c5d9670d5cb6f4428303834152 +P a1d08fd3d0419da8c22355d48c6d83eed6fd7e07 +R 52625b1830d3c09e89f8505fdc133a11 +U drh +Z 6b238da064de6e3b5f5d0b4365b7caf0 diff --git a/manifest.uuid b/manifest.uuid index 2b74ea5ad5..5810842471 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a1d08fd3d0419da8c22355d48c6d83eed6fd7e07 \ No newline at end of file +7d272aa62cd4cbbf4b5d04e3b918de27671e8301 \ No newline at end of file diff --git a/src/build.c b/src/build.c index c0bd81b1a0..ea89e501dc 100644 --- a/src/build.c +++ b/src/build.c @@ -3136,7 +3136,7 @@ Index *sqlite3CreateIndex( /* Analyze the list of expressions that form the terms of the index and ** report any errors. In the common case where the expression is exactly ** a table column, store that column in aiColumn[]. For general expressions, - ** populate pIndex->aColExpr and store -2 in aiColumn[]. + ** populate pIndex->aColExpr and store XN_EXPR (-2) in aiColumn[]. ** ** TODO: Issue a warning if two or more columns of the index are identical. ** TODO: Issue a warning if the table primary key is used as part of the @@ -3165,8 +3165,8 @@ Index *sqlite3CreateIndex( pListItem = &pCopy->a[i]; } } - j = -2; - pIndex->aiColumn[i] = -2; + j = XN_EXPR; + pIndex->aiColumn[i] = XN_EXPR; pIndex->uniqNotNull = 0; }else{ j = pCExpr->iColumn; @@ -3219,7 +3219,7 @@ Index *sqlite3CreateIndex( } assert( i==pIndex->nColumn ); }else{ - pIndex->aiColumn[i] = -1; + pIndex->aiColumn[i] = XN_ROWID; pIndex->azColl[i] = "BINARY"; } sqlite3DefaultRowEst(pIndex); diff --git a/src/delete.c b/src/delete.c index 6a512017e7..faef3a814e 100644 --- a/src/delete.c +++ b/src/delete.c @@ -422,7 +422,7 @@ void sqlite3DeleteFrom( /* Extract the rowid or primary key for the current row */ if( pPk ){ for(i=0; iaiColumn[i]>=(-1) ); + assert( pPk->aiColumn[i]>=0 ); sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, pPk->aiColumn[i], iPk+i); } @@ -858,7 +858,7 @@ int sqlite3GenerateIndexKey( for(j=0; jaiColumn[j]==pIdx->aiColumn[j] - && pPrior->aiColumn[j]>=(-1) + && pPrior->aiColumn[j]!=XN_EXPR ){ /* This column was already computed by the previous index */ continue; diff --git a/src/expr.c b/src/expr.c index 3141cd9dbd..b52e814f3c 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2443,15 +2443,15 @@ void sqlite3ExprCodeLoadIndexColumn( int regOut /* Store the index column value in this register */ ){ i16 iTabCol = pIdx->aiColumn[iIdxCol]; - if( iTabCol>=(-1) ){ + if( iTabCol==XN_EXPR ){ + assert( pIdx->aColExpr ); + assert( pIdx->aColExpr->nExpr>iIdxCol ); + pParse->iSelfTab = iTabCur; + sqlite3ExprCode(pParse, pIdx->aColExpr->a[iIdxCol].pExpr, regOut); + }else{ sqlite3ExprCodeGetColumnOfTable(pParse->pVdbe, pIdx->pTable, iTabCur, iTabCol, regOut); - return; } - assert( pIdx->aColExpr ); - assert( pIdx->aColExpr->nExpr>iIdxCol ); - pParse->iSelfTab = iTabCur; - sqlite3ExprCode(pParse, pIdx->aColExpr->a[iIdxCol].pExpr, regOut); } /* diff --git a/src/fkey.c b/src/fkey.c index a087889f4c..b55e2a9813 100644 --- a/src/fkey.c +++ b/src/fkey.c @@ -252,6 +252,8 @@ int sqlite3FkLocateIndex( char *zDfltColl; /* Def. collation for column */ char *zIdxCol; /* Name of indexed column */ + if( iCol<0 ) break; /* No foreign keys against expression indexes */ + /* If the index uses a collation sequence that is different from ** the default collation sequence for the column, this index is ** unusable. Bail out early in this case. */ @@ -404,6 +406,7 @@ static void fkLookupParent( for(i=0; iaiColumn[i]+1+regData; + assert( pIdx->aiColumn[i]>=0 ); assert( aiCol[i]!=pTab->iPKey ); if( pIdx->aiColumn[i]==pTab->iPKey ){ /* The parent key is a composite key that includes the IPK column */ @@ -612,6 +615,7 @@ static void fkScanChildren( assert( pIdx!=0 ); for(i=0; inKeyCol; i++){ i16 iCol = pIdx->aiColumn[i]; + assert( iCol>=0 ); pLeft = exprTableRegister(pParse, pTab, regData, iCol); pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, iCol); pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0); @@ -931,6 +935,7 @@ void sqlite3FkCheck( if( aiCol[i]==pTab->iPKey ){ aiCol[i] = -1; } + assert( pIdx==0 || pIdx->aiColumn[i]>=0 ); #ifndef SQLITE_OMIT_AUTHORIZATION /* Request permission to read the parent key columns. If the ** authorization callback returns SQLITE_IGNORE, behave as if any @@ -1062,7 +1067,10 @@ u32 sqlite3FkOldmask( Index *pIdx = 0; sqlite3FkLocateIndex(pParse, pTab, p, &pIdx, 0); if( pIdx ){ - for(i=0; inKeyCol; i++) mask |= COLUMN_MASK(pIdx->aiColumn[i]); + for(i=0; inKeyCol; i++){ + assert( pIdx->aiColumn[i]>=0 ); + mask |= COLUMN_MASK(pIdx->aiColumn[i]); + } } } } @@ -1185,6 +1193,7 @@ static Trigger *fkActionTrigger( iFromCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom; assert( iFromCol>=0 ); assert( pIdx!=0 || (pTab->iPKey>=0 && pTab->iPKeynCol) ); + assert( pIdx==0 || pIdx->aiColumn[i]>=0 ); tToCol.z = pTab->aCol[pIdx ? pIdx->aiColumn[i] : pTab->iPKey].zName; tFromCol.z = pFKey->pFrom->aCol[iFromCol].zName; diff --git a/src/insert.c b/src/insert.c index 3ade95e4ec..785e57d02c 100644 --- a/src/insert.c +++ b/src/insert.c @@ -90,11 +90,11 @@ const char *sqlite3IndexAffinityStr(sqlite3 *db, Index *pIdx){ i16 x = pIdx->aiColumn[n]; if( x>=0 ){ pIdx->zColAff[n] = pTab->aCol[x].affinity; - }else if( x==(-1) ){ + }else if( x==XN_ROWID ){ pIdx->zColAff[n] = SQLITE_AFF_INTEGER; }else{ char aff; - assert( x==(-2) ); + assert( x==XN_EXPR ); assert( pIdx->aColExpr!=0 ); aff = sqlite3ExprAffinity(pIdx->aColExpr->a[n].pExpr); if( aff==0 ) aff = SQLITE_AFF_BLOB; @@ -1408,13 +1408,13 @@ void sqlite3GenerateConstraintChecks( for(i=0; inColumn; i++){ int iField = pIdx->aiColumn[i]; int x; - if( iField==(-2) ){ + if( iField==XN_EXPR ){ pParse->ckBase = regNewData+1; sqlite3ExprCode(pParse, pIdx->aColExpr->a[i].pExpr, regIdx+i); pParse->ckBase = 0; VdbeComment((v, "%s column %d", pIdx->zName, i)); }else{ - if( iField==(-1) || iField==pTab->iPKey ){ + if( iField==XN_ROWID || iField==pTab->iPKey ){ if( regRowid==regIdx+i ) continue; /* ROWID already in regIdx+i */ x = regNewData; regRowid = pIdx->pPartIdxWhere ? -1 : regIdx+i; @@ -1473,6 +1473,7 @@ void sqlite3GenerateConstraintChecks( ** store it in registers regR..regR+nPk-1 */ if( pIdx!=pPk ){ for(i=0; inKeyCol; i++){ + assert( pPk->aiColumn[i]>=0 ); x = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[i]); sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i); VdbeComment((v, "%s.%s", pTab->zName, @@ -1494,6 +1495,7 @@ void sqlite3GenerateConstraintChecks( for(i=0; inKeyCol; i++){ char *p4 = (char*)sqlite3LocateCollSeq(pParse, pPk->azColl[i]); x = pPk->aiColumn[i]; + assert( x>=0 ); if( i==(pPk->nKeyCol-1) ){ addrJump = addrUniqueOk; op = OP_Eq; @@ -1745,7 +1747,7 @@ static int xferCompatibleIndex(Index *pDest, Index *pSrc){ if( pSrc->aiColumn[i]!=pDest->aiColumn[i] ){ return 0; /* Different columns indexed */ } - if( pSrc->aiColumn[i]==(-2) ){ + if( pSrc->aiColumn[i]==XN_EXPR ){ assert( pSrc->aColExpr!=0 && pDest->aColExpr!=0 ); if( sqlite3ExprCompare(pSrc->aColExpr->a[i].pExpr, pDest->aColExpr->a[i].pExpr, -1)!=0 ){ diff --git a/src/pragma.c b/src/pragma.c index 1edc66daf8..e5e7e54a29 100644 --- a/src/pragma.c +++ b/src/pragma.c @@ -1524,7 +1524,7 @@ void sqlite3Pragma( int kk; for(kk=0; kknKeyCol; kk++){ int iCol = pIdx->aiColumn[kk]; - assert( iCol!=(-1) && iColnCol ); + assert( iCol!=XN_ROWID && iColnCol ); if( iCol>=0 && pTab->aCol[iCol].notNull ) continue; sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk); VdbeCoverage(v); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index b32cc21bbb..6c9bb06f69 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1917,6 +1917,12 @@ struct Index { /* Return true if index X is a UNIQUE index */ #define IsUniqueIndex(X) ((X)->onError!=OE_None) +/* The Index.aiColumn[] values are normally positive integer. But +** there are some negative values that have special meaning: +*/ +#define XN_ROWID (-1) /* Indexed column is the rowid */ +#define XN_EXPR (-2) /* Indexed column is an expression */ + /* ** Each sample stored in the sqlite_stat3 table is represented in memory ** using a structure of this type. See documentation at the top of the diff --git a/src/update.c b/src/update.c index ba5d0380af..74f247bb28 100644 --- a/src/update.c +++ b/src/update.c @@ -384,7 +384,7 @@ void sqlite3Update( if( pWInfo==0 ) goto update_cleanup; okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass); for(i=0; iaiColumn[i]>=(-1) ); + assert( pPk->aiColumn[i]>=0 ); sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pPk->aiColumn[i], iPk+i); } diff --git a/src/vdbeblob.c b/src/vdbeblob.c index 2cdc3edb00..30a329189e 100644 --- a/src/vdbeblob.c +++ b/src/vdbeblob.c @@ -248,7 +248,7 @@ int sqlite3_blob_open( int j; for(j=0; jnKeyCol; j++){ /* FIXME: Be smarter about indexes that use expressions */ - if( pIdx->aiColumn[j]==iCol || pIdx->aiColumn[j]==(-2) ){ + if( pIdx->aiColumn[j]==iCol || pIdx->aiColumn[j]==XN_EXPR ){ zFault = "indexed"; } } diff --git a/src/where.c b/src/where.c index 2be05a6752..af8e2f35fd 100644 --- a/src/where.c +++ b/src/where.c @@ -189,12 +189,12 @@ static WhereTerm *whereScanNext(WhereScan *pScan){ while( pScan->iEquiv<=pScan->nEquiv ){ iCur = pScan->aiCur[pScan->iEquiv-1]; iColumn = pScan->aiColumn[pScan->iEquiv-1]; - if( iColumn==(-2) && pScan->pIdxExpr==0 ) return 0; + if( iColumn==XN_EXPR && pScan->pIdxExpr==0 ) return 0; while( (pWC = pScan->pWC)!=0 ){ for(pTerm=pWC->a+k; knTerm; k++, pTerm++){ if( pTerm->leftCursor==iCur && pTerm->u.leftColumn==iColumn - && (iColumn!=(-2) + && (iColumn!=XN_EXPR || sqlite3ExprCompare(pTerm->pExpr->pLeft,pScan->pIdxExpr,iCur)==0) && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin)) ){ @@ -288,7 +288,7 @@ static WhereTerm *whereScanInit( if( pIdx ){ j = iColumn; iColumn = pIdx->aiColumn[j]; - if( iColumn==(-2) ) pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr; + if( iColumn==XN_EXPR ) pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr; } if( pIdx && iColumn>=0 ){ pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity; @@ -727,7 +727,7 @@ static void constructAutomaticIndex( } } assert( n==nKeyCol ); - pIdx->aiColumn[n] = -1; + pIdx->aiColumn[n] = XN_ROWID; pIdx->azColl[n] = "BINARY"; /* Create the automatic index */ @@ -2242,7 +2242,9 @@ static int whereLoopAddBtreeIndex( int iCol = pProbe->aiColumn[saved_nEq]; pNew->wsFlags |= WHERE_COLUMN_EQ; assert( saved_nEq==pNew->u.btree.nEq ); - if( iCol==(-1) || (iCol>0 && nInMul==0 && saved_nEq==pProbe->nKeyCol-1) ){ + if( iCol==XN_ROWID + || (iCol>0 && nInMul==0 && saved_nEq==pProbe->nKeyCol-1) + ){ if( iCol>=0 && pProbe->uniqNotNull==0 ){ pNew->wsFlags |= WHERE_UNQ_WANTED; }else{ @@ -2442,7 +2444,7 @@ static int indexMightHelpWithOrderBy( } }else if( (aColExpr = pIndex->aColExpr)!=0 ){ for(jj=0; jjnKeyCol; jj++){ - if( pIndex->aiColumn[jj]!=(-2) ) continue; + if( pIndex->aiColumn[jj]!=XN_EXPR ) continue; if( sqlite3ExprCompare(pExpr,aColExpr->a[jj].pExpr,iCursor)==0 ){ return 1; } @@ -3230,7 +3232,8 @@ static i8 wherePathSatisfiesOrderBy( nKeyCol = pIndex->nKeyCol; nColumn = pIndex->nColumn; assert( nColumn==nKeyCol+1 || !HasRowid(pIndex->pTable) ); - assert( pIndex->aiColumn[nColumn-1]==(-1) || !HasRowid(pIndex->pTable)); + assert( pIndex->aiColumn[nColumn-1]==XN_ROWID + || !HasRowid(pIndex->pTable)); isOrderDistinct = IsUniqueIndex(pIndex); } @@ -3262,7 +3265,7 @@ static i8 wherePathSatisfiesOrderBy( revIdx = pIndex->aSortOrder[j]; if( iColumn==pIndex->pTable->iPKey ) iColumn = -1; }else{ - iColumn = -1; + iColumn = XN_ROWID; revIdx = 0; } @@ -4562,6 +4565,7 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){ if( !HasRowid(pTab) ){ Index *pPk = sqlite3PrimaryKeyIndex(pTab); x = pPk->aiColumn[x]; + assert( x>=0 ); } x = sqlite3ColumnOfIndex(pIdx, x); if( x>=0 ){ diff --git a/src/wherecode.c b/src/wherecode.c index f9b56e7c83..a6c45f0321 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -46,8 +46,8 @@ static void explainAppendTerm( */ static const char *explainIndexColumnName(Index *pIdx, int i){ i = pIdx->aiColumn[i]; - if( i==(-2) ) return ""; - if( i==(-1) ) return "rowid"; + if( i==XN_EXPR ) return ""; + if( i==XN_ROWID ) return "rowid"; return pIdx->pTable->aCol[i].zName; } @@ -514,7 +514,7 @@ static int codeAllEqualityTerms( sqlite3VdbeJumpHere(v, j); for(j=0; jaiColumn[j]==(-2) ); + testcase( pIdx->aiColumn[j]==XN_EXPR ); VdbeComment((v, "%s", explainIndexColumnName(pIdx, j))); } }