/ Check-in [55945fc1]
Login

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

Overview
Comment:In sqlite3FindInIndex(), improve internal comments and avoid an unreachable branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | rowvalue
Files: files | file ages | folders
SHA1: 55945fc12f8157e32e6850e41575c0c6422d29e7
User & Date: drh 2016-08-24 18:51:23
Context
2016-08-24
21:24
Improved extended comments of comparison operators when the SQLITE_STOREP2 flags is set on P5. No changes to non-debug code. check-in: bbc1b016 user: drh tags: rowvalue
18:51
In sqlite3FindInIndex(), improve internal comments and avoid an unreachable branch. check-in: 55945fc1 user: drh tags: rowvalue
17:49
Fix more unreachable branches. check-in: 6099c180 user: drh tags: rowvalue
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

  2148   2148   
  2149   2149       /* This function is only called from two places. In both cases the vdbe
  2150   2150       ** has already been allocated. So assume sqlite3GetVdbe() is always
  2151   2151       ** successful here.
  2152   2152       */
  2153   2153       assert(v);
  2154   2154       if( nExpr==1 && pEList->a[0].pExpr->iColumn<0 ){
         2155  +      /* The "x IN (SELECT rowid FROM table)" case */
  2155   2156         int iAddr = sqlite3CodeOnce(pParse);
  2156   2157         VdbeCoverage(v);
  2157   2158   
  2158   2159         sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
  2159   2160         eType = IN_INDEX_ROWID;
  2160   2161   
  2161   2162         sqlite3VdbeJumpHere(v, iAddr);
  2162   2163       }else{
  2163   2164         Index *pIdx;                         /* Iterator variable */
  2164   2165         int affinity_ok = 1;
  2165   2166         int i;
  2166   2167   
  2167   2168         /* Check that the affinity that will be used to perform each 
  2168         -      ** comparison is the same as the affinity of each column. If
  2169         -      ** it not, it is not possible to use any index.  */
         2169  +      ** comparison is the same as the affinity of each column in table
         2170  +      ** on the RHS of the IN operator.  If it not, it is not possible to
         2171  +      ** use any index of the RHS table.  */
  2170   2172         for(i=0; i<nExpr && affinity_ok; i++){
  2171   2173           Expr *pLhs = sqlite3VectorFieldSubexpr(pX->pLeft, i);
  2172   2174           int iCol = pEList->a[i].pExpr->iColumn;
  2173         -        char idxaff = pTab->aCol[iCol].affinity;
         2175  +        char idxaff = pTab->aCol[iCol].affinity;  /* RHS table affinity */
  2174   2176           char cmpaff = sqlite3CompareAffinity(pLhs, idxaff);
         2177  +        testcase( cmpaff==SQLITE_AFF_BLOB );
         2178  +        testcase( cmpaff==SQLITE_AFF_TEXT );
  2175   2179           switch( cmpaff ){
  2176   2180             case SQLITE_AFF_BLOB:
  2177   2181               break;
  2178   2182             case SQLITE_AFF_TEXT:
  2179         -            affinity_ok = (idxaff==SQLITE_AFF_TEXT);
         2183  +            /* sqlite3CompareAffinity() only returns TEXT if one side or the
         2184  +            ** other has no affinity and the other side is TEXT.  Hence,
         2185  +            ** the only way for cmpaff to be TEXT is for idxaff to be TEXT
         2186  +            ** and for the term on the LHS of the IN to have no affinity. */
         2187  +            assert( idxaff==SQLITE_AFF_TEXT );
  2180   2188               break;
  2181   2189             default:
  2182   2190               affinity_ok = sqlite3IsNumericAffinity(idxaff);
  2183   2191           }
  2184   2192         }
  2185   2193   
  2186   2194         /* The collation sequence used by the comparison. If an index is to