/ Check-in [53f5cfe1]
Login

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

Overview
Comment:Simplifications to the expression code generator. Remove about 80 lines of older and obsolete code.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 53f5cfe11516d0496c7760378b6305c3088d479f
User & Date: drh 2010-09-27 18:14:12
References
2011-10-25
20:36
Cherrypick changes [53f5cfe115] and [1f7ef0af8d] in order to fix an issue with DISTINCT check-in: 14bc58ca user: drh tags: branch-3.7.2
Context
2010-09-28
07:14
Merge fixes for ticket [b351d95f9cd5ef17e9d9dbae18f5ca8611190001] into the trunk. check-in: 1f7ef0af user: drh tags: trunk
2010-09-27
21:09
Add assert() statements that fail when a shallow copy is accessed after the original has been modified. These assert() statements should detect the kinds of subtle SCopy bugs such as caused the fault in ticket [b351d95f9cd5ef17e9d9dbae18f]. check-in: 8b8e1732 user: drh tags: bug-b351d95f9c
18:14
Simplifications to the expression code generator. Remove about 80 lines of older and obsolete code. check-in: 53f5cfe1 user: drh tags: trunk
2010-09-25
22:32
Enhance the ANALYZE command so that it gathers statistics in the sqlite_stat1 table even for tables that are empty or have no indices. check-in: a7645d29 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

  2230   2230       int r = p->iReg;
  2231   2231       if( r>=iFrom && r<=iTo ) return 1;    /*NO_TEST*/
  2232   2232     }
  2233   2233     return 0;
  2234   2234   }
  2235   2235   #endif /* SQLITE_DEBUG || SQLITE_COVERAGE_TEST */
  2236   2236   
  2237         -/*
  2238         -** If the last instruction coded is an ephemeral copy of any of
  2239         -** the registers in the nReg registers beginning with iReg, then
  2240         -** convert the last instruction from OP_SCopy to OP_Copy.
  2241         -*/
  2242         -void sqlite3ExprHardCopy(Parse *pParse, int iReg, int nReg){
  2243         -  VdbeOp *pOp;
  2244         -  Vdbe *v;
  2245         -
  2246         -  assert( pParse->db->mallocFailed==0 );
  2247         -  v = pParse->pVdbe;
  2248         -  assert( v!=0 );
  2249         -  pOp = sqlite3VdbeGetOp(v, -1);
  2250         -  assert( pOp!=0 );
  2251         -  if( pOp->opcode==OP_SCopy && pOp->p1>=iReg && pOp->p1<iReg+nReg ){
  2252         -    pOp->opcode = OP_Copy;
  2253         -  }
  2254         -}
  2255         -
  2256         -/*
  2257         -** Generate code to store the value of the iAlias-th alias in register
  2258         -** target.  The first time this is called, pExpr is evaluated to compute
  2259         -** the value of the alias.  The value is stored in an auxiliary register
  2260         -** and the number of that register is returned.  On subsequent calls,
  2261         -** the register number is returned without generating any code.
  2262         -**
  2263         -** Note that in order for this to work, code must be generated in the
  2264         -** same order that it is executed.
  2265         -**
  2266         -** Aliases are numbered starting with 1.  So iAlias is in the range
  2267         -** of 1 to pParse->nAlias inclusive.  
  2268         -**
  2269         -** pParse->aAlias[iAlias-1] records the register number where the value
  2270         -** of the iAlias-th alias is stored.  If zero, that means that the
  2271         -** alias has not yet been computed.
  2272         -*/
  2273         -static int codeAlias(Parse *pParse, int iAlias, Expr *pExpr, int target){
  2274         -#if 0
  2275         -  sqlite3 *db = pParse->db;
  2276         -  int iReg;
  2277         -  if( pParse->nAliasAlloc<pParse->nAlias ){
  2278         -    pParse->aAlias = sqlite3DbReallocOrFree(db, pParse->aAlias,
  2279         -                                 sizeof(pParse->aAlias[0])*pParse->nAlias );
  2280         -    testcase( db->mallocFailed && pParse->nAliasAlloc>0 );
  2281         -    if( db->mallocFailed ) return 0;
  2282         -    memset(&pParse->aAlias[pParse->nAliasAlloc], 0,
  2283         -           (pParse->nAlias-pParse->nAliasAlloc)*sizeof(pParse->aAlias[0]));
  2284         -    pParse->nAliasAlloc = pParse->nAlias;
  2285         -  }
  2286         -  assert( iAlias>0 && iAlias<=pParse->nAlias );
  2287         -  iReg = pParse->aAlias[iAlias-1];
  2288         -  if( iReg==0 ){
  2289         -    if( pParse->iCacheLevel>0 ){
  2290         -      iReg = sqlite3ExprCodeTarget(pParse, pExpr, target);
  2291         -    }else{
  2292         -      iReg = ++pParse->nMem;
  2293         -      sqlite3ExprCode(pParse, pExpr, iReg);
  2294         -      pParse->aAlias[iAlias-1] = iReg;
  2295         -    }
  2296         -  }
  2297         -  return iReg;
  2298         -#else
  2299         -  UNUSED_PARAMETER(iAlias);
  2300         -  return sqlite3ExprCodeTarget(pParse, pExpr, target);
  2301         -#endif
  2302         -}
  2303         -
  2304   2237   /*
  2305   2238   ** Generate code into the current Vdbe to evaluate the given
  2306   2239   ** expression.  Attempt to store the results in register "target".
  2307   2240   ** Return the register where results are stored.
  2308   2241   **
  2309   2242   ** With this routine, there is no guarantee that results will
  2310   2243   ** be stored in target.  The result might be stored in some other
................................................................................
  2405   2338         break;
  2406   2339       }
  2407   2340       case TK_REGISTER: {
  2408   2341         inReg = pExpr->iTable;
  2409   2342         break;
  2410   2343       }
  2411   2344       case TK_AS: {
  2412         -      inReg = codeAlias(pParse, pExpr->iTable, pExpr->pLeft, target);
         2345  +      inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
  2413   2346         break;
  2414   2347       }
  2415   2348   #ifndef SQLITE_OMIT_CAST
  2416   2349       case TK_CAST: {
  2417   2350         /* Expressions of the form:   CAST(pLeft AS token) */
  2418   2351         int aff, to_op;
  2419   2352         inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
................................................................................
  3108   3041   ){
  3109   3042     struct ExprList_item *pItem;
  3110   3043     int i, n;
  3111   3044     assert( pList!=0 );
  3112   3045     assert( target>0 );
  3113   3046     n = pList->nExpr;
  3114   3047     for(pItem=pList->a, i=0; i<n; i++, pItem++){
  3115         -    if( pItem->iAlias ){
  3116         -      int iReg = codeAlias(pParse, pItem->iAlias, pItem->pExpr, target+i);
  3117         -      Vdbe *v = sqlite3GetVdbe(pParse);
  3118         -      if( iReg!=target+i ){
  3119         -        sqlite3VdbeAddOp2(v, OP_SCopy, iReg, target+i);
  3120         -      }
  3121         -    }else{
  3122         -      sqlite3ExprCode(pParse, pItem->pExpr, target+i);
  3123         -    }
  3124         -    if( doHardCopy && !pParse->db->mallocFailed ){
  3125         -      sqlite3ExprHardCopy(pParse, target, n);
         3048  +    Expr *pExpr = pItem->pExpr;
         3049  +    int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
         3050  +    assert( pParse->pVdbe || pParse->db->mallocFailed );
         3051  +    if( inReg!=target+i && pParse->pVdbe ){
         3052  +      sqlite3VdbeAddOp2(pParse->pVdbe, doHardCopy ? OP_Copy : OP_SCopy,
         3053  +                        inReg, target+i);
  3126   3054       }
  3127   3055     }
  3128   3056     return n;
  3129   3057   }
  3130   3058   
  3131   3059   /*
  3132   3060   ** Generate code for a BETWEEN operator.

Changes to src/sqliteInt.h.

  2698   2698   void sqlite3ExprCodeCopy(Parse*, int, int, int);
  2699   2699   void sqlite3ExprCacheStore(Parse*, int, int, int);
  2700   2700   void sqlite3ExprCachePush(Parse*);
  2701   2701   void sqlite3ExprCachePop(Parse*, int);
  2702   2702   void sqlite3ExprCacheRemove(Parse*, int, int);
  2703   2703   void sqlite3ExprCacheClear(Parse*);
  2704   2704   void sqlite3ExprCacheAffinityChange(Parse*, int, int);
  2705         -void sqlite3ExprHardCopy(Parse*,int,int);
  2706   2705   int sqlite3ExprCode(Parse*, Expr*, int);
  2707   2706   int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
  2708   2707   int sqlite3ExprCodeTarget(Parse*, Expr*, int);
  2709   2708   int sqlite3ExprCodeAndCache(Parse*, Expr*, int);
  2710   2709   void sqlite3ExprCodeConstants(Parse*, Expr*);
  2711   2710   int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int);
  2712   2711   void sqlite3ExprIfTrue(Parse*, Expr*, int, int);