/ Check-in [ad130bb8]
Login

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

Overview
Comment:Combine the Expr.pTab and Expr.pWin fields into a union named "y". Add a new EP_WinFunc property that is only true if Expr.y.pWin is a valid pointer. This reduces the size of the Expr object by 8 bytes, reduces the overall amount of code, and shaves over 1 million cycles off of the speed test.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ad130bb86e74e6ce165fdbdce3a19699510f0e62071c1c7923b5a4538d888c7c
User & Date: drh 2018-09-20 19:02:15
Context
2018-09-20
20:15
Add the "PRAGMA legacy_alter_table=ON" command to enable the pre-3.25.0 behavior of ALTER TABLE that does not modify the bodies of triggers or views or the WHERE clause of a partial index. Enable the legacy behavior by default when running the xRename method of virtual tables. check-in: 7edd26ed user: drh tags: trunk
19:02
Combine the Expr.pTab and Expr.pWin fields into a union named "y". Add a new EP_WinFunc property that is only true if Expr.y.pWin is a valid pointer. This reduces the size of the Expr object by 8 bytes, reduces the overall amount of code, and shaves over 1 million cycles off of the speed test. check-in: ad130bb8 user: drh tags: trunk
2018-09-19
17:09
Fix a compilation issue in the "userauth" extension. Also fix a few test script errors that occur with SQLITE_USER_AUTHENTICATION=1 builds. check-in: 221f3f57 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/alter.c.

   799    799     if( pExpr->op==TK_TRIGGER 
   800    800      && pExpr->iColumn==p->iCol 
   801    801      && pWalker->pParse->pTriggerTab==p->pTab
   802    802     ){
   803    803       renameTokenFind(pWalker->pParse, p, (void*)pExpr);
   804    804     }else if( pExpr->op==TK_COLUMN 
   805    805      && pExpr->iColumn==p->iCol 
   806         -   && p->pTab==pExpr->pTab
          806  +   && p->pTab==pExpr->y.pTab
   807    807     ){
   808    808       renameTokenFind(pWalker->pParse, p, (void*)pExpr);
   809    809     }
   810    810     return WRC_Continue;
   811    811   }
   812    812   
   813    813   /*
................................................................................
  1337   1337   }
  1338   1338   
  1339   1339   /*
  1340   1340   ** Walker expression callback used by "RENAME TABLE". 
  1341   1341   */
  1342   1342   static int renameTableExprCb(Walker *pWalker, Expr *pExpr){
  1343   1343     RenameCtx *p = pWalker->u.pRename;
  1344         -  if( pExpr->op==TK_COLUMN && p->pTab==pExpr->pTab ){
  1345         -    renameTokenFind(pWalker->pParse, p, (void*)&pExpr->pTab);
         1344  +  if( pExpr->op==TK_COLUMN && p->pTab==pExpr->y.pTab ){
         1345  +    renameTokenFind(pWalker->pParse, p, (void*)&pExpr->y.pTab);
  1346   1346     }
  1347   1347     return WRC_Continue;
  1348   1348   }
  1349   1349   
  1350   1350   /*
  1351   1351   ** Walker select callback used by "RENAME TABLE". 
  1352   1352   */

Changes to src/expr.c.

    54     54     if( op==TK_REGISTER ) op = pExpr->op2;
    55     55   #ifndef SQLITE_OMIT_CAST
    56     56     if( op==TK_CAST ){
    57     57       assert( !ExprHasProperty(pExpr, EP_IntValue) );
    58     58       return sqlite3AffinityType(pExpr->u.zToken, 0);
    59     59     }
    60     60   #endif
    61         -  if( (op==TK_AGG_COLUMN || op==TK_COLUMN) && pExpr->pTab ){
    62         -    return sqlite3TableColumnAffinity(pExpr->pTab, pExpr->iColumn);
           61  +  if( (op==TK_AGG_COLUMN || op==TK_COLUMN) && pExpr->y.pTab ){
           62  +    return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
    63     63     }
    64     64     if( op==TK_SELECT_COLUMN ){
    65     65       assert( pExpr->pLeft->flags&EP_xIsSelect );
    66     66       return sqlite3ExprAffinity(
    67     67           pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
    68     68       );
    69     69     }
................................................................................
   139    139     CollSeq *pColl = 0;
   140    140     Expr *p = pExpr;
   141    141     while( p ){
   142    142       int op = p->op;
   143    143       if( p->flags & EP_Generic ) break;
   144    144       if( (op==TK_AGG_COLUMN || op==TK_COLUMN
   145    145             || op==TK_REGISTER || op==TK_TRIGGER)
   146         -     && p->pTab!=0
          146  +     && p->y.pTab!=0
   147    147       ){
   148         -      /* op==TK_REGISTER && p->pTab!=0 happens when pExpr was originally
          148  +      /* op==TK_REGISTER && p->y.pTab!=0 happens when pExpr was originally
   149    149         ** a TK_COLUMN but was previously evaluated and cached in a register */
   150    150         int j = p->iColumn;
   151    151         if( j>=0 ){
   152         -        const char *zColl = p->pTab->aCol[j].zColl;
          152  +        const char *zColl = p->y.pTab->aCol[j].zColl;
   153    153           pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
   154    154         }
   155    155         break;
   156    156       }
   157    157       if( op==TK_CAST || op==TK_UPLUS ){
   158    158         p = p->pLeft;
   159    159         continue;
................................................................................
  1048   1048   /*
  1049   1049   ** Recursively delete an expression tree.
  1050   1050   */
  1051   1051   static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){
  1052   1052     assert( p!=0 );
  1053   1053     /* Sanity check: Assert that the IntValue is non-negative if it exists */
  1054   1054     assert( !ExprHasProperty(p, EP_IntValue) || p->u.iValue>=0 );
         1055  +
         1056  +  assert( !ExprHasProperty(p, EP_WinFunc) || p->y.pWin!=0 || db->mallocFailed );
         1057  +  assert( p->op!=TK_FUNCTION || ExprHasProperty(p, EP_TokenOnly|EP_Reduced)
         1058  +          || p->y.pWin==0 || ExprHasProperty(p, EP_WinFunc) );
  1055   1059   #ifdef SQLITE_DEBUG
  1056   1060     if( ExprHasProperty(p, EP_Leaf) && !ExprHasProperty(p, EP_TokenOnly) ){
  1057   1061       assert( p->pLeft==0 );
  1058   1062       assert( p->pRight==0 );
  1059   1063       assert( p->x.pSelect==0 );
  1060   1064     }
  1061   1065   #endif
................................................................................
  1066   1070       if( p->pRight ){
  1067   1071         sqlite3ExprDeleteNN(db, p->pRight);
  1068   1072       }else if( ExprHasProperty(p, EP_xIsSelect) ){
  1069   1073         sqlite3SelectDelete(db, p->x.pSelect);
  1070   1074       }else{
  1071   1075         sqlite3ExprListDelete(db, p->x.pList);
  1072   1076       }
  1073         -    if( !ExprHasProperty(p, EP_Reduced) ){
  1074         -      sqlite3WindowDelete(db, p->pWin);
         1077  +    if( ExprHasProperty(p, EP_WinFunc) ){
         1078  +      assert( p->op==TK_FUNCTION );
         1079  +      sqlite3WindowDelete(db, p->y.pWin);
  1075   1080       }
  1076   1081     }
  1077   1082     if( ExprHasProperty(p, EP_MemToken) ) sqlite3DbFree(db, p->u.zToken);
  1078   1083     if( !ExprHasProperty(p, EP_Static) ){
  1079   1084       sqlite3DbFreeNN(db, p);
  1080   1085     }
  1081   1086   }
................................................................................
  1131   1136   static int dupedExprStructSize(Expr *p, int flags){
  1132   1137     int nSize;
  1133   1138     assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */
  1134   1139     assert( EXPR_FULLSIZE<=0xfff );
  1135   1140     assert( (0xfff & (EP_Reduced|EP_TokenOnly))==0 );
  1136   1141     if( 0==flags || p->op==TK_SELECT_COLUMN 
  1137   1142   #ifndef SQLITE_OMIT_WINDOWFUNC
  1138         -   || p->pWin 
         1143  +   || ExprHasProperty(p, EP_WinFunc)
  1139   1144   #endif
  1140   1145     ){
  1141   1146       nSize = EXPR_FULLSIZE;
  1142   1147     }else{
  1143   1148       assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
  1144   1149       assert( !ExprHasProperty(p, EP_FromJoin) ); 
  1145   1150       assert( !ExprHasProperty(p, EP_MemToken) );
................................................................................
  1274   1279                          exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc) : 0;
  1275   1280         }
  1276   1281         if( pzBuffer ){
  1277   1282           *pzBuffer = zAlloc;
  1278   1283         }
  1279   1284       }else{
  1280   1285   #ifndef SQLITE_OMIT_WINDOWFUNC
  1281         -      if( ExprHasProperty(p, EP_Reduced|EP_TokenOnly) ){
  1282         -        pNew->pWin = 0;
  1283         -      }else{
  1284         -        pNew->pWin = sqlite3WindowDup(db, pNew, p->pWin);
         1286  +      if( ExprHasProperty(p, EP_WinFunc) ){
         1287  +        pNew->y.pWin = sqlite3WindowDup(db, pNew, p->y.pWin);
         1288  +        assert( ExprHasProperty(pNew, EP_WinFunc) );
  1285   1289         }
  1286   1290   #endif /* SQLITE_OMIT_WINDOWFUNC */
  1287   1291         if( !ExprHasProperty(p, EP_TokenOnly|EP_Leaf) ){
  1288   1292           if( pNew->op==TK_SELECT_COLUMN ){
  1289   1293             pNew->pLeft = p->pLeft;
  1290   1294             assert( p->iColumn==0 || p->pRight==0 );
  1291   1295             assert( p->pRight==0  || p->pRight==p->pLeft );
................................................................................
  2085   2089       case TK_INTEGER:
  2086   2090       case TK_STRING:
  2087   2091       case TK_FLOAT:
  2088   2092       case TK_BLOB:
  2089   2093         return 0;
  2090   2094       case TK_COLUMN:
  2091   2095         return ExprHasProperty(p, EP_CanBeNull) ||
  2092         -             p->pTab==0 ||  /* Reference to column of index on expression */
  2093         -             (p->iColumn>=0 && p->pTab->aCol[p->iColumn].notNull==0);
         2096  +             p->y.pTab==0 ||  /* Reference to column of index on expression */
         2097  +             (p->iColumn>=0 && p->y.pTab->aCol[p->iColumn].notNull==0);
  2094   2098       default:
  2095   2099         return 1;
  2096   2100     }
  2097   2101   }
  2098   2102   
  2099   2103   /*
  2100   2104   ** Return TRUE if the given expression is a constant which would be
................................................................................
  3374   3378           /* This COLUMN expression is really a constant due to WHERE clause
  3375   3379           ** constraints, and that constant is coded by the pExpr->pLeft
  3376   3380           ** expresssion.  However, make sure the constant has the correct
  3377   3381           ** datatype by applying the Affinity of the table column to the
  3378   3382           ** constant.
  3379   3383           */
  3380   3384           int iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target);
  3381         -        int aff = sqlite3TableColumnAffinity(pExpr->pTab, pExpr->iColumn);
         3385  +        int aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
  3382   3386           if( aff!=SQLITE_AFF_BLOB ){
  3383   3387             static const char zAff[] = "B\000C\000D\000E";
  3384   3388             assert( SQLITE_AFF_BLOB=='A' );
  3385   3389             assert( SQLITE_AFF_TEXT=='B' );
  3386   3390             if( iReg!=target ){
  3387   3391               sqlite3VdbeAddOp2(v, OP_SCopy, iReg, target);
  3388   3392               iReg = target;
................................................................................
  3398   3402             return pExpr->iColumn - pParse->iSelfTab;
  3399   3403           }else{
  3400   3404             /* Coding an expression that is part of an index where column names
  3401   3405             ** in the index refer to the table to which the index belongs */
  3402   3406             iTab = pParse->iSelfTab - 1;
  3403   3407           }
  3404   3408         }
  3405         -      return sqlite3ExprCodeGetColumn(pParse, pExpr->pTab,
         3409  +      return sqlite3ExprCodeGetColumn(pParse, pExpr->y.pTab,
  3406   3410                                  pExpr->iColumn, iTab, target,
  3407   3411                                  pExpr->op2);
  3408   3412       }
  3409   3413       case TK_INTEGER: {
  3410   3414         codeInteger(pParse, pExpr, 0, target);
  3411   3415         return target;
  3412   3416       }
................................................................................
  3612   3616         u32 constMask = 0;     /* Mask of function arguments that are constant */
  3613   3617         int i;                 /* Loop counter */
  3614   3618         sqlite3 *db = pParse->db;  /* The database connection */
  3615   3619         u8 enc = ENC(db);      /* The text encoding used by this database */
  3616   3620         CollSeq *pColl = 0;    /* A collating sequence */
  3617   3621   
  3618   3622   #ifndef SQLITE_OMIT_WINDOWFUNC
  3619         -      if( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) && pExpr->pWin ){
  3620         -        return pExpr->pWin->regResult;
         3623  +      if( ExprHasProperty(pExpr, EP_WinFunc) ){
         3624  +        return pExpr->y.pWin->regResult;
  3621   3625         }
  3622   3626   #endif
  3623   3627   
  3624   3628         if( ConstFactorOk(pParse) && sqlite3ExprIsConstantNotJoin(pExpr) ){
  3625   3629           /* SQL functions can be expensive. So try to move constant functions
  3626   3630           ** out of the inner loop, even if that means an extra OP_Copy. */
  3627   3631           return sqlite3ExprCodeAtInit(pParse, pExpr, -1);
................................................................................
  3856   3860         **
  3857   3861         ** Then p1 is interpreted as follows:
  3858   3862         **
  3859   3863         **   p1==0   ->    old.rowid     p1==3   ->    new.rowid
  3860   3864         **   p1==1   ->    old.a         p1==4   ->    new.a
  3861   3865         **   p1==2   ->    old.b         p1==5   ->    new.b       
  3862   3866         */
  3863         -      Table *pTab = pExpr->pTab;
         3867  +      Table *pTab = pExpr->y.pTab;
  3864   3868         int p1 = pExpr->iTable * (pTab->nCol+1) + 1 + pExpr->iColumn;
  3865   3869   
  3866   3870         assert( pExpr->iTable==0 || pExpr->iTable==1 );
  3867   3871         assert( pExpr->iColumn>=-1 && pExpr->iColumn<pTab->nCol );
  3868   3872         assert( pTab->iPKey<0 || pExpr->iColumn!=pTab->iPKey );
  3869   3873         assert( p1>=0 && p1<(pTab->nCol*2+2) );
  3870   3874   
  3871   3875         sqlite3VdbeAddOp2(v, OP_Param, p1, target);
  3872   3876         VdbeComment((v, "r[%d]=%s.%s", target,
  3873   3877           (pExpr->iTable ? "new" : "old"),
  3874         -        (pExpr->iColumn<0 ? "rowid" : pExpr->pTab->aCol[pExpr->iColumn].zName)
         3878  +        (pExpr->iColumn<0 ? "rowid" : pExpr->y.pTab->aCol[pExpr->iColumn].zName)
  3875   3879         ));
  3876   3880   
  3877   3881   #ifndef SQLITE_OMIT_FLOATING_POINT
  3878   3882         /* If the column has REAL affinity, it may currently be stored as an
  3879   3883         ** integer. Use OP_RealAffinity to make sure it is really real.
  3880   3884         **
  3881   3885         ** EVIDENCE-OF: R-60985-57662 SQLite will convert the value back to
................................................................................
  4718   4722         return 1;
  4719   4723       }
  4720   4724       return 2;
  4721   4725     }
  4722   4726     if( pA->op!=TK_COLUMN && pA->op!=TK_AGG_COLUMN && pA->u.zToken ){
  4723   4727       if( pA->op==TK_FUNCTION ){
  4724   4728         if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
         4729  +#ifndef SQLITE_OMIT_WINDOWFUNC
         4730  +      /* Justification for the assert():
         4731  +      ** window functions have p->op==TK_FUNCTION but aggregate functions
         4732  +      ** have p->op==TK_AGG_FUNCTION.  So any comparison between an aggregate
         4733  +      ** function and a window function should have failed before reaching
         4734  +      ** this point.  And, it is not possible to have a window function and
         4735  +      ** a scalar function with the same name and number of arguments.  So
         4736  +      ** if we reach this point, either A and B both window functions or
         4737  +      ** neither are a window functions. */
         4738  +      assert( ExprHasProperty(pA,EP_WinFunc)==ExprHasProperty(pB,EP_WinFunc) );
         4739  +      if( ExprHasProperty(pA,EP_WinFunc) ){
         4740  +        if( sqlite3WindowCompare(pParse,pA->y.pWin,pB->y.pWin)!=0 ) return 2;
         4741  +      }
         4742  +#endif
  4725   4743       }else if( pA->op==TK_COLLATE ){
  4726   4744         if( sqlite3_stricmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
  4727   4745       }else if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
  4728   4746         return 2;
  4729   4747       }
  4730   4748     }
  4731   4749     if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2;
................................................................................
  4737   4755       if( sqlite3ExprListCompare(pA->x.pList, pB->x.pList, iTab) ) return 2;
  4738   4756       assert( (combinedFlags & EP_Reduced)==0 );
  4739   4757       if( pA->op!=TK_STRING && pA->op!=TK_TRUEFALSE ){
  4740   4758         if( pA->iColumn!=pB->iColumn ) return 2;
  4741   4759         if( pA->iTable!=pB->iTable 
  4742   4760          && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2;
  4743   4761       }
  4744         -#ifndef SQLITE_OMIT_WINDOWFUNC
  4745         -    /* Justification for the assert():
  4746         -    ** window functions have p->op==TK_FUNCTION but aggregate functions
  4747         -    ** have p->op==TK_AGG_FUNCTION.  So any comparison between an aggregate
  4748         -    ** function and a window function should have failed before reaching
  4749         -    ** this point.  And, it is not possible to have a window function and
  4750         -    ** a scalar function with the same name and number of arguments.  So
  4751         -    ** if we reach this point, either A and B both window functions or
  4752         -    ** neither are a window functions. */
  4753         -    assert( (pA->pWin==0)==(pB->pWin==0) );
  4754         -
  4755         -    if( pA->pWin!=0 ){
  4756         -      if( sqlite3WindowCompare(pParse,pA->pWin,pB->pWin)!=0 ) return 2;
  4757         -    }
  4758         -#endif
  4759   4762     }
  4760   4763     return 0;
  4761   4764   }
  4762   4765   
  4763   4766   /*
  4764   4767   ** Compare two ExprList objects.  Return 0 if they are identical and 
  4765   4768   ** non-zero if they differ in any way.
................................................................................
  4895   4898       case TK_GE:
  4896   4899         testcase( pExpr->op==TK_EQ );
  4897   4900         testcase( pExpr->op==TK_NE );
  4898   4901         testcase( pExpr->op==TK_LT );
  4899   4902         testcase( pExpr->op==TK_LE );
  4900   4903         testcase( pExpr->op==TK_GT );
  4901   4904         testcase( pExpr->op==TK_GE );
  4902         -      if( (pExpr->pLeft->op==TK_COLUMN && IsVirtual(pExpr->pLeft->pTab))
  4903         -       || (pExpr->pRight->op==TK_COLUMN && IsVirtual(pExpr->pRight->pTab))
         4905  +      if( (pExpr->pLeft->op==TK_COLUMN && IsVirtual(pExpr->pLeft->y.pTab))
         4906  +       || (pExpr->pRight->op==TK_COLUMN && IsVirtual(pExpr->pRight->y.pTab))
  4904   4907         ){
  4905   4908          return WRC_Prune;
  4906   4909         }
  4907   4910       default:
  4908   4911         return WRC_Continue;
  4909   4912     }
  4910   4913   }
................................................................................
  5127   5130                   break;
  5128   5131                 }
  5129   5132               }
  5130   5133               if( (k>=pAggInfo->nColumn)
  5131   5134                && (k = addAggInfoColumn(pParse->db, pAggInfo))>=0 
  5132   5135               ){
  5133   5136                 pCol = &pAggInfo->aCol[k];
  5134         -              pCol->pTab = pExpr->pTab;
         5137  +              pCol->pTab = pExpr->y.pTab;
  5135   5138                 pCol->iTable = pExpr->iTable;
  5136   5139                 pCol->iColumn = pExpr->iColumn;
  5137   5140                 pCol->iMem = ++pParse->nMem;
  5138   5141                 pCol->iSorterColumn = -1;
  5139   5142                 pCol->pExpr = pExpr;
  5140   5143                 if( pAggInfo->pGroupBy ){
  5141   5144                   int j, n;

Changes to src/fkey.c.

   498    498     sqlite3 *db,      /* The database connection */
   499    499     Table *pTab,      /* The table whose column is desired */
   500    500     int iCursor,      /* The open cursor on the table */
   501    501     i16 iCol          /* The column that is wanted */
   502    502   ){
   503    503     Expr *pExpr = sqlite3Expr(db, TK_COLUMN, 0);
   504    504     if( pExpr ){
   505         -    pExpr->pTab = pTab;
          505  +    pExpr->y.pTab = pTab;
   506    506       pExpr->iTable = iCursor;
   507    507       pExpr->iColumn = iCol;
   508    508     }
   509    509     return pExpr;
   510    510   }
   511    511   
   512    512   /*

Changes to src/parse.y.

   937    937         p->op = (u8)op;
   938    938         p->affinity = 0;
   939    939         p->flags = EP_Leaf;
   940    940         p->iAgg = -1;
   941    941         p->pLeft = p->pRight = 0;
   942    942         p->x.pList = 0;
   943    943         p->pAggInfo = 0;
   944         -      p->pTab = 0;
          944  +      p->y.pTab = 0;
   945    945         p->op2 = 0;
   946    946         p->iTable = 0;
   947    947         p->iColumn = 0;
   948         -#ifndef SQLITE_OMIT_WINDOWFUNC
   949         -      p->pWin = 0;
   950         -#endif
   951    948         p->u.zToken = (char*)&p[1];
   952    949         memcpy(p->u.zToken, t.z, t.n);
   953    950         p->u.zToken[t.n] = 0;
   954    951         if( sqlite3Isquote(p->u.zToken[0]) ){
   955    952           if( p->u.zToken[0]=='"' ) p->flags |= EP_DblQuoted;
   956    953           sqlite3Dequote(p->u.zToken);
   957    954         }

Changes to src/resolve.c.

   155    155   ** expression node refer back to that source column.  The following changes
   156    156   ** are made to pExpr:
   157    157   **
   158    158   **    pExpr->iDb           Set the index in db->aDb[] of the database X
   159    159   **                         (even if X is implied).
   160    160   **    pExpr->iTable        Set to the cursor number for the table obtained
   161    161   **                         from pSrcList.
   162         -**    pExpr->pTab          Points to the Table structure of X.Y (even if
          162  +**    pExpr->y.pTab        Points to the Table structure of X.Y (even if
   163    163   **                         X and/or Y are implied.)
   164    164   **    pExpr->iColumn       Set to the column number within the table.
   165    165   **    pExpr->op            Set to TK_COLUMN.
   166    166   **    pExpr->pLeft         Any expression this points to is deleted
   167    167   **    pExpr->pRight        Any expression this points to is deleted.
   168    168   **
   169    169   ** The zDb variable is the name of the database (the "X").  This value may be
................................................................................
   199    199   
   200    200     assert( pNC );     /* the name context cannot be NULL. */
   201    201     assert( zCol );    /* The Z in X.Y.Z cannot be NULL */
   202    202     assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
   203    203   
   204    204     /* Initialize the node to no-match */
   205    205     pExpr->iTable = -1;
   206         -  pExpr->pTab = 0;
   207    206     ExprSetVVAProperty(pExpr, EP_NoReduce);
   208    207   
   209    208     /* Translate the schema name in zDb into a pointer to the corresponding
   210    209     ** schema.  If not found, pSchema will remain NULL and nothing will match
   211    210     ** resulting in an appropriate error message toward the end of this routine
   212    211     */
   213    212     if( zDb ){
................................................................................
   261    260           if( zTab ){
   262    261             const char *zTabName = pItem->zAlias ? pItem->zAlias : pTab->zName;
   263    262             assert( zTabName!=0 );
   264    263             if( sqlite3StrICmp(zTabName, zTab)!=0 ){
   265    264               continue;
   266    265             }
   267    266             if( IN_RENAME_OBJECT && pItem->zAlias ){
   268         -            sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->pTab);
          267  +            sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab);
   269    268             }
   270    269           }
   271    270           if( 0==(cntTab++) ){
   272    271             pMatch = pItem;
   273    272           }
   274    273           for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
   275    274             if( sqlite3StrICmp(pCol->zName, zCol)==0 ){
................................................................................
   287    286               pExpr->iColumn = j==pTab->iPKey ? -1 : (i16)j;
   288    287               break;
   289    288             }
   290    289           }
   291    290         }
   292    291         if( pMatch ){
   293    292           pExpr->iTable = pMatch->iCursor;
   294         -        pExpr->pTab = pMatch->pTab;
          293  +        pExpr->y.pTab = pMatch->pTab;
   295    294           /* RIGHT JOIN not (yet) supported */
   296    295           assert( (pMatch->fg.jointype & JT_RIGHT)==0 );
   297    296           if( (pMatch->fg.jointype & JT_LEFT)!=0 ){
   298    297             ExprSetProperty(pExpr, EP_CanBeNull);
   299    298           }
   300         -        pSchema = pExpr->pTab->pSchema;
          299  +        pSchema = pExpr->y.pTab->pSchema;
   301    300         }
   302    301       } /* if( pSrcList ) */
   303    302   
   304    303   #if !defined(SQLITE_OMIT_TRIGGER) || !defined(SQLITE_OMIT_UPSERT)
   305    304       /* If we have not already resolved the name, then maybe 
   306    305       ** it is a new.* or old.* trigger argument reference.  Or
   307    306       ** maybe it is an excluded.* from an upsert.
................................................................................
   350    349           if( iCol<pTab->nCol ){
   351    350             cnt++;
   352    351   #ifndef SQLITE_OMIT_UPSERT
   353    352             if( pExpr->iTable==2 ){
   354    353               testcase( iCol==(-1) );
   355    354               if( IN_RENAME_OBJECT ){
   356    355                 pExpr->iColumn = iCol;
   357         -              pExpr->pTab = pTab;
          356  +              pExpr->y.pTab = pTab;
   358    357                 eNewExprOp = TK_COLUMN;
   359    358               }else{
   360    359                 pExpr->iTable = pNC->uNC.pUpsert->regData + iCol;
   361    360                 eNewExprOp = TK_REGISTER;
   362    361                 ExprSetProperty(pExpr, EP_Alias);
   363    362               }
   364    363             }else
................................................................................
   372    371                 testcase( iCol==32 );
   373    372                 pParse->oldmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol));
   374    373               }else{
   375    374                 testcase( iCol==31 );
   376    375                 testcase( iCol==32 );
   377    376                 pParse->newmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol));
   378    377               }
   379         -            pExpr->pTab = pTab;
          378  +            pExpr->y.pTab = pTab;
   380    379               pExpr->iColumn = (i16)iCol;
   381    380               eNewExprOp = TK_TRIGGER;
   382    381   #endif /* SQLITE_OMIT_TRIGGER */
   383    382             }
   384    383           }
   385    384         }
   386    385       }
................................................................................
   472    471     ** Because no reference was made to outer contexts, the pNC->nRef
   473    472     ** fields are not changed in any context.
   474    473     */
   475    474     if( cnt==0 && zTab==0 ){
   476    475       assert( pExpr->op==TK_ID );
   477    476       if( ExprHasProperty(pExpr,EP_DblQuoted) ){
   478    477         pExpr->op = TK_STRING;
   479         -      pExpr->pTab = 0;
          478  +      pExpr->y.pTab = 0;
   480    479         return WRC_Prune;
   481    480       }
   482    481       if( sqlite3ExprIdToTrueFalse(pExpr) ){
   483    482         return WRC_Prune;
   484    483       }
   485    484     }
   486    485   
................................................................................
   550    549   ** Allocate and return a pointer to an expression to load the column iCol
   551    550   ** from datasource iSrc in SrcList pSrc.
   552    551   */
   553    552   Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){
   554    553     Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0);
   555    554     if( p ){
   556    555       struct SrcList_item *pItem = &pSrc->a[iSrc];
   557         -    p->pTab = pItem->pTab;
          556  +    p->y.pTab = pItem->pTab;
   558    557       p->iTable = pItem->iCursor;
   559         -    if( p->pTab->iPKey==iCol ){
          558  +    if( p->y.pTab->iPKey==iCol ){
   560    559         p->iColumn = -1;
   561    560       }else{
   562    561         p->iColumn = (ynVar)iCol;
   563    562         testcase( iCol==BMS );
   564    563         testcase( iCol==BMS-1 );
   565    564         pItem->colUsed |= ((Bitmask)1)<<(iCol>=BMS ? BMS-1 : iCol);
   566    565       }
................................................................................
   642    641       case TK_ROW: {
   643    642         SrcList *pSrcList = pNC->pSrcList;
   644    643         struct SrcList_item *pItem;
   645    644         assert( pSrcList && pSrcList->nSrc==1 );
   646    645         pItem = pSrcList->a;
   647    646         assert( HasRowid(pItem->pTab) && pItem->pTab->pSelect==0 );
   648    647         pExpr->op = TK_COLUMN;
   649         -      pExpr->pTab = pItem->pTab;
          648  +      pExpr->y.pTab = pItem->pTab;
   650    649         pExpr->iTable = pItem->iCursor;
   651    650         pExpr->iColumn = -1;
   652    651         pExpr->affinity = SQLITE_AFF_INTEGER;
   653    652         break;
   654    653       }
   655    654   #endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT)
   656    655             && !defined(SQLITE_OMIT_SUBQUERY) */
................................................................................
   688    687           }
   689    688           zTable = pLeft->u.zToken;
   690    689           zColumn = pRight->u.zToken;
   691    690           if( IN_RENAME_OBJECT ){
   692    691             sqlite3RenameTokenRemap(pParse, (void*)pExpr, (void*)pRight);
   693    692           }
   694    693           if( IN_RENAME_OBJECT ){
   695         -          sqlite3RenameTokenRemap(pParse, (void*)&pExpr->pTab, (void*)pLeft);
          694  +          sqlite3RenameTokenRemap(pParse, (void*)&pExpr->y.pTab, (void*)pLeft);
   696    695           }
   697    696         }
   698    697         return lookupName(pParse, zDb, zTable, zColumn, pNC, pExpr);
   699    698       }
   700    699   
   701    700       /* Resolve function names
   702    701       */
................................................................................
   778    777   
   779    778         if( 0==IN_RENAME_OBJECT ){
   780    779   #ifndef SQLITE_OMIT_WINDOWFUNC
   781    780           assert( is_agg==0 || (pDef->funcFlags & SQLITE_FUNC_MINMAX)
   782    781             || (pDef->xValue==0 && pDef->xInverse==0)
   783    782             || (pDef->xValue && pDef->xInverse && pDef->xSFunc && pDef->xFinalize)
   784    783           );
   785         -        if( pDef && pDef->xValue==0 && pExpr->pWin ){
          784  +        if( pDef && pDef->xValue==0 && ExprHasProperty(pExpr, EP_WinFunc) ){
   786    785             sqlite3ErrorMsg(pParse, 
   787    786                 "%.*s() may not be used as a window function", nId, zId
   788    787             );
   789    788             pNC->nErr++;
   790    789           }else if( 
   791    790                 (is_agg && (pNC->ncFlags & NC_AllowAgg)==0)
   792         -           || (is_agg && (pDef->funcFlags & SQLITE_FUNC_WINDOW) && !pExpr->pWin)
   793         -           || (is_agg && pExpr->pWin && (pNC->ncFlags & NC_AllowWin)==0)
          791  +           || (is_agg && (pDef->funcFlags&SQLITE_FUNC_WINDOW) && !pExpr->y.pWin)
          792  +           || (is_agg && pExpr->y.pWin && (pNC->ncFlags & NC_AllowWin)==0)
   794    793           ){
   795    794             const char *zType;
   796         -          if( (pDef->funcFlags & SQLITE_FUNC_WINDOW) || pExpr->pWin ){
          795  +          if( (pDef->funcFlags & SQLITE_FUNC_WINDOW) || pExpr->y.pWin ){
   797    796               zType = "window";
   798    797             }else{
   799    798               zType = "aggregate";
   800    799             }
   801    800             sqlite3ErrorMsg(pParse, "misuse of %s function %.*s()",zType,nId,zId);
   802    801             pNC->nErr++;
   803    802             is_agg = 0;
................................................................................
   819    818           }else if( wrong_num_args ){
   820    819             sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()",
   821    820                  nId, zId);
   822    821             pNC->nErr++;
   823    822           }
   824    823           if( is_agg ){
   825    824   #ifndef SQLITE_OMIT_WINDOWFUNC
   826         -          pNC->ncFlags &= ~(pExpr->pWin ? NC_AllowWin : NC_AllowAgg);
          825  +          pNC->ncFlags &= ~(pExpr->y.pWin ? NC_AllowWin : NC_AllowAgg);
   827    826   #else
   828    827             pNC->ncFlags &= ~NC_AllowAgg;
   829    828   #endif
   830    829           }
   831    830         }
   832    831         sqlite3WalkExprList(pWalker, pList);
   833    832         if( is_agg ){
   834    833   #ifndef SQLITE_OMIT_WINDOWFUNC
   835         -        if( pExpr->pWin ){
          834  +        if( pExpr->y.pWin ){
   836    835             Select *pSel = pNC->pWinSelect;
   837         -          sqlite3WalkExprList(pWalker, pExpr->pWin->pPartition);
   838         -          sqlite3WalkExprList(pWalker, pExpr->pWin->pOrderBy);
   839         -          sqlite3WalkExpr(pWalker, pExpr->pWin->pFilter);
   840         -          sqlite3WindowUpdate(pParse, pSel->pWinDefn, pExpr->pWin, pDef);
          836  +          sqlite3WalkExprList(pWalker, pExpr->y.pWin->pPartition);
          837  +          sqlite3WalkExprList(pWalker, pExpr->y.pWin->pOrderBy);
          838  +          sqlite3WalkExpr(pWalker, pExpr->y.pWin->pFilter);
          839  +          sqlite3WindowUpdate(pParse, pSel->pWinDefn, pExpr->y.pWin, pDef);
   841    840             if( 0==pSel->pWin 
   842         -           || 0==sqlite3WindowCompare(pParse, pSel->pWin, pExpr->pWin) 
          841  +           || 0==sqlite3WindowCompare(pParse, pSel->pWin, pExpr->y.pWin) 
   843    842             ){
   844         -            pExpr->pWin->pNextWin = pSel->pWin;
   845         -            pSel->pWin = pExpr->pWin;
          843  +            pExpr->y.pWin->pNextWin = pSel->pWin;
          844  +            pSel->pWin = pExpr->y.pWin;
   846    845             }
   847    846             pNC->ncFlags |= NC_AllowWin;
   848    847           }else
   849    848   #endif /* SQLITE_OMIT_WINDOWFUNC */
   850    849           {
   851    850             NameContext *pNC2 = pNC;
   852    851             pExpr->op = TK_AGG_FUNCTION;
................................................................................
  1261   1260       pItem->u.x.iOrderByCol = 0;
  1262   1261       if( sqlite3ResolveExprNames(pNC, pE) ){
  1263   1262         return 1;
  1264   1263       }
  1265   1264       for(j=0; j<pSelect->pEList->nExpr; j++){
  1266   1265         if( sqlite3ExprCompare(0, pE, pSelect->pEList->a[j].pExpr, -1)==0 ){
  1267   1266   #ifndef SQLITE_OMIT_WINDOWFUNC
  1268         -        if( pE->pWin ){
         1267  +        if( ExprHasProperty(pE, EP_WinFunc) ){
  1269   1268             /* Since this window function is being changed into a reference
  1270   1269             ** to the same window function the result set, remove the instance
  1271   1270             ** of this window function from the Select.pWin list. */
  1272   1271             Window **pp;
  1273   1272             for(pp=&pSelect->pWin; *pp; pp=&(*pp)->pNextWin){
  1274         -            if( *pp==pE->pWin ){
         1273  +            if( *pp==pE->y.pWin ){
  1275   1274                 *pp = (*pp)->pNextWin;
  1276   1275               }    
  1277   1276             }
  1278   1277           }
  1279   1278   #endif
  1280   1279           pItem->u.x.iOrderByCol = j+1;
  1281   1280         }

Changes to src/select.c.

   799    799     int i;
   800    800     int nDefer = 0;
   801    801     ExprList *pExtra = 0;
   802    802     for(i=0; i<pEList->nExpr; i++){
   803    803       struct ExprList_item *pItem = &pEList->a[i];
   804    804       if( pItem->u.x.iOrderByCol==0 ){
   805    805         Expr *pExpr = pItem->pExpr;
   806         -      Table *pTab = pExpr->pTab;
          806  +      Table *pTab = pExpr->y.pTab;
   807    807         if( pExpr->op==TK_COLUMN && pExpr->iColumn>=0 && pTab && !IsVirtual(pTab)
   808    808          && (pTab->aCol[pExpr->iColumn].colFlags & COLFLAG_SORTERREF)
   809    809         ){
   810    810           int j;
   811    811           for(j=0; j<nDefer; j++){
   812    812             if( pSort->aDefer[j].iCsr==pExpr->iTable ) break;
   813    813           }
................................................................................
   822    822                 pPk = sqlite3PrimaryKeyIndex(pTab);
   823    823                 nKey = pPk->nKeyCol;
   824    824               }
   825    825               for(k=0; k<nKey; k++){
   826    826                 Expr *pNew = sqlite3PExpr(pParse, TK_COLUMN, 0, 0);
   827    827                 if( pNew ){
   828    828                   pNew->iTable = pExpr->iTable;
   829         -                pNew->pTab = pExpr->pTab;
          829  +                pNew->y.pTab = pExpr->y.pTab;
   830    830                   pNew->iColumn = pPk ? pPk->aiColumn[k] : -1;
   831    831                   pExtra = sqlite3ExprListAppend(pParse, pExtra, pNew);
   832    832                 }
   833    833               }
   834         -            pSort->aDefer[nDefer].pTab = pExpr->pTab;
          834  +            pSort->aDefer[nDefer].pTab = pExpr->y.pTab;
   835    835               pSort->aDefer[nDefer].iCsr = pExpr->iTable;
   836    836               pSort->aDefer[nDefer].nKey = nKey;
   837    837               nDefer++;
   838    838             }
   839    839           }
   840    840           pItem->bSorterRef = 1;
   841    841         }
................................................................................
  1676   1676           ** This is not a problem, as the column type of "t1.col" is never
  1677   1677           ** used. When columnType() is called on the expression 
  1678   1678           ** "(SELECT t1.col)", the correct type is returned (see the TK_SELECT
  1679   1679           ** branch below.  */
  1680   1680           break;
  1681   1681         }
  1682   1682   
  1683         -      assert( pTab && pExpr->pTab==pTab );
         1683  +      assert( pTab && pExpr->y.pTab==pTab );
  1684   1684         if( pS ){
  1685   1685           /* The "table" is actually a sub-select or a view in the FROM clause
  1686   1686           ** of the SELECT statement. Return the declaration type and origin
  1687   1687           ** data for the result-set column of the sub-select.
  1688   1688           */
  1689   1689           if( iCol>=0 && iCol<pS->pEList->nExpr ){
  1690   1690             /* If iCol is less than zero, then the expression requests the
................................................................................
  1861   1861     srcName = (db->flags & SQLITE_ShortColNames)!=0 || fullName;
  1862   1862     sqlite3VdbeSetNumCols(v, pEList->nExpr);
  1863   1863     for(i=0; i<pEList->nExpr; i++){
  1864   1864       Expr *p = pEList->a[i].pExpr;
  1865   1865   
  1866   1866       assert( p!=0 );
  1867   1867       assert( p->op!=TK_AGG_COLUMN );  /* Agg processing has not run yet */
  1868         -    assert( p->op!=TK_COLUMN || p->pTab!=0 ); /* Covering idx not yet coded */
         1868  +    assert( p->op!=TK_COLUMN || p->y.pTab!=0 ); /* Covering idx not yet coded */
  1869   1869       if( pEList->a[i].zName ){
  1870   1870         /* An AS clause always takes first priority */
  1871   1871         char *zName = pEList->a[i].zName;
  1872   1872         sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
  1873   1873       }else if( srcName && p->op==TK_COLUMN ){
  1874   1874         char *zCol;
  1875   1875         int iCol = p->iColumn;
  1876         -      pTab = p->pTab;
         1876  +      pTab = p->y.pTab;
  1877   1877         assert( pTab!=0 );
  1878   1878         if( iCol<0 ) iCol = pTab->iPKey;
  1879   1879         assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
  1880   1880         if( iCol<0 ){
  1881   1881           zCol = "rowid";
  1882   1882         }else{
  1883   1883           zCol = pTab->aCol[iCol].zName;
................................................................................
  1960   1960           pColExpr = pColExpr->pRight;
  1961   1961           assert( pColExpr!=0 );
  1962   1962         }
  1963   1963         assert( pColExpr->op!=TK_AGG_COLUMN );
  1964   1964         if( pColExpr->op==TK_COLUMN ){
  1965   1965           /* For columns use the column name name */
  1966   1966           int iCol = pColExpr->iColumn;
  1967         -        Table *pTab = pColExpr->pTab;
         1967  +        Table *pTab = pColExpr->y.pTab;
  1968   1968           assert( pTab!=0 );
  1969   1969           if( iCol<0 ) iCol = pTab->iPKey;
  1970   1970           zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid";
  1971   1971         }else if( pColExpr->op==TK_ID ){
  1972   1972           assert( !ExprHasProperty(pColExpr, EP_IntValue) );
  1973   1973           zName = pColExpr->u.zToken;
  1974   1974         }else{

Changes to src/sqliteInt.h.

  2455   2455                            ** TK_SELECT_COLUMN: column of the result vector */
  2456   2456     i16 iAgg;              /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
  2457   2457     i16 iRightJoinTable;   /* If EP_FromJoin, the right table of the join */
  2458   2458     u8 op2;                /* TK_REGISTER: original value of Expr.op
  2459   2459                            ** TK_COLUMN: the value of p5 for OP_Column
  2460   2460                            ** TK_AGG_FUNCTION: nesting depth */
  2461   2461     AggInfo *pAggInfo;     /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
  2462         -  Table *pTab;           /* Table for TK_COLUMN expressions.  Can be NULL
  2463         -                         ** for a column of an index on an expression */
  2464         -#ifndef SQLITE_OMIT_WINDOWFUNC
  2465         -  Window *pWin;          /* Window definition for window functions */
  2466         -#endif
         2462  +  union {
         2463  +    Table *pTab;           /* TK_COLUMN: Table containing column. Can be NULL
         2464  +                           ** for a column of an index on an expression */
         2465  +    Window *pWin;          /* TK_FUNCTION: Window definition for the func */
         2466  +  } y;
  2467   2467   };
  2468   2468   
  2469   2469   /*
  2470   2470   ** The following are the meanings of bits in the Expr.flags field.
  2471   2471   */
  2472   2472   #define EP_FromJoin  0x000001 /* Originates in ON/USING clause of outer join */
  2473   2473   #define EP_Agg       0x000002 /* Contains one or more aggregate functions */
................................................................................
  2489   2489   #define EP_NoReduce  0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
  2490   2490   #define EP_Unlikely  0x040000 /* unlikely() or likelihood() function */
  2491   2491   #define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
  2492   2492   #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
  2493   2493   #define EP_Subquery  0x200000 /* Tree contains a TK_SELECT operator */
  2494   2494   #define EP_Alias     0x400000 /* Is an alias for a result set column */
  2495   2495   #define EP_Leaf      0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
         2496  +#define EP_WinFunc  0x1000000 /* TK_FUNCTION with Expr.y.pWin set */
  2496   2497   
  2497   2498   /*
  2498   2499   ** The EP_Propagate mask is a set of properties that automatically propagate
  2499   2500   ** upwards into parent nodes.
  2500   2501   */
  2501   2502   #define EP_Propagate (EP_Collate|EP_Subquery|EP_HasFunc)
  2502   2503   

Changes to src/treeview.c.

   493    493         Window *pWin;
   494    494         if( ExprHasProperty(pExpr, EP_TokenOnly) ){
   495    495           pFarg = 0;
   496    496           pWin = 0;
   497    497         }else{
   498    498           pFarg = pExpr->x.pList;
   499    499   #ifndef SQLITE_OMIT_WINDOWFUNC
   500         -        pWin = pExpr->pWin;
          500  +        pWin = pExpr->y.pWin;
   501    501   #else
   502    502           pWin = 0;
   503    503   #endif 
   504    504         }
   505    505         if( pExpr->op==TK_AGG_FUNCTION ){
   506    506           sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q",
   507    507                                pExpr->op2, pExpr->u.zToken);

Changes to src/vtab.c.

  1049   1049     void *pArg = 0;
  1050   1050     FuncDef *pNew;
  1051   1051     int rc = 0;
  1052   1052   
  1053   1053     /* Check to see the left operand is a column in a virtual table */
  1054   1054     if( NEVER(pExpr==0) ) return pDef;
  1055   1055     if( pExpr->op!=TK_COLUMN ) return pDef;
  1056         -  pTab = pExpr->pTab;
         1056  +  pTab = pExpr->y.pTab;
  1057   1057     if( pTab==0 ) return pDef;
  1058   1058     if( !IsVirtual(pTab) ) return pDef;
  1059   1059     pVtab = sqlite3GetVTable(db, pTab)->pVtab;
  1060   1060     assert( pVtab!=0 );
  1061   1061     assert( pVtab->pModule!=0 );
  1062   1062     pMod = (sqlite3_module *)pVtab->pModule;
  1063   1063     if( pMod->xFindFunction==0 ) return pDef;

Changes to src/walker.c.

    51     51           continue;
    52     52         }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){
    53     53           if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
    54     54         }else if( pExpr->x.pList ){
    55     55           if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
    56     56         }
    57     57   #ifndef SQLITE_OMIT_WINDOWFUNC
    58         -      if( !ExprHasProperty(pExpr, EP_Reduced) && pExpr->pWin ){
    59         -        Window *pWin = pExpr->pWin;
           58  +      if( ExprHasProperty(pExpr, EP_WinFunc) ){
           59  +        Window *pWin = pExpr->y.pWin;
    60     60           if( sqlite3WalkExprList(pWalker, pWin->pPartition) ) return WRC_Abort;
    61     61           if( sqlite3WalkExprList(pWalker, pWin->pOrderBy) ) return WRC_Abort;
    62     62           if( sqlite3WalkExpr(pWalker, pWin->pFilter) ) return WRC_Abort;
    63     63         }
    64     64   #endif
    65     65       }
    66     66       break;

Changes to src/wherecode.c.

  1113   1113   */
  1114   1114   static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
  1115   1115     IdxExprTrans *pX = p->u.pIdxTrans;
  1116   1116     if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
  1117   1117       pExpr->op = TK_COLUMN;
  1118   1118       pExpr->iTable = pX->iIdxCur;
  1119   1119       pExpr->iColumn = pX->iIdxCol;
  1120         -    pExpr->pTab = 0;
         1120  +    pExpr->y.pTab = 0;
  1121   1121       return WRC_Prune;
  1122   1122     }else{
  1123   1123       return WRC_Continue;
  1124   1124     }
  1125   1125   }
  1126   1126   
  1127   1127   /*

Changes to src/whereexpr.c.

   277    277           */
   278    278           if( sqlite3Isdigit(zNew[0])
   279    279            || zNew[0]=='-'
   280    280            || (zNew[0]+1=='0' && iTo==1)
   281    281           ){
   282    282             if( pLeft->op!=TK_COLUMN 
   283    283              || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT 
   284         -           || IsVirtual(pLeft->pTab)  /* Value might be numeric */
          284  +           || IsVirtual(pLeft->y.pTab)  /* Value might be numeric */
   285    285             ){
   286    286               sqlite3ExprDelete(db, pPrefix);
   287    287               sqlite3ValueFree(pVal);
   288    288               return 0;
   289    289             }
   290    290           }
   291    291         }
................................................................................
   378    378       ** virtual table on their second argument, which is the same as
   379    379       ** the left-hand side operand in their in-fix form.
   380    380       **
   381    381       **       vtab_column MATCH expression
   382    382       **       MATCH(expression,vtab_column)
   383    383       */
   384    384       pCol = pList->a[1].pExpr;
   385         -    if( pCol->op==TK_COLUMN && IsVirtual(pCol->pTab) ){
          385  +    if( pCol->op==TK_COLUMN && IsVirtual(pCol->y.pTab) ){
   386    386         for(i=0; i<ArraySize(aOp); i++){
   387    387           if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){
   388    388             *peOp2 = aOp[i].eOp2;
   389    389             *ppRight = pList->a[0].pExpr;
   390    390             *ppLeft = pCol;
   391    391             return 1;
   392    392           }
................................................................................
   400    400       **      OVERLOADED(vtab_column,expression)
   401    401       **
   402    402       ** Historically, xFindFunction expected to see lower-case function
   403    403       ** names.  But for this use case, xFindFunction is expected to deal
   404    404       ** with function names in an arbitrary case.
   405    405       */
   406    406       pCol = pList->a[0].pExpr;
   407         -    if( pCol->op==TK_COLUMN && IsVirtual(pCol->pTab) ){
          407  +    if( pCol->op==TK_COLUMN && IsVirtual(pCol->y.pTab) ){
   408    408         sqlite3_vtab *pVtab;
   409    409         sqlite3_module *pMod;
   410    410         void (*xNotUsed)(sqlite3_context*,int,sqlite3_value**);
   411    411         void *pNotUsed;
   412         -      pVtab = sqlite3GetVTable(db, pCol->pTab)->pVtab;
          412  +      pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab;
   413    413         assert( pVtab!=0 );
   414    414         assert( pVtab->pModule!=0 );
   415    415         pMod = (sqlite3_module *)pVtab->pModule;
   416    416         if( pMod->xFindFunction!=0 ){
   417    417           i = pMod->xFindFunction(pVtab,2, pExpr->u.zToken, &xNotUsed, &pNotUsed);
   418    418           if( i>=SQLITE_INDEX_CONSTRAINT_FUNCTION ){
   419    419             *peOp2 = i;
................................................................................
   423    423           }
   424    424         }
   425    425       }
   426    426     }else if( pExpr->op==TK_NE || pExpr->op==TK_ISNOT || pExpr->op==TK_NOTNULL ){
   427    427       int res = 0;
   428    428       Expr *pLeft = pExpr->pLeft;
   429    429       Expr *pRight = pExpr->pRight;
   430         -    if( pLeft->op==TK_COLUMN && IsVirtual(pLeft->pTab) ){
          430  +    if( pLeft->op==TK_COLUMN && IsVirtual(pLeft->y.pTab) ){
   431    431         res++;
   432    432       }
   433         -    if( pRight && pRight->op==TK_COLUMN && IsVirtual(pRight->pTab) ){
          433  +    if( pRight && pRight->op==TK_COLUMN && IsVirtual(pRight->y.pTab) ){
   434    434         res++;
   435    435         SWAP(Expr*, pLeft, pRight);
   436    436       }
   437    437       *ppLeft = pLeft;
   438    438       *ppRight = pRight;
   439    439       if( pExpr->op==TK_NE ) *peOp2 = SQLITE_INDEX_CONSTRAINT_NE;
   440    440       if( pExpr->op==TK_ISNOT ) *peOp2 = SQLITE_INDEX_CONSTRAINT_ISNOT;
................................................................................
  1579   1579                         pTab->zName, j);
  1580   1580         return;
  1581   1581       }
  1582   1582       pColRef = sqlite3ExprAlloc(pParse->db, TK_COLUMN, 0, 0);
  1583   1583       if( pColRef==0 ) return;
  1584   1584       pColRef->iTable = pItem->iCursor;
  1585   1585       pColRef->iColumn = k++;
  1586         -    pColRef->pTab = pTab;
         1586  +    pColRef->y.pTab = pTab;
  1587   1587       pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef,
  1588   1588                            sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0));
  1589   1589       whereClauseInsert(pWC, pTerm, TERM_DYNAMIC);
  1590   1590     }
  1591   1591   }

Changes to src/window.c.

   620    620         if( i==nSrc ) return WRC_Continue;
   621    621       }
   622    622     }
   623    623   
   624    624     switch( pExpr->op ){
   625    625   
   626    626       case TK_FUNCTION:
   627         -      if( pExpr->pWin==0 ){
          627  +      if( !ExprHasProperty(pExpr, EP_WinFunc) ){
   628    628           break;
   629    629         }else{
   630    630           Window *pWin;
   631    631           for(pWin=p->pWin; pWin; pWin=pWin->pNextWin){
   632         -          if( pExpr->pWin==pWin ){
          632  +          if( pExpr->y.pWin==pWin ){
   633    633               assert( pWin->pOwner==pExpr );
   634    634               return WRC_Prune;
   635    635             }
   636    636           }
   637    637         }
   638    638         /* Fall through.  */
   639    639   
................................................................................
   955    955   }
   956    956   
   957    957   /*
   958    958   ** Attach window object pWin to expression p.
   959    959   */
   960    960   void sqlite3WindowAttach(Parse *pParse, Expr *p, Window *pWin){
   961    961     if( p ){
          962  +    assert( p->op==TK_FUNCTION );
   962    963       /* This routine is only called for the parser.  If pWin was not
   963    964       ** allocated due to an OOM, then the parser would fail before ever
   964    965       ** invoking this routine */
   965    966       if( ALWAYS(pWin) ){
   966         -      p->pWin = pWin;
          967  +      p->y.pWin = pWin;
          968  +      ExprSetProperty(p, EP_WinFunc);
   967    969         pWin->pOwner = p;
   968    970         if( p->flags & EP_Distinct ){
   969    971           sqlite3ErrorMsg(pParse,
   970    972              "DISTINCT is not supported for window functions");
   971    973         }
   972    974       }
   973    975     }else{
................................................................................
  2122   2124   /*
  2123   2125   ** Allocate and return a duplicate of the Window object indicated by the
  2124   2126   ** third argument. Set the Window.pOwner field of the new object to
  2125   2127   ** pOwner.
  2126   2128   */
  2127   2129   Window *sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p){
  2128   2130     Window *pNew = 0;
  2129         -  if( p ){
         2131  +  if( ALWAYS(p) ){
  2130   2132       pNew = sqlite3DbMallocZero(db, sizeof(Window));
  2131   2133       if( pNew ){
  2132   2134         pNew->zName = sqlite3DbStrDup(db, p->zName);
  2133   2135         pNew->pFilter = sqlite3ExprDup(db, p->pFilter, 0);
  2134   2136         pNew->pPartition = sqlite3ExprListDup(db, p->pPartition, 0);
  2135   2137         pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, 0);
  2136   2138         pNew->eType = p->eType;