/ Check-in [63e625c8]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Merge fixes from trunk. Also fix a reference to the KeyInfo.aSortOrder field, which should now be KeyInfo.aSortFlags
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | nulls-last
Files: files | file ages | folders
SHA3-256: 63e625c8eb06720eef30573aa562e38c90d228a9cf493f8bb59f09e50f0e3168
User & Date: drh 2019-08-22 19:35:24
Context
2019-08-22
21:13
Add additional VDBE coverage macros. check-in: d3531f5b user: drh tags: nulls-last
19:35
Merge fixes from trunk. Also fix a reference to the KeyInfo.aSortOrder field, which should now be KeyInfo.aSortFlags check-in: 63e625c8 user: drh tags: nulls-last
16:38
Fix the likely(), unlikely(), and likelihood() functions so that they have no affinity, just like any other function. Ticket [7e07a3dbf5a8cd26] check-in: 44578865 user: drh tags: trunk
2019-08-21
19:58
Add missing VdbeCoverage() macros to new code. check-in: b1cbcdc6 user: dan tags: nulls-last
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

   102    102     Token s;
   103    103     assert( zC!=0 );
   104    104     sqlite3TokenInit(&s, (char*)zC);
   105    105     return sqlite3ExprAddCollateToken(pParse, pExpr, &s, 0);
   106    106   }
   107    107   
   108    108   /*
   109         -** Skip over any TK_COLLATE operators and any unlikely()
   110         -** or likelihood() function at the root of an expression.
          109  +** Skip over any TK_COLLATE operators.
   111    110   */
   112    111   Expr *sqlite3ExprSkipCollate(Expr *pExpr){
          112  +  while( pExpr && ExprHasProperty(pExpr, EP_Skip) ){
          113  +    assert( pExpr->op==TK_COLLATE );
          114  +    pExpr = pExpr->pLeft;
          115  +  }   
          116  +  return pExpr;
          117  +}
          118  +
          119  +/*
          120  +** Skip over any TK_COLLATE operators and/or any unlikely()
          121  +** or likelihood() or likely() functions at the root of an
          122  +** expression.
          123  +*/
          124  +Expr *sqlite3ExprSkipCollateAndLikely(Expr *pExpr){
   113    125     while( pExpr && ExprHasProperty(pExpr, EP_Skip|EP_Unlikely) ){
   114    126       if( ExprHasProperty(pExpr, EP_Unlikely) ){
   115    127         assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
   116    128         assert( pExpr->x.pList->nExpr>0 );
   117    129         assert( pExpr->op==TK_FUNCTION );
   118    130         pExpr = pExpr->x.pList->a[0].pExpr;
   119    131       }else{
................................................................................
  2175   2187   ** This routine is used to determine if the OP_Affinity operation
  2176   2188   ** can be omitted.  When in doubt return FALSE.  A false negative
  2177   2189   ** is harmless.  A false positive, however, can result in the wrong
  2178   2190   ** answer.
  2179   2191   */
  2180   2192   int sqlite3ExprNeedsNoAffinityChange(const Expr *p, char aff){
  2181   2193     u8 op;
         2194  +  int unaryMinus = 0;
  2182   2195     if( aff==SQLITE_AFF_BLOB ) return 1;
  2183         -  while( p->op==TK_UPLUS || p->op==TK_UMINUS ){ p = p->pLeft; }
         2196  +  while( p->op==TK_UPLUS || p->op==TK_UMINUS ){
         2197  +    if( p->op==TK_UMINUS ) unaryMinus = 1;
         2198  +    p = p->pLeft;
         2199  +  }
  2184   2200     op = p->op;
  2185   2201     if( op==TK_REGISTER ) op = p->op2;
  2186   2202     switch( op ){
  2187   2203       case TK_INTEGER: {
  2188   2204         return aff==SQLITE_AFF_INTEGER || aff==SQLITE_AFF_NUMERIC;
  2189   2205       }
  2190   2206       case TK_FLOAT: {
  2191   2207         return aff==SQLITE_AFF_REAL || aff==SQLITE_AFF_NUMERIC;
  2192   2208       }
  2193   2209       case TK_STRING: {
  2194         -      return aff==SQLITE_AFF_TEXT;
         2210  +      return !unaryMinus && aff==SQLITE_AFF_TEXT;
  2195   2211       }
  2196   2212       case TK_BLOB: {
  2197         -      return 1;
         2213  +      return !unaryMinus;
  2198   2214       }
  2199   2215       case TK_COLUMN: {
  2200   2216         assert( p->iTable>=0 );  /* p cannot be part of a CHECK constraint */
  2201   2217         return p->iColumn<0
  2202   2218             && (aff==SQLITE_AFF_INTEGER || aff==SQLITE_AFF_NUMERIC);
  2203   2219       }
  2204   2220       default: {
................................................................................
  3394   3410   
  3395   3411   /*
  3396   3412   ** Convert a scalar expression node to a TK_REGISTER referencing
  3397   3413   ** register iReg.  The caller must ensure that iReg already contains
  3398   3414   ** the correct value for the expression.
  3399   3415   */
  3400   3416   static void exprToRegister(Expr *pExpr, int iReg){
  3401         -  Expr *p = sqlite3ExprSkipCollate(pExpr);
         3417  +  Expr *p = sqlite3ExprSkipCollateAndLikely(pExpr);
  3402   3418     p->op2 = p->op;
  3403   3419     p->op = TK_REGISTER;
  3404   3420     p->iTable = iReg;
  3405   3421     ExprClearProperty(p, EP_Skip);
  3406   3422   }
  3407   3423   
  3408   3424   /*
................................................................................
  4202   4218   **
  4203   4219   ** If pExpr is a constant, then this routine might generate this
  4204   4220   ** code to fill the register in the initialization section of the
  4205   4221   ** VDBE program, in order to factor it out of the evaluation loop.
  4206   4222   */
  4207   4223   int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
  4208   4224     int r2;
  4209         -  pExpr = sqlite3ExprSkipCollate(pExpr);
         4225  +  pExpr = sqlite3ExprSkipCollateAndLikely(pExpr);
  4210   4226     if( ConstFactorOk(pParse)
  4211   4227      && pExpr->op!=TK_REGISTER
  4212   4228      && sqlite3ExprIsConstantNotJoin(pExpr)
  4213   4229     ){
  4214   4230       *pReg  = 0;
  4215   4231       r2 = sqlite3ExprCodeAtInit(pParse, pExpr, -1);
  4216   4232     }else{
................................................................................
  4945   4961   
  4946   4962   /*
  4947   4963   ** Like sqlite3ExprCompare() except COLLATE operators at the top-level
  4948   4964   ** are ignored.
  4949   4965   */
  4950   4966   int sqlite3ExprCompareSkip(Expr *pA, Expr *pB, int iTab){
  4951   4967     return sqlite3ExprCompare(0,
  4952         -             sqlite3ExprSkipCollate(pA),
  4953         -             sqlite3ExprSkipCollate(pB),
         4968  +             sqlite3ExprSkipCollateAndLikely(pA),
         4969  +             sqlite3ExprSkipCollateAndLikely(pB),
  4954   4970                iTab);
  4955   4971   }
  4956   4972   
  4957   4973   /*
  4958   4974   ** Return non-zero if Expr p can only be true if pNN is not NULL.
  4959   4975   */
  4960   4976   static int exprImpliesNotNull(
................................................................................
  5154   5170   ** an ordinary JOIN.  The p argument is the WHERE clause.  If the WHERE
  5155   5171   ** clause requires that some column of the right table of the LEFT JOIN
  5156   5172   ** be non-NULL, then the LEFT JOIN can be safely converted into an
  5157   5173   ** ordinary join.
  5158   5174   */
  5159   5175   int sqlite3ExprImpliesNonNullRow(Expr *p, int iTab){
  5160   5176     Walker w;
  5161         -  p = sqlite3ExprSkipCollate(p);
         5177  +  p = sqlite3ExprSkipCollateAndLikely(p);
  5162   5178     while( p ){
  5163   5179       if( p->op==TK_NOTNULL ){
  5164   5180         p = p->pLeft;
  5165   5181       }else if( p->op==TK_AND ){
  5166   5182         if( sqlite3ExprImpliesNonNullRow(p->pLeft, iTab) ) return 1;
  5167   5183         p = p->pRight;
  5168   5184       }else{

Changes to src/resolve.c.

   969    969       }
   970    970       case TK_VARIABLE: {
   971    971         notValid(pParse, pNC, "parameters", NC_IsCheck|NC_PartIdx|NC_IdxExpr);
   972    972         break;
   973    973       }
   974    974       case TK_IS:
   975    975       case TK_ISNOT: {
   976         -      Expr *pRight = sqlite3ExprSkipCollate(pExpr->pRight);
          976  +      Expr *pRight = sqlite3ExprSkipCollateAndLikely(pExpr->pRight);
   977    977         assert( !ExprHasProperty(pExpr, EP_Reduced) );
   978    978         /* Handle special cases of "x IS TRUE", "x IS FALSE", "x IS NOT TRUE",
   979    979         ** and "x IS NOT FALSE". */
   980    980         if( pRight->op==TK_ID ){
   981    981           int rc = resolveExprStep(pWalker, pRight);
   982    982           if( rc==WRC_Abort ) return WRC_Abort;
   983    983           if( pRight->op==TK_TRUEFALSE ){
................................................................................
  1180   1180       moreToDo = 0;
  1181   1181       pEList = pSelect->pEList;
  1182   1182       assert( pEList!=0 );
  1183   1183       for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
  1184   1184         int iCol = -1;
  1185   1185         Expr *pE, *pDup;
  1186   1186         if( pItem->done ) continue;
  1187         -      pE = sqlite3ExprSkipCollate(pItem->pExpr);
         1187  +      pE = sqlite3ExprSkipCollateAndLikely(pItem->pExpr);
  1188   1188         if( sqlite3ExprIsInteger(pE, &iCol) ){
  1189   1189           if( iCol<=0 || iCol>pEList->nExpr ){
  1190   1190             resolveOutOfRangeError(pParse, "ORDER", i+1, pEList->nExpr);
  1191   1191             return 1;
  1192   1192           }
  1193   1193         }else{
  1194   1194           iCol = resolveAsName(pParse, pEList, pE);
................................................................................
  1359   1359     int nResult;                   /* Number of terms in the result set */
  1360   1360   
  1361   1361     if( pOrderBy==0 ) return 0;
  1362   1362     nResult = pSelect->pEList->nExpr;
  1363   1363     pParse = pNC->pParse;
  1364   1364     for(i=0, pItem=pOrderBy->a; i<pOrderBy->nExpr; i++, pItem++){
  1365   1365       Expr *pE = pItem->pExpr;
  1366         -    Expr *pE2 = sqlite3ExprSkipCollate(pE);
         1366  +    Expr *pE2 = sqlite3ExprSkipCollateAndLikely(pE);
  1367   1367       if( zType[0]!='G' ){
  1368   1368         iCol = resolveAsName(pParse, pSelect->pEList, pE2);
  1369   1369         if( iCol>0 ){
  1370   1370           /* If an AS-name match is found, mark this ORDER BY column as being
  1371   1371           ** a copy of the iCol-th result-set column.  The subsequent call to
  1372   1372           ** sqlite3ResolveOrderGroupBy() will convert the expression to a
  1373   1373           ** copy of the iCol-th result-set expression. */

Changes to src/select.c.

  1956   1956   
  1957   1957     for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){
  1958   1958       /* Get an appropriate name for the column
  1959   1959       */
  1960   1960       if( (zName = pEList->a[i].zName)!=0 ){
  1961   1961         /* If the column contains an "AS <name>" phrase, use <name> as the name */
  1962   1962       }else{
  1963         -      Expr *pColExpr = sqlite3ExprSkipCollate(pEList->a[i].pExpr);
         1963  +      Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pEList->a[i].pExpr);
  1964   1964         while( pColExpr->op==TK_DOT ){
  1965   1965           pColExpr = pColExpr->pRight;
  1966   1966           assert( pColExpr!=0 );
  1967   1967         }
  1968   1968         if( pColExpr->op==TK_COLUMN ){
  1969   1969           /* For columns use the column name name */
  1970   1970           int iCol = pColExpr->iColumn;

Changes to src/sqliteInt.h.

  4274   4274   CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName);
  4275   4275   CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr);
  4276   4276   CollSeq *sqlite3ExprNNCollSeq(Parse *pParse, Expr *pExpr);
  4277   4277   int sqlite3ExprCollSeqMatch(Parse*,Expr*,Expr*);
  4278   4278   Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, const Token*, int);
  4279   4279   Expr *sqlite3ExprAddCollateString(Parse*,Expr*,const char*);
  4280   4280   Expr *sqlite3ExprSkipCollate(Expr*);
         4281  +Expr *sqlite3ExprSkipCollateAndLikely(Expr*);
  4281   4282   int sqlite3CheckCollSeq(Parse *, CollSeq *);
  4282   4283   int sqlite3WritableSchema(sqlite3*);
  4283   4284   int sqlite3CheckObjectName(Parse*, const char*,const char*,const char*);
  4284   4285   void sqlite3VdbeSetChanges(sqlite3 *, int);
  4285   4286   int sqlite3AddInt64(i64*,i64);
  4286   4287   int sqlite3SubInt64(i64*,i64);
  4287   4288   int sqlite3MulInt64(i64*,i64);

Changes to src/vdbe.c.

  4128   4128   #ifdef SQLITE_DEBUG
  4129   4129     pC->seekOp = pOp->opcode;
  4130   4130   #endif
  4131   4131   
  4132   4132     pC->deferredMoveto = 0;
  4133   4133     pC->cacheStatus = CACHE_STALE;
  4134   4134     if( pC->isTable ){
         4135  +    u16 flags3, newType;
  4135   4136       /* The BTREE_SEEK_EQ flag is only set on index cursors */
  4136   4137       assert( sqlite3BtreeCursorHasHint(pC->uc.pCursor, BTREE_SEEK_EQ)==0
  4137   4138                 || CORRUPT_DB );
  4138   4139   
  4139   4140       /* The input value in P3 might be of any type: integer, real, string,
  4140   4141       ** blob, or NULL.  But it needs to be an integer before we can do
  4141   4142       ** the seek, so convert it. */
  4142   4143       pIn3 = &aMem[pOp->p3];
  4143         -    if( (pIn3->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Str))==MEM_Str ){
         4144  +    flags3 = pIn3->flags;
         4145  +    if( (flags3 & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Str))==MEM_Str ){
  4144   4146         applyNumericAffinity(pIn3, 0);
  4145   4147       }
  4146         -    iKey = sqlite3VdbeIntValue(pIn3);
         4148  +    iKey = sqlite3VdbeIntValue(pIn3); /* Get the integer key value */
         4149  +    newType = pIn3->flags; /* Record the type after applying numeric affinity */
         4150  +    pIn3->flags = flags3;  /* But convert the type back to its original */
  4147   4151   
  4148   4152       /* If the P3 value could not be converted into an integer without
  4149   4153       ** loss of information, then special processing is required... */
  4150         -    if( (pIn3->flags & (MEM_Int|MEM_IntReal))==0 ){
  4151         -      if( (pIn3->flags & MEM_Real)==0 ){
  4152         -        if( (pIn3->flags & MEM_Null) || oc>=OP_SeekGE ){
         4154  +    if( (newType & (MEM_Int|MEM_IntReal))==0 ){
         4155  +      if( (newType & MEM_Real)==0 ){
         4156  +        if( (newType & MEM_Null) || oc>=OP_SeekGE ){
  4153   4157             VdbeBranchTaken(1,2);
  4154   4158             goto jump_to_p2;
  4155   4159           }else{
  4156   4160             rc = sqlite3BtreeLast(pC->uc.pCursor, &res);
  4157   4161             if( rc!=SQLITE_OK ) goto abort_due_to_error;
  4158   4162             goto seek_not_found;
  4159   4163           }

Changes to src/vdbeaux.c.

  5018   5018     preupdate.v = v;
  5019   5019     preupdate.pCsr = pCsr;
  5020   5020     preupdate.op = op;
  5021   5021     preupdate.iNewReg = iReg;
  5022   5022     preupdate.keyinfo.db = db;
  5023   5023     preupdate.keyinfo.enc = ENC(db);
  5024   5024     preupdate.keyinfo.nKeyField = pTab->nCol;
  5025         -  preupdate.keyinfo.aSortOrder = (u8*)&fakeSortOrder;
         5025  +  preupdate.keyinfo.aSortFlags = (u8*)&fakeSortOrder;
  5026   5026     preupdate.iKey1 = iKey1;
  5027   5027     preupdate.iKey2 = iKey2;
  5028   5028     preupdate.pTab = pTab;
  5029   5029   
  5030   5030     db->pPreUpdate = &preupdate;
  5031   5031     db->xPreUpdateCallback(db->pPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2);
  5032   5032     db->pPreUpdate = 0;

Changes to src/where.c.

   249    249            && (iColumn!=XN_EXPR
   250    250                || sqlite3ExprCompareSkip(pTerm->pExpr->pLeft,
   251    251                                          pScan->pIdxExpr,iCur)==0)
   252    252            && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
   253    253           ){
   254    254             if( (pTerm->eOperator & WO_EQUIV)!=0
   255    255              && pScan->nEquiv<ArraySize(pScan->aiCur)
   256         -           && (pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight))->op==TK_COLUMN
          256  +           && (pX = sqlite3ExprSkipCollateAndLikely(pTerm->pExpr->pRight))->op
          257  +               ==TK_COLUMN
   257    258             ){
   258    259               int j;
   259    260               for(j=0; j<pScan->nEquiv; j++){
   260    261                 if( pScan->aiCur[j]==pX->iTable
   261    262                  && pScan->aiColumn[j]==pX->iColumn ){
   262    263                     break;
   263    264                 }
................................................................................
   445    446     Index *pIdx,                    /* Index to match column of */
   446    447     int iCol                        /* Column of index to match */
   447    448   ){
   448    449     int i;
   449    450     const char *zColl = pIdx->azColl[iCol];
   450    451   
   451    452     for(i=0; i<pList->nExpr; i++){
   452         -    Expr *p = sqlite3ExprSkipCollate(pList->a[i].pExpr);
          453  +    Expr *p = sqlite3ExprSkipCollateAndLikely(pList->a[i].pExpr);
   453    454       if( p->op==TK_COLUMN
   454    455        && p->iColumn==pIdx->aiColumn[iCol]
   455    456        && p->iTable==iBase
   456    457       ){
   457    458         CollSeq *pColl = sqlite3ExprNNCollSeq(pParse, pList->a[i].pExpr);
   458    459         if( 0==sqlite3StrICmp(pColl->zName, zColl) ){
   459    460           return i;
................................................................................
   509    510     pTab = pTabList->a[0].pTab;
   510    511   
   511    512     /* If any of the expressions is an IPK column on table iBase, then return 
   512    513     ** true. Note: The (p->iTable==iBase) part of this test may be false if the
   513    514     ** current SELECT is a correlated sub-query.
   514    515     */
   515    516     for(i=0; i<pDistinct->nExpr; i++){
   516         -    Expr *p = sqlite3ExprSkipCollate(pDistinct->a[i].pExpr);
          517  +    Expr *p = sqlite3ExprSkipCollateAndLikely(pDistinct->a[i].pExpr);
   517    518       if( p->op==TK_COLUMN && p->iTable==iBase && p->iColumn<0 ) return 1;
   518    519     }
   519    520   
   520    521     /* Loop through all indices on the table, checking each to see if it makes
   521    522     ** the DISTINCT qualifier redundant. It does so if:
   522    523     **
   523    524     **   1. The index is itself UNIQUE, and
................................................................................
  2766   2767     ExprList *pOB;
  2767   2768     ExprList *aColExpr;
  2768   2769     int ii, jj;
  2769   2770   
  2770   2771     if( pIndex->bUnordered ) return 0;
  2771   2772     if( (pOB = pBuilder->pWInfo->pOrderBy)==0 ) return 0;
  2772   2773     for(ii=0; ii<pOB->nExpr; ii++){
  2773         -    Expr *pExpr = sqlite3ExprSkipCollate(pOB->a[ii].pExpr);
         2774  +    Expr *pExpr = sqlite3ExprSkipCollateAndLikely(pOB->a[ii].pExpr);
  2774   2775       if( pExpr->op==TK_COLUMN && pExpr->iTable==iCursor ){
  2775   2776         if( pExpr->iColumn<0 ) return 1;
  2776   2777         for(jj=0; jj<pIndex->nKeyCol; jj++){
  2777   2778           if( pExpr->iColumn==pIndex->aiColumn[jj] ) return 1;
  2778   2779         }
  2779   2780       }else if( (aColExpr = pIndex->aColExpr)!=0 ){
  2780   2781         for(jj=0; jj<pIndex->nKeyCol; jj++){
................................................................................
  3706   3707       /* Mark off any ORDER BY term X that is a column in the table of
  3707   3708       ** the current loop for which there is term in the WHERE
  3708   3709       ** clause of the form X IS NULL or X=? that reference only outer
  3709   3710       ** loops.
  3710   3711       */
  3711   3712       for(i=0; i<nOrderBy; i++){
  3712   3713         if( MASKBIT(i) & obSat ) continue;
  3713         -      pOBExpr = sqlite3ExprSkipCollate(pOrderBy->a[i].pExpr);
         3714  +      pOBExpr = sqlite3ExprSkipCollateAndLikely(pOrderBy->a[i].pExpr);
  3714   3715         if( pOBExpr->op!=TK_COLUMN ) continue;
  3715   3716         if( pOBExpr->iTable!=iCur ) continue;
  3716   3717         pTerm = sqlite3WhereFindTerm(&pWInfo->sWC, iCur, pOBExpr->iColumn,
  3717   3718                          ~ready, eqOpMask, 0);
  3718   3719         if( pTerm==0 ) continue;
  3719   3720         if( pTerm->eOperator==WO_IN ){
  3720   3721           /* IN terms are only valid for sorting in the ORDER BY LIMIT 
................................................................................
  3826   3827   
  3827   3828           /* Find the ORDER BY term that corresponds to the j-th column
  3828   3829           ** of the index and mark that ORDER BY term off 
  3829   3830           */
  3830   3831           isMatch = 0;
  3831   3832           for(i=0; bOnce && i<nOrderBy; i++){
  3832   3833             if( MASKBIT(i) & obSat ) continue;
  3833         -          pOBExpr = sqlite3ExprSkipCollate(pOrderBy->a[i].pExpr);
         3834  +          pOBExpr = sqlite3ExprSkipCollateAndLikely(pOrderBy->a[i].pExpr);
  3834   3835             testcase( wctrlFlags & WHERE_GROUPBY );
  3835   3836             testcase( wctrlFlags & WHERE_DISTINCTBY );
  3836   3837             if( (wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY))==0 ) bOnce = 0;
  3837   3838             if( iColumn>=XN_ROWID ){
  3838   3839               if( pOBExpr->op!=TK_COLUMN ) continue;
  3839   3840               if( pOBExpr->iTable!=iCur ) continue;
  3840   3841               if( pOBExpr->iColumn!=iColumn ) continue;

Changes to src/whereexpr.c.

    80     80     }
    81     81     pTerm = &pWC->a[idx = pWC->nTerm++];
    82     82     if( p && ExprHasProperty(p, EP_Unlikely) ){
    83     83       pTerm->truthProb = sqlite3LogEst(p->iTable) - 270;
    84     84     }else{
    85     85       pTerm->truthProb = 1;
    86     86     }
    87         -  pTerm->pExpr = sqlite3ExprSkipCollate(p);
           87  +  pTerm->pExpr = sqlite3ExprSkipCollateAndLikely(p);
    88     88     pTerm->wtFlags = wtFlags;
    89     89     pTerm->pWC = pWC;
    90     90     pTerm->iParent = -1;
    91     91     memset(&pTerm->eOperator, 0,
    92     92            sizeof(WhereTerm) - offsetof(WhereTerm,eOperator));
    93     93     return idx;
    94     94   }
................................................................................
  1447   1447   ** does is make slot[] entries point to substructure within pExpr.
  1448   1448   **
  1449   1449   ** In the previous sentence and in the diagram, "slot[]" refers to
  1450   1450   ** the WhereClause.a[] array.  The slot[] array grows as needed to contain
  1451   1451   ** all terms of the WHERE clause.
  1452   1452   */
  1453   1453   void sqlite3WhereSplit(WhereClause *pWC, Expr *pExpr, u8 op){
  1454         -  Expr *pE2 = sqlite3ExprSkipCollate(pExpr);
         1454  +  Expr *pE2 = sqlite3ExprSkipCollateAndLikely(pExpr);
  1455   1455     pWC->op = op;
  1456   1456     if( pE2==0 ) return;
  1457   1457     if( pE2->op!=op ){
  1458   1458       whereClauseInsert(pWC, pExpr, 0);
  1459   1459     }else{
  1460   1460       sqlite3WhereSplit(pWC, pE2->pLeft, op);
  1461   1461       sqlite3WhereSplit(pWC, pE2->pRight, op);

Changes to test/affinity2.test.

    80     80     INSERT INTO t3 VALUES(3, 1, 1);
    81     81     INSERT INTO t3 VALUES(4, 1, 0);
    82     82     INSERT INTO t3 VALUES(5, 1, 1);
    83     83   }
    84     84   do_execsql_test 440 {
    85     85     SELECT * FROM t3 WHERE c='0' ORDER BY a;
    86     86   } {2 1 0 4 1 0}
           87  +
           88  +# 2019-08-22 ticket https://sqlite.org/src/info/d99f1ffe836c591ac57f
           89  +# False positive in sqlite3ExprNeedsNoAffinityChange()
           90  +#
           91  +do_execsql_test 500 {
           92  +  DROP TABLE IF EXISTS t0;
           93  +  CREATE TABLE t0(c0 TEXT UNIQUE, c1);
           94  +  INSERT INTO t0(c0) VALUES (-1);
           95  +  SELECT quote(- x'ce'), quote(t0.c0), quote(- x'ce' >= t0.c0) FROM t0;
           96  +} {0 '-1' 1}
           97  +do_execsql_test 501 {
           98  +  SELECT * FROM t0 WHERE - x'ce' >= t0.c0;
           99  +} {-1 {}}
          100  +do_execsql_test 502 {
          101  +  SELECT quote(+-+x'ce'), quote(t0.c0), quote(+-+x'ce' >= t0.c0) FROM t0;
          102  +} {0 '-1' 1}
          103  +do_execsql_test 503 {
          104  +  SELECT * FROM t0 WHERE +-+x'ce' >= t0.c0;
          105  +} {-1 {}}
          106  +do_execsql_test 504 {
          107  +  SELECT quote(- 'ce'), quote(t0.c0), quote(- 'ce' >= t0.c0) FROM t0;
          108  +} {0 '-1' 1}
          109  +do_execsql_test 505 {
          110  +  SELECT * FROM t0 WHERE - 'ce' >= t0.c0;
          111  +} {-1 {}}
          112  +do_execsql_test 506 {
          113  +  SELECT quote(+-+'ce'), quote(t0.c0), quote(+-+'ce' >= t0.c0) FROM t0;
          114  +} {0 '-1' 1}
          115  +do_execsql_test 507 {
          116  +  SELECT * FROM t0 WHERE +-+'ce' >= t0.c0;
          117  +} {-1 {}}
          118  + 
    87    119   
    88    120   finish_test

Changes to test/where.test.

  1533   1533   do_catchsql_test where-25.4 {
  1534   1534     SELECT * FROM t1 WHERE c='iii'
  1535   1535   } {0 {}}
  1536   1536   do_catchsql_test where-25.5 {
  1537   1537     INSERT INTO t1 VALUES(4, 'four', 'iii') 
  1538   1538       ON CONFLICT(c) DO UPDATE SET b=NULL
  1539   1539   } {1 {corrupt database}}
         1540  +
         1541  +# 2019-08-21 Ticket https://www.sqlite.org/src/info/d9f584e936c7a8d0
         1542  +#
         1543  +db close
         1544  +sqlite3 db :memory:
         1545  +do_execsql_test where-26.1 {
         1546  +  CREATE TABLE t0(c0 INTEGER PRIMARY KEY, c1 TEXT);
         1547  +  INSERT INTO t0(c0, c1) VALUES (1, 'a');
         1548  +  CREATE TABLE t1(c0 INT PRIMARY KEY, c1 TEXT);
         1549  +  INSERT INTO t1(c0, c1) VALUES (1, 'a');
         1550  +  SELECT * FROM t0 WHERE '-1' BETWEEN 0 AND t0.c0;
         1551  +} {1 a}
         1552  +do_execsql_test where-26.2 {
         1553  +  SELECT * FROM t1 WHERE '-1' BETWEEN 0 AND t1.c0;
         1554  +} {1 a}
         1555  +do_execsql_test where-26.3 {
         1556  +  SELECT * FROM t0 WHERE '-1'>=0 AND '-1'<=t0.c0;
         1557  +} {1 a}
         1558  +do_execsql_test where-26.4 {
         1559  +  SELECT * FROM t1 WHERE '-1'>=0 AND '-1'<=t1.c0;
         1560  +} {1 a}
         1561  +do_execsql_test where-26.5 {
         1562  +  SELECT '-1' BETWEEN 0 AND t0.c0 FROM t0;
         1563  +} {1}
         1564  +do_execsql_test where-26.6 {
         1565  +  SELECT '-1' BETWEEN 0 AND t1.c0 FROM t1;
         1566  +} {1}
         1567  +do_execsql_test where-26.7 {
         1568  +  SELECT '-1'>=0 AND '-1'<=t0.c0 FROM t0;
         1569  +} {1}
         1570  +do_execsql_test where-26.8 {
         1571  +  SELECT '-1'>=0 AND '-1'<=t1.c0 FROM t1;
         1572  +} {1}
  1540   1573   
  1541   1574   finish_test

Changes to test/whereG.test.

   261    261   } {1 3 1 4 9 3 9 4}
   262    262   do_execsql_test 7.2 {
   263    263     SELECT likelihood(a,0.5), x FROM t1, t2 ORDER BY 1, 2;
   264    264   } {1 3 1 4 9 3 9 4}
   265    265   do_execsql_test 7.3 {
   266    266     SELECT coalesce(a,a), x FROM t1, t2 ORDER BY 1, 2;
   267    267   } {1 3 1 4 9 3 9 4}
          268  +
          269  +# 2019-08-22
          270  +# Ticket https://www.sqlite.org/src/info/7e07a3dbf5a8cd26
          271  +#
          272  +do_execsql_test 8.1 {
          273  +  DROP TABLE IF EXISTS t0;
          274  +  CREATE TABLE t0 (c0);
          275  +  INSERT INTO t0(c0) VALUES ('a');
          276  +  SELECT LIKELY(t0.rowid) <= '0' FROM t0;
          277  +} {1}
          278  +do_execsql_test 8.2 {
          279  +  SELECT * FROM t0 WHERE LIKELY(t0.rowid) <= '0';
          280  +} {a}
          281  +do_execsql_test 8.3 {
          282  +  SELECT (t0.rowid) <= '0' FROM t0;
          283  +} {0}
          284  +do_execsql_test 8.4 {
          285  +  SELECT * FROM t0 WHERE (t0.rowid) <= '0';
          286  +} {}
          287  +do_execsql_test 8.5 {
          288  +  SELECT unlikely(t0.rowid) <= '0', likelihood(t0.rowid,0.5) <= '0' FROM t0;
          289  +} {1 1}
          290  +do_execsql_test 8.6 {
          291  +  SELECT * FROM t0 WHERE unlikely(t0.rowid) <= '0';
          292  +} {a}
          293  +do_execsql_test 8.7 {
          294  +  SELECT * FROM t0 WHERE likelihood(t0.rowid, 0.5) <= '0';
          295  +} {a}
          296  +do_execsql_test 8.8 {
          297  +  SELECT unlikely(t0.rowid <= '0'),
          298  +         likely(t0.rowid <= '0'),
          299  +         likelihood(t0.rowid <= '0',0.5)
          300  +    FROM t0;
          301  +} {0 0 0}
          302  +do_execsql_test 8.9 {
          303  +  SELECT * FROM t0 WHERE unlikely(t0.rowid <= '0');
          304  +} {}
          305  +do_execsql_test 8.10 {
          306  +  SELECT * FROM t0 WHERE likelihood(t0.rowid <= '0', 0.5);
          307  +} {}
          308  +
          309  +
   268    310   
   269    311   
   270    312   finish_test