/ Check-in [2a81763e]
Login

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

Overview
Comment:Performance improvement and size reduction in the Expr node allocator function sqlite3PExpr().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2a81763e68cdf9b8c46389b1e1a87bc2084b53e7
User & Date: drh 2016-12-06 22:47:23
Context
2016-12-07
13:49
Always honor the sqlite3.dbOptFlags bitmask, regardless of compile-time options. Continuing fix for ticket [da78413751863]. check-in: afab1663 user: drh tags: trunk
07:46
Merge latest trunk changes into this branch. Leaf check-in: 391344d8 user: dan tags: changebatch
2016-12-06
22:47
Performance improvement and size reduction in the Expr node allocator function sqlite3PExpr(). check-in: 2a81763e user: drh tags: trunk
19:33
Add missing nul-terminator to a Tcl_AppendResult() call in tclsqlite.c. check-in: 0820f8b3 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/delete.c.

   160    160     **   DELETE FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1
   161    161     ** becomes:
   162    162     **   DELETE FROM table_a WHERE rowid IN ( 
   163    163     **     SELECT rowid FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1
   164    164     **   );
   165    165     */
   166    166   
   167         -  pSelectRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0);
          167  +  pSelectRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0);
   168    168     if( pSelectRowid == 0 ) goto limit_where_cleanup;
   169    169     pEList = sqlite3ExprListAppend(pParse, 0, pSelectRowid);
   170    170     if( pEList == 0 ) goto limit_where_cleanup;
   171    171   
   172    172     /* duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree
   173    173     ** and the SELECT subtree. */
   174    174     pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc, 0);
................................................................................
   179    179   
   180    180     /* generate the SELECT expression tree. */
   181    181     pSelect = sqlite3SelectNew(pParse,pEList,pSelectSrc,pWhere,0,0,
   182    182                                pOrderBy,0,pLimit,pOffset);
   183    183     if( pSelect == 0 ) return 0;
   184    184   
   185    185     /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */
   186         -  pWhereRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0);
   187         -  pInClause = pWhereRowid ? sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0, 0) : 0;
          186  +  pWhereRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0);
          187  +  pInClause = pWhereRowid ? sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0) : 0;
   188    188     sqlite3PExprAddSelect(pParse, pInClause, pSelect);
   189    189     return pInClause;
   190    190   
   191    191   limit_where_cleanup:
   192    192     sqlite3ExprDelete(pParse->db, pWhere);
   193    193     sqlite3ExprListDelete(pParse->db, pOrderBy);
   194    194     sqlite3ExprDelete(pParse->db, pLimit);

Changes to src/expr.c.

   423    423       ** sqlite3ExprDelete() specifically skips the recursive delete of
   424    424       ** pLeft on TK_SELECT_COLUMN nodes.  But pRight is followed, so pVector
   425    425       ** can be attached to pRight to cause this node to take ownership of
   426    426       ** pVector.  Typically there will be multiple TK_SELECT_COLUMN nodes
   427    427       ** with the same pLeft pointer to the pVector, but only one of them
   428    428       ** will own the pVector.
   429    429       */
   430         -    pRet = sqlite3PExpr(pParse, TK_SELECT_COLUMN, 0, 0, 0);
          430  +    pRet = sqlite3PExpr(pParse, TK_SELECT_COLUMN, 0, 0);
   431    431       if( pRet ){
   432    432         pRet->iColumn = iField;
   433    433         pRet->pLeft = pVector;
   434    434       }
   435    435       assert( pRet==0 || pRet->iTable==0 );
   436    436     }else{
   437    437       if( pVector->op==TK_VECTOR ) pVector = pVector->x.pList->a[iField].pExpr;
................................................................................
   815    815   ** Expr node.  Or, if an OOM error occurs, set pParse->db->mallocFailed,
   816    816   ** free the subtrees and return NULL.
   817    817   */
   818    818   Expr *sqlite3PExpr(
   819    819     Parse *pParse,          /* Parsing context */
   820    820     int op,                 /* Expression opcode */
   821    821     Expr *pLeft,            /* Left operand */
   822         -  Expr *pRight,           /* Right operand */
   823         -  const Token *pToken     /* Argument token */
          822  +  Expr *pRight            /* Right operand */
   824    823   ){
   825    824     Expr *p;
   826    825     if( op==TK_AND && pParse->nErr==0 ){
   827    826       /* Take advantage of short-circuit false optimization for AND */
   828    827       p = sqlite3ExprAnd(pParse->db, pLeft, pRight);
   829    828     }else{
   830         -    p = sqlite3ExprAlloc(pParse->db, op & TKFLG_MASK, pToken, 1);
          829  +    p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr));
          830  +    if( p ){
          831  +      memset(p, 0, sizeof(Expr));
          832  +      p->op = op & TKFLG_MASK;
          833  +      p->iAgg = -1;
          834  +    }
   831    835       sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
   832    836     }
   833    837     if( p ) {
   834    838       sqlite3ExprCheckHeight(pParse, p->nHeight);
   835    839     }
   836    840     return p;
   837    841   }

Changes to src/fkey.c.

   580    580   
   581    581       iCol = pIdx ? pIdx->aiColumn[i] : -1;
   582    582       pLeft = exprTableRegister(pParse, pTab, regData, iCol);
   583    583       iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
   584    584       assert( iCol>=0 );
   585    585       zCol = pFKey->pFrom->aCol[iCol].zName;
   586    586       pRight = sqlite3Expr(db, TK_ID, zCol);
   587         -    pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0);
          587  +    pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight);
   588    588       pWhere = sqlite3ExprAnd(db, pWhere, pEq);
   589    589     }
   590    590   
   591    591     /* If the child table is the same as the parent table, then add terms
   592    592     ** to the WHERE clause that prevent this entry from being scanned.
   593    593     ** The added WHERE clause terms are like this:
   594    594     **
................................................................................
   602    602     if( pTab==pFKey->pFrom && nIncr>0 ){
   603    603       Expr *pNe;                    /* Expression (pLeft != pRight) */
   604    604       Expr *pLeft;                  /* Value from parent table row */
   605    605       Expr *pRight;                 /* Column ref to child table */
   606    606       if( HasRowid(pTab) ){
   607    607         pLeft = exprTableRegister(pParse, pTab, regData, -1);
   608    608         pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1);
   609         -      pNe = sqlite3PExpr(pParse, TK_NE, pLeft, pRight, 0);
          609  +      pNe = sqlite3PExpr(pParse, TK_NE, pLeft, pRight);
   610    610       }else{
   611    611         Expr *pEq, *pAll = 0;
   612    612         Index *pPk = sqlite3PrimaryKeyIndex(pTab);
   613    613         assert( pIdx!=0 );
   614    614         for(i=0; i<pPk->nKeyCol; i++){
   615    615           i16 iCol = pIdx->aiColumn[i];
   616    616           assert( iCol>=0 );
   617    617           pLeft = exprTableRegister(pParse, pTab, regData, iCol);
   618    618           pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, iCol);
   619         -        pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0);
          619  +        pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight);
   620    620           pAll = sqlite3ExprAnd(db, pAll, pEq);
   621    621         }
   622         -      pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0, 0);
          622  +      pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0);
   623    623       }
   624    624       pWhere = sqlite3ExprAnd(db, pWhere, pNe);
   625    625     }
   626    626   
   627    627     /* Resolve the references in the WHERE clause. */
   628    628     memset(&sNameContext, 0, sizeof(NameContext));
   629    629     sNameContext.pSrcList = pSrc;
................................................................................
  1201   1201         /* Create the expression "OLD.zToCol = zFromCol". It is important
  1202   1202         ** that the "OLD.zToCol" term is on the LHS of the = operator, so
  1203   1203         ** that the affinity and collation sequence associated with the
  1204   1204         ** parent table are used for the comparison. */
  1205   1205         pEq = sqlite3PExpr(pParse, TK_EQ,
  1206   1206             sqlite3PExpr(pParse, TK_DOT, 
  1207   1207               sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
  1208         -            sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
  1209         -          , 0),
         1208  +            sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)),
  1210   1209             sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0)
  1211         -      , 0);
         1210  +      );
  1212   1211         pWhere = sqlite3ExprAnd(db, pWhere, pEq);
  1213   1212   
  1214   1213         /* For ON UPDATE, construct the next term of the WHEN clause.
  1215   1214         ** The final WHEN clause will be like this:
  1216   1215         **
  1217   1216         **    WHEN NOT(old.col1 IS new.col1 AND ... AND old.colN IS new.colN)
  1218   1217         */
  1219   1218         if( pChanges ){
  1220   1219           pEq = sqlite3PExpr(pParse, TK_IS,
  1221   1220               sqlite3PExpr(pParse, TK_DOT, 
  1222   1221                 sqlite3ExprAlloc(db, TK_ID, &tOld, 0),
  1223         -              sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
  1224         -              0),
         1222  +              sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)),
  1225   1223               sqlite3PExpr(pParse, TK_DOT, 
  1226   1224                 sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
  1227         -              sqlite3ExprAlloc(db, TK_ID, &tToCol, 0),
  1228         -              0),
  1229         -            0);
         1225  +              sqlite3ExprAlloc(db, TK_ID, &tToCol, 0))
         1226  +            );
  1230   1227           pWhen = sqlite3ExprAnd(db, pWhen, pEq);
  1231   1228         }
  1232   1229     
  1233   1230         if( action!=OE_Restrict && (action!=OE_Cascade || pChanges) ){
  1234   1231           Expr *pNew;
  1235   1232           if( action==OE_Cascade ){
  1236   1233             pNew = sqlite3PExpr(pParse, TK_DOT, 
  1237   1234               sqlite3ExprAlloc(db, TK_ID, &tNew, 0),
  1238         -            sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)
  1239         -          , 0);
         1235  +            sqlite3ExprAlloc(db, TK_ID, &tToCol, 0));
  1240   1236           }else if( action==OE_SetDflt ){
  1241   1237             Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt;
  1242   1238             if( pDflt ){
  1243   1239               pNew = sqlite3ExprDup(db, pDflt, 0);
  1244   1240             }else{
  1245   1241               pNew = sqlite3ExprAlloc(db, TK_NULL, 0, 0);
  1246   1242             }
................................................................................
  1288   1284         pStep->zTarget = (char *)&pStep[1];
  1289   1285         memcpy((char *)pStep->zTarget, zFrom, nFrom);
  1290   1286     
  1291   1287         pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE);
  1292   1288         pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE);
  1293   1289         pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE);
  1294   1290         if( pWhen ){
  1295         -        pWhen = sqlite3PExpr(pParse, TK_NOT, pWhen, 0, 0);
         1291  +        pWhen = sqlite3PExpr(pParse, TK_NOT, pWhen, 0);
  1296   1292           pTrigger->pWhen = sqlite3ExprDup(db, pWhen, EXPRDUP_REDUCE);
  1297   1293         }
  1298   1294       }
  1299   1295   
  1300   1296       /* Re-enable the lookaside buffer, if it was disabled earlier. */
  1301   1297       db->lookaside.bDisable--;
  1302   1298   

Changes to src/parse.y.

   264    264   carglist ::= .
   265    265   ccons ::= CONSTRAINT nm(X).           {pParse->constraintName = X;}
   266    266   ccons ::= DEFAULT term(X).            {sqlite3AddDefaultValue(pParse,&X);}
   267    267   ccons ::= DEFAULT LP expr(X) RP.      {sqlite3AddDefaultValue(pParse,&X);}
   268    268   ccons ::= DEFAULT PLUS term(X).       {sqlite3AddDefaultValue(pParse,&X);}
   269    269   ccons ::= DEFAULT MINUS(A) term(X).      {
   270    270     ExprSpan v;
   271         -  v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, X.pExpr, 0, 0);
          271  +  v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, X.pExpr, 0);
   272    272     v.zStart = A.z;
   273    273     v.zEnd = X.zEnd;
   274    274     sqlite3AddDefaultValue(pParse,&v);
   275    275   }
   276    276   ccons ::= DEFAULT id(X).              {
   277    277     ExprSpan v;
   278    278     spanExpr(&v, pParse, TK_STRING, X);
................................................................................
   539    539      sqlite3ExprListSetSpan(pParse,A,&X);
   540    540   }
   541    541   selcollist(A) ::= sclp(A) STAR. {
   542    542     Expr *p = sqlite3Expr(pParse->db, TK_ASTERISK, 0);
   543    543     A = sqlite3ExprListAppend(pParse, A, p);
   544    544   }
   545    545   selcollist(A) ::= sclp(A) nm(X) DOT STAR. {
   546         -  Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0, 0);
   547         -  Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &X);
   548         -  Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
          546  +  Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0);
          547  +  Expr *pLeft = sqlite3ExprAlloc(pParse->db, TK_ID, &X, 1);
          548  +  Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
   549    549     A = sqlite3ExprListAppend(pParse,A, pDot);
   550    550   }
   551    551   
   552    552   // An option "AS <id>" phrase that can follow one of the expressions that
   553    553   // define the result set, or one of the tables in the FROM clause.
   554    554   //
   555    555   %type as {Token}
................................................................................
   866    866   term(A) ::= NULL(X).        {spanExpr(&A,pParse,@X,X);/*A-overwrites-X*/}
   867    867   expr(A) ::= id(X).          {spanExpr(&A,pParse,TK_ID,X); /*A-overwrites-X*/}
   868    868   expr(A) ::= JOIN_KW(X).     {spanExpr(&A,pParse,TK_ID,X); /*A-overwrites-X*/}
   869    869   expr(A) ::= nm(X) DOT nm(Y). {
   870    870     Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &X, 1);
   871    871     Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &Y, 1);
   872    872     spanSet(&A,&X,&Y); /*A-overwrites-X*/
   873         -  A.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0);
          873  +  A.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2);
   874    874   }
   875    875   expr(A) ::= nm(X) DOT nm(Y) DOT nm(Z). {
   876    876     Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &X, 1);
   877    877     Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &Y, 1);
   878    878     Expr *temp3 = sqlite3ExprAlloc(pParse->db, TK_ID, &Z, 1);
   879         -  Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0);
          879  +  Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3);
   880    880     spanSet(&A,&X,&Z); /*A-overwrites-X*/
   881         -  A.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
          881  +  A.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
   882    882   }
   883    883   term(A) ::= FLOAT|BLOB(X). {spanExpr(&A,pParse,@X,X);/*A-overwrites-X*/}
   884    884   term(A) ::= STRING(X).     {spanExpr(&A,pParse,@X,X);/*A-overwrites-X*/}
   885    885   term(A) ::= INTEGER(X). {
   886    886     A.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &X, 1);
   887    887     A.zStart = X.z;
   888    888     A.zEnd = X.z + X.n;
................................................................................
   900    900       Token t = X; /*A-overwrites-X*/
   901    901       assert( t.n>=2 );
   902    902       spanSet(&A, &t, &t);
   903    903       if( pParse->nested==0 ){
   904    904         sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t);
   905    905         A.pExpr = 0;
   906    906       }else{
   907         -      A.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, 0);
          907  +      A.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0);
   908    908         if( A.pExpr ) sqlite3GetInt32(&t.z[1], &A.pExpr->iTable);
   909    909       }
   910    910     }
   911    911   }
   912    912   expr(A) ::= expr(A) COLLATE ids(C). {
   913    913     A.pExpr = sqlite3ExprAddCollateToken(pParse, A.pExpr, &C, 1);
   914    914     A.zEnd = &C.z[C.n];
   915    915   }
   916    916   %ifndef SQLITE_OMIT_CAST
   917    917   expr(A) ::= CAST(X) LP expr(E) AS typetoken(T) RP(Y). {
   918    918     spanSet(&A,&X,&Y); /*A-overwrites-X*/
   919         -  A.pExpr = sqlite3PExpr(pParse, TK_CAST, E.pExpr, 0, &T);
          919  +  A.pExpr = sqlite3ExprAlloc(pParse->db, TK_CAST, &T, 1);
          920  +  sqlite3ExprAttachSubtrees(pParse->db, A.pExpr, E.pExpr, 0);
   920    921   }
   921    922   %endif  SQLITE_OMIT_CAST
   922    923   expr(A) ::= id(X) LP distinct(D) exprlist(Y) RP(E). {
   923    924     if( Y && Y->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){
   924    925       sqlite3ErrorMsg(pParse, "too many arguments on function %T", &X);
   925    926     }
   926    927     A.pExpr = sqlite3ExprFunction(pParse, Y, &X);
................................................................................
   944    945     */
   945    946     static void spanBinaryExpr(
   946    947       Parse *pParse,      /* The parsing context.  Errors accumulate here */
   947    948       int op,             /* The binary operation */
   948    949       ExprSpan *pLeft,    /* The left operand, and output */
   949    950       ExprSpan *pRight    /* The right operand */
   950    951     ){
   951         -    pLeft->pExpr = sqlite3PExpr(pParse, op, pLeft->pExpr, pRight->pExpr, 0);
          952  +    pLeft->pExpr = sqlite3PExpr(pParse, op, pLeft->pExpr, pRight->pExpr);
   952    953       pLeft->zEnd = pRight->zEnd;
   953    954     }
   954    955   
   955    956     /* If doNot is true, then add a TK_NOT Expr-node wrapper around the
   956    957     ** outside of *ppExpr.
   957    958     */
   958    959     static void exprNot(Parse *pParse, int doNot, ExprSpan *pSpan){
   959    960       if( doNot ){
   960         -      pSpan->pExpr = sqlite3PExpr(pParse, TK_NOT, pSpan->pExpr, 0, 0);
          961  +      pSpan->pExpr = sqlite3PExpr(pParse, TK_NOT, pSpan->pExpr, 0);
   961    962       }
   962    963     }
   963    964   }
   964    965   
   965    966   expr(A) ::= LP(L) nexprlist(X) COMMA expr(Y) RP(R). {
   966    967     ExprList *pList = sqlite3ExprListAppend(pParse, X, Y.pExpr);
   967         -  A.pExpr = sqlite3PExpr(pParse, TK_VECTOR, 0, 0, 0);
          968  +  A.pExpr = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
   968    969     if( A.pExpr ){
   969    970       A.pExpr->x.pList = pList;
   970    971       spanSet(&A, &L, &R);
   971    972     }else{
   972    973       sqlite3ExprListDelete(pParse->db, pList);
   973    974     }
   974    975   }
................................................................................
  1017   1018     */
  1018   1019     static void spanUnaryPostfix(
  1019   1020       Parse *pParse,         /* Parsing context to record errors */
  1020   1021       int op,                /* The operator */
  1021   1022       ExprSpan *pOperand,    /* The operand, and output */
  1022   1023       Token *pPostOp         /* The operand token for setting the span */
  1023   1024     ){
  1024         -    pOperand->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0, 0);
         1025  +    pOperand->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0);
  1025   1026       pOperand->zEnd = &pPostOp->z[pPostOp->n];
  1026   1027     }                           
  1027   1028   }
  1028   1029   
  1029   1030   expr(A) ::= expr(A) ISNULL|NOTNULL(E).   {spanUnaryPostfix(pParse,@E,&A,&E);}
  1030   1031   expr(A) ::= expr(A) NOT NULL(E). {spanUnaryPostfix(pParse,TK_NOTNULL,&A,&E);}
  1031   1032   
................................................................................
  1064   1065       ExprSpan *pOut,        /* Write the new expression node here */
  1065   1066       Parse *pParse,         /* Parsing context to record errors */
  1066   1067       int op,                /* The operator */
  1067   1068       ExprSpan *pOperand,    /* The operand */
  1068   1069       Token *pPreOp         /* The operand token for setting the span */
  1069   1070     ){
  1070   1071       pOut->zStart = pPreOp->z;
  1071         -    pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0, 0);
         1072  +    pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0);
  1072   1073       pOut->zEnd = pOperand->zEnd;
  1073   1074     }
  1074   1075   }
  1075   1076   
  1076   1077   
  1077   1078   
  1078   1079   expr(A) ::= NOT(B) expr(X).  
................................................................................
  1086   1087   
  1087   1088   %type between_op {int}
  1088   1089   between_op(A) ::= BETWEEN.     {A = 0;}
  1089   1090   between_op(A) ::= NOT BETWEEN. {A = 1;}
  1090   1091   expr(A) ::= expr(A) between_op(N) expr(X) AND expr(Y). [BETWEEN] {
  1091   1092     ExprList *pList = sqlite3ExprListAppend(pParse,0, X.pExpr);
  1092   1093     pList = sqlite3ExprListAppend(pParse,pList, Y.pExpr);
  1093         -  A.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, A.pExpr, 0, 0);
         1094  +  A.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, A.pExpr, 0);
  1094   1095     if( A.pExpr ){
  1095   1096       A.pExpr->x.pList = pList;
  1096   1097     }else{
  1097   1098       sqlite3ExprListDelete(pParse->db, pList);
  1098   1099     } 
  1099   1100     exprNot(pParse, N, &A);
  1100   1101     A.zEnd = Y.zEnd;
................................................................................
  1110   1111         **      expr1 IN ()
  1111   1112         **      expr1 NOT IN ()
  1112   1113         **
  1113   1114         ** simplify to constants 0 (false) and 1 (true), respectively,
  1114   1115         ** regardless of the value of expr1.
  1115   1116         */
  1116   1117         sqlite3ExprDelete(pParse->db, A.pExpr);
  1117         -      A.pExpr = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, &sqlite3IntTokens[N]);
         1118  +      A.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[N],1);
  1118   1119       }else if( Y->nExpr==1 ){
  1119   1120         /* Expressions of the form:
  1120   1121         **
  1121   1122         **      expr1 IN (?1)
  1122   1123         **      expr1 NOT IN (?2)
  1123   1124         **
  1124   1125         ** with exactly one value on the RHS can be simplified to something
................................................................................
  1137   1138         sqlite3ExprListDelete(pParse->db, Y);
  1138   1139         /* pRHS cannot be NULL because a malloc error would have been detected
  1139   1140         ** before now and control would have never reached this point */
  1140   1141         if( ALWAYS(pRHS) ){
  1141   1142           pRHS->flags &= ~EP_Collate;
  1142   1143           pRHS->flags |= EP_Generic;
  1143   1144         }
  1144         -      A.pExpr = sqlite3PExpr(pParse, N ? TK_NE : TK_EQ, A.pExpr, pRHS, 0);
         1145  +      A.pExpr = sqlite3PExpr(pParse, N ? TK_NE : TK_EQ, A.pExpr, pRHS);
  1145   1146       }else{
  1146         -      A.pExpr = sqlite3PExpr(pParse, TK_IN, A.pExpr, 0, 0);
         1147  +      A.pExpr = sqlite3PExpr(pParse, TK_IN, A.pExpr, 0);
  1147   1148         if( A.pExpr ){
  1148   1149           A.pExpr->x.pList = Y;
  1149   1150           sqlite3ExprSetHeightAndFlags(pParse, A.pExpr);
  1150   1151         }else{
  1151   1152           sqlite3ExprListDelete(pParse->db, Y);
  1152   1153         }
  1153   1154         exprNot(pParse, N, &A);
  1154   1155       }
  1155   1156       A.zEnd = &E.z[E.n];
  1156   1157     }
  1157   1158     expr(A) ::= LP(B) select(X) RP(E). {
  1158   1159       spanSet(&A,&B,&E); /*A-overwrites-B*/
  1159         -    A.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
         1160  +    A.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
  1160   1161       sqlite3PExprAddSelect(pParse, A.pExpr, X);
  1161   1162     }
  1162   1163     expr(A) ::= expr(A) in_op(N) LP select(Y) RP(E).  [IN] {
  1163         -    A.pExpr = sqlite3PExpr(pParse, TK_IN, A.pExpr, 0, 0);
         1164  +    A.pExpr = sqlite3PExpr(pParse, TK_IN, A.pExpr, 0);
  1164   1165       sqlite3PExprAddSelect(pParse, A.pExpr, Y);
  1165   1166       exprNot(pParse, N, &A);
  1166   1167       A.zEnd = &E.z[E.n];
  1167   1168     }
  1168   1169     expr(A) ::= expr(A) in_op(N) nm(Y) dbnm(Z) paren_exprlist(E). [IN] {
  1169   1170       SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&Y,&Z);
  1170   1171       Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
  1171   1172       if( E )  sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, E);
  1172         -    A.pExpr = sqlite3PExpr(pParse, TK_IN, A.pExpr, 0, 0);
         1173  +    A.pExpr = sqlite3PExpr(pParse, TK_IN, A.pExpr, 0);
  1173   1174       sqlite3PExprAddSelect(pParse, A.pExpr, pSelect);
  1174   1175       exprNot(pParse, N, &A);
  1175   1176       A.zEnd = Z.z ? &Z.z[Z.n] : &Y.z[Y.n];
  1176   1177     }
  1177   1178     expr(A) ::= EXISTS(B) LP select(Y) RP(E). {
  1178   1179       Expr *p;
  1179   1180       spanSet(&A,&B,&E); /*A-overwrites-B*/
  1180         -    p = A.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
         1181  +    p = A.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
  1181   1182       sqlite3PExprAddSelect(pParse, p, Y);
  1182   1183     }
  1183   1184   %endif SQLITE_OMIT_SUBQUERY
  1184   1185   
  1185   1186   /* CASE expressions */
  1186   1187   expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). {
  1187   1188     spanSet(&A,&C,&E);  /*A-overwrites-C*/
  1188         -  A.pExpr = sqlite3PExpr(pParse, TK_CASE, X, 0, 0);
         1189  +  A.pExpr = sqlite3PExpr(pParse, TK_CASE, X, 0);
  1189   1190     if( A.pExpr ){
  1190   1191       A.pExpr->x.pList = Z ? sqlite3ExprListAppend(pParse,Y,Z) : Y;
  1191   1192       sqlite3ExprSetHeightAndFlags(pParse, A.pExpr);
  1192   1193     }else{
  1193   1194       sqlite3ExprListDelete(pParse->db, Y);
  1194   1195       sqlite3ExprDelete(pParse->db, Z);
  1195   1196     }
................................................................................
  1441   1442   // SELECT
  1442   1443   trigger_cmd(A) ::= select(X).
  1443   1444      {A = sqlite3TriggerSelectStep(pParse->db, X); /*A-overwrites-X*/}
  1444   1445   
  1445   1446   // The special RAISE expression that may occur in trigger programs
  1446   1447   expr(A) ::= RAISE(X) LP IGNORE RP(Y).  {
  1447   1448     spanSet(&A,&X,&Y);  /*A-overwrites-X*/
  1448         -  A.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0); 
         1449  +  A.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0); 
  1449   1450     if( A.pExpr ){
  1450   1451       A.pExpr->affinity = OE_Ignore;
  1451   1452     }
  1452   1453   }
  1453   1454   expr(A) ::= RAISE(X) LP raisetype(T) COMMA nm(Z) RP(Y).  {
  1454   1455     spanSet(&A,&X,&Y);  /*A-overwrites-X*/
  1455         -  A.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &Z); 
         1456  +  A.pExpr = sqlite3ExprAlloc(pParse->db, TK_RAISE, &Z, 1); 
  1456   1457     if( A.pExpr ) {
  1457   1458       A.pExpr->affinity = (char)T;
  1458   1459     }
  1459   1460   }
  1460   1461   %endif  !SQLITE_OMIT_TRIGGER
  1461   1462   
  1462   1463   %type raisetype {int}

Changes to src/select.c.

   330    330     assert( pSrc->nSrc>iRight );
   331    331     assert( pSrc->a[iLeft].pTab );
   332    332     assert( pSrc->a[iRight].pTab );
   333    333   
   334    334     pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iColLeft);
   335    335     pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight);
   336    336   
   337         -  pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2, 0);
          337  +  pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2);
   338    338     if( pEq && isOuterJoin ){
   339    339       ExprSetProperty(pEq, EP_FromJoin);
   340    340       assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) );
   341    341       ExprSetVVAProperty(pEq, EP_NoReduce);
   342    342       pEq->iRightJoinTable = (i16)pE2->iTable;
   343    343     }
   344    344     *ppWhere = sqlite3ExprAnd(db, *ppWhere, pEq);
................................................................................
  4471   4471               }
  4472   4472               pRight = sqlite3Expr(db, TK_ID, zName);
  4473   4473               zColname = zName;
  4474   4474               zToFree = 0;
  4475   4475               if( longNames || pTabList->nSrc>1 ){
  4476   4476                 Expr *pLeft;
  4477   4477                 pLeft = sqlite3Expr(db, TK_ID, zTabName);
  4478         -              pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
         4478  +              pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
  4479   4479                 if( zSchemaName ){
  4480   4480                   pLeft = sqlite3Expr(db, TK_ID, zSchemaName);
  4481         -                pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pExpr, 0);
         4481  +                pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pExpr);
  4482   4482                 }
  4483   4483                 if( longNames ){
  4484   4484                   zColname = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
  4485   4485                   zToFree = zColname;
  4486   4486                 }
  4487   4487               }else{
  4488   4488                 pExpr = pRight;

Changes to src/sqliteInt.h.

  3548   3548   void sqlite3ClearTempRegCache(Parse*);
  3549   3549   #ifdef SQLITE_DEBUG
  3550   3550   int sqlite3NoTempsInRange(Parse*,int,int);
  3551   3551   #endif
  3552   3552   Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int);
  3553   3553   Expr *sqlite3Expr(sqlite3*,int,const char*);
  3554   3554   void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*);
  3555         -Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
         3555  +Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*);
  3556   3556   void sqlite3PExprAddSelect(Parse*, Expr*, Select*);
  3557   3557   Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
  3558   3558   Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
  3559   3559   void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32);
  3560   3560   void sqlite3ExprDelete(sqlite3*, Expr*);
  3561   3561   ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
  3562   3562   ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*);

Changes to src/wherecode.c.

  1171   1171             assert( pOp->opcode!=OP_Rowid || pOp->p2==iReg+j+2 );
  1172   1172             testcase( pOp->opcode==OP_Rowid );
  1173   1173             sqlite3VdbeAddOp3(v, pOp->opcode, pOp->p1, pOp->p2, pOp->p3);
  1174   1174           }
  1175   1175   
  1176   1176           /* Generate code that will continue to the next row if 
  1177   1177           ** the IN constraint is not satisfied */
  1178         -        pCompare = sqlite3PExpr(pParse, TK_EQ, 0, 0, 0);
         1178  +        pCompare = sqlite3PExpr(pParse, TK_EQ, 0, 0);
  1179   1179           assert( pCompare!=0 || db->mallocFailed );
  1180   1180           if( pCompare ){
  1181   1181             pCompare->pLeft = pTerm->pExpr->pLeft;
  1182   1182             pCompare->pRight = pRight = sqlite3Expr(db, TK_REGISTER, 0);
  1183   1183             if( pRight ){
  1184   1184               pRight->iTable = iReg+j+2;
  1185   1185               sqlite3ExprIfFalse(pParse, pCompare, pLevel->addrCont, 0);
................................................................................
  1770   1770           if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED))!=0 ) continue;
  1771   1771           if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
  1772   1772           testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
  1773   1773           pExpr = sqlite3ExprDup(db, pExpr, 0);
  1774   1774           pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr);
  1775   1775         }
  1776   1776         if( pAndExpr ){
  1777         -        pAndExpr = sqlite3PExpr(pParse, TK_AND|TKFLG_DONTFOLD, 0, pAndExpr, 0);
         1777  +        pAndExpr = sqlite3PExpr(pParse, TK_AND|TKFLG_DONTFOLD, 0, pAndExpr);
  1778   1778         }
  1779   1779       }
  1780   1780   
  1781   1781       /* Run a separate WHERE clause for each term of the OR clause.  After
  1782   1782       ** eliminating duplicates from other WHERE clauses, the action for each
  1783   1783       ** sub-WHERE clause is to to invoke the main loop body as a subroutine.
  1784   1784       */

Changes to src/whereexpr.c.

   730    730           assert( pOrTerm->u.leftColumn==iColumn );
   731    731           pDup = sqlite3ExprDup(db, pOrTerm->pExpr->pRight, 0);
   732    732           pList = sqlite3ExprListAppend(pWInfo->pParse, pList, pDup);
   733    733           pLeft = pOrTerm->pExpr->pLeft;
   734    734         }
   735    735         assert( pLeft!=0 );
   736    736         pDup = sqlite3ExprDup(db, pLeft, 0);
   737         -      pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0, 0);
          737  +      pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0);
   738    738         if( pNew ){
   739    739           int idxNew;
   740    740           transferJoinMarkings(pNew, pExpr);
   741    741           assert( !ExprHasProperty(pNew, EP_xIsSelect) );
   742    742           pNew->x.pList = pList;
   743    743           idxNew = whereClauseInsert(pWC, pNew, TERM_VIRTUAL|TERM_DYNAMIC);
   744    744           testcase( idxNew==0 );
................................................................................
  1028   1028       assert( pList!=0 );
  1029   1029       assert( pList->nExpr==2 );
  1030   1030       for(i=0; i<2; i++){
  1031   1031         Expr *pNewExpr;
  1032   1032         int idxNew;
  1033   1033         pNewExpr = sqlite3PExpr(pParse, ops[i], 
  1034   1034                                sqlite3ExprDup(db, pExpr->pLeft, 0),
  1035         -                             sqlite3ExprDup(db, pList->a[i].pExpr, 0), 0);
         1035  +                             sqlite3ExprDup(db, pList->a[i].pExpr, 0));
  1036   1036         transferJoinMarkings(pNewExpr, pExpr);
  1037   1037         idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
  1038   1038         testcase( idxNew==0 );
  1039   1039         exprAnalyze(pSrc, pWC, idxNew);
  1040   1040         pTerm = &pWC->a[idxTerm];
  1041   1041         markTermAsChild(pWC, idxNew, idxTerm);
  1042   1042       }
................................................................................
  1113   1113         }
  1114   1114         *pC = c + 1;
  1115   1115       }
  1116   1116       zCollSeqName = noCase ? "NOCASE" : "BINARY";
  1117   1117       pNewExpr1 = sqlite3ExprDup(db, pLeft, 0);
  1118   1118       pNewExpr1 = sqlite3PExpr(pParse, TK_GE,
  1119   1119              sqlite3ExprAddCollateString(pParse,pNewExpr1,zCollSeqName),
  1120         -           pStr1, 0);
         1120  +           pStr1);
  1121   1121       transferJoinMarkings(pNewExpr1, pExpr);
  1122   1122       idxNew1 = whereClauseInsert(pWC, pNewExpr1, wtFlags);
  1123   1123       testcase( idxNew1==0 );
  1124   1124       exprAnalyze(pSrc, pWC, idxNew1);
  1125   1125       pNewExpr2 = sqlite3ExprDup(db, pLeft, 0);
  1126   1126       pNewExpr2 = sqlite3PExpr(pParse, TK_LT,
  1127   1127              sqlite3ExprAddCollateString(pParse,pNewExpr2,zCollSeqName),
  1128         -           pStr2, 0);
         1128  +           pStr2);
  1129   1129       transferJoinMarkings(pNewExpr2, pExpr);
  1130   1130       idxNew2 = whereClauseInsert(pWC, pNewExpr2, wtFlags);
  1131   1131       testcase( idxNew2==0 );
  1132   1132       exprAnalyze(pSrc, pWC, idxNew2);
  1133   1133       pTerm = &pWC->a[idxTerm];
  1134   1134       if( isComplete ){
  1135   1135         markTermAsChild(pWC, idxNew1, idxTerm);
................................................................................
  1154   1154       pRight = pExpr->x.pList->a[0].pExpr;
  1155   1155       pLeft = pExpr->x.pList->a[1].pExpr;
  1156   1156       prereqExpr = sqlite3WhereExprUsage(pMaskSet, pRight);
  1157   1157       prereqColumn = sqlite3WhereExprUsage(pMaskSet, pLeft);
  1158   1158       if( (prereqExpr & prereqColumn)==0 ){
  1159   1159         Expr *pNewExpr;
  1160   1160         pNewExpr = sqlite3PExpr(pParse, TK_MATCH, 
  1161         -                              0, sqlite3ExprDup(db, pRight, 0), 0);
         1161  +                              0, sqlite3ExprDup(db, pRight, 0));
  1162   1162         idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
  1163   1163         testcase( idxNew==0 );
  1164   1164         pNewTerm = &pWC->a[idxNew];
  1165   1165         pNewTerm->prereqRight = prereqExpr;
  1166   1166         pNewTerm->leftCursor = pLeft->iTable;
  1167   1167         pNewTerm->u.leftColumn = pLeft->iColumn;
  1168   1168         pNewTerm->eOperator = WO_MATCH;
................................................................................
  1193   1193       assert( nLeft==sqlite3ExprVectorSize(pExpr->pRight) );
  1194   1194       for(i=0; i<nLeft; i++){
  1195   1195         int idxNew;
  1196   1196         Expr *pNew;
  1197   1197         Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i);
  1198   1198         Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i);
  1199   1199   
  1200         -      pNew = sqlite3PExpr(pParse, pExpr->op, pLeft, pRight, 0);
         1200  +      pNew = sqlite3PExpr(pParse, pExpr->op, pLeft, pRight);
  1201   1201         transferJoinMarkings(pNew, pExpr);
  1202   1202         idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC);
  1203   1203         exprAnalyze(pSrc, pWC, idxNew);
  1204   1204       }
  1205   1205       pTerm = &pWC->a[idxTerm];
  1206   1206       pTerm->wtFlags = TERM_CODED|TERM_VIRTUAL;  /* Disable the original */
  1207   1207       pTerm->eOperator = 0;
................................................................................
  1245   1245       Expr *pNewExpr;
  1246   1246       Expr *pLeft = pExpr->pLeft;
  1247   1247       int idxNew;
  1248   1248       WhereTerm *pNewTerm;
  1249   1249   
  1250   1250       pNewExpr = sqlite3PExpr(pParse, TK_GT,
  1251   1251                               sqlite3ExprDup(db, pLeft, 0),
  1252         -                            sqlite3ExprAlloc(db, TK_NULL, 0, 0), 0);
         1252  +                            sqlite3ExprAlloc(db, TK_NULL, 0, 0));
  1253   1253   
  1254   1254       idxNew = whereClauseInsert(pWC, pNewExpr,
  1255   1255                                 TERM_VIRTUAL|TERM_DYNAMIC|TERM_VNULL);
  1256   1256       if( idxNew ){
  1257   1257         pNewTerm = &pWC->a[idxNew];
  1258   1258         pNewTerm->prereqRight = 0;
  1259   1259         pNewTerm->leftCursor = pLeft->iTable;
................................................................................
  1431   1431       }
  1432   1432       pColRef = sqlite3ExprAlloc(pParse->db, TK_COLUMN, 0, 0);
  1433   1433       if( pColRef==0 ) return;
  1434   1434       pColRef->iTable = pItem->iCursor;
  1435   1435       pColRef->iColumn = k++;
  1436   1436       pColRef->pTab = pTab;
  1437   1437       pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef,
  1438         -                         sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0);
         1438  +                         sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0));
  1439   1439       whereClauseInsert(pWC, pTerm, TERM_DYNAMIC);
  1440   1440     }
  1441   1441   }