/ Check-in [6199760d]
Login

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

Overview
Comment:Remove a local variable from the OP_Column implementation, resulting in a modest size reduction and a performance increase.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6199760d1340858d97c845177986b783da915d9e
User & Date: drh 2014-09-19 16:56:45
Context
2014-09-19
19:00
Make the "nolock" VFS on unix a version-3 VFS so that the sorter can use memory-mapped I/O. check-in: 3db78d61 user: drh tags: trunk
16:56
Remove a local variable from the OP_Column implementation, resulting in a modest size reduction and a performance increase. check-in: 6199760d user: drh tags: trunk
16:13
Small size reduction and performance increase for releaseMemArray(). check-in: 24cd32d6 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

  2253   2253   ** skipped for length() and all content loading can be skipped for typeof().
  2254   2254   */
  2255   2255   case OP_Column: {
  2256   2256     i64 payloadSize64; /* Number of bytes in the record */
  2257   2257     int p2;            /* column number to retrieve */
  2258   2258     VdbeCursor *pC;    /* The VDBE cursor */
  2259   2259     BtCursor *pCrsr;   /* The BTree cursor */
  2260         -  u32 *aType;        /* aType[i] holds the numeric type of the i-th column */
  2261   2260     u32 *aOffset;      /* aOffset[i] is offset to start of data for i-th column */
  2262   2261     int len;           /* The length of the serialized data for the column */
  2263   2262     int i;             /* Loop counter */
  2264   2263     Mem *pDest;        /* Where to write the extracted value */
  2265   2264     Mem sMem;          /* For storing the record being decoded */
  2266   2265     const u8 *zData;   /* Part of the record being decoded */
  2267   2266     const u8 *zHdr;    /* Next unparsed byte of the header */
  2268   2267     const u8 *zEndHdr; /* Pointer to first byte after the header */
  2269   2268     u32 offset;        /* Offset into the data */
  2270   2269     u32 szField;       /* Number of bytes in the content of a field */
  2271   2270     u32 avail;         /* Number of bytes of available data */
  2272   2271     u32 t;             /* A type code from the record header */
         2272  +  u16 fx;            /* pDest->flags value */
  2273   2273     Mem *pReg;         /* PseudoTable input register */
  2274   2274   
  2275   2275     p2 = pOp->p2;
  2276   2276     assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
  2277   2277     pDest = &aMem[pOp->p3];
  2278   2278     memAboutToChange(p, pDest);
  2279   2279     assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  2280   2280     pC = p->apCsr[pOp->p1];
  2281   2281     assert( pC!=0 );
  2282   2282     assert( p2<pC->nField );
  2283         -  aType = pC->aType;
  2284         -  aOffset = aType + pC->nField;
         2283  +  aOffset = pC->aType + pC->nField;
  2285   2284   #ifndef SQLITE_OMIT_VIRTUALTABLE
  2286   2285     assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
  2287   2286   #endif
  2288   2287     pCrsr = pC->pCursor;
  2289   2288     assert( pCrsr!=0 || pC->pseudoTableReg>0 ); /* pCrsr NULL on PseudoTables */
  2290   2289     assert( pCrsr!=0 || pC->nullRow );          /* pC->nullRow on PseudoTables */
  2291   2290   
................................................................................
  2358   2357       if( offset > 98307 || offset > pC->payloadSize ){
  2359   2358         rc = SQLITE_CORRUPT_BKPT;
  2360   2359         goto op_column_error;
  2361   2360       }
  2362   2361     }
  2363   2362   
  2364   2363     /* Make sure at least the first p2+1 entries of the header have been
  2365         -  ** parsed and valid information is in aOffset[] and aType[].
         2364  +  ** parsed and valid information is in aOffset[] and pC->aType[].
  2366   2365     */
  2367   2366     if( pC->nHdrParsed<=p2 ){
  2368   2367       /* If there is more header available for parsing in the record, try
  2369   2368       ** to extract additional fields up through the p2+1-th field 
  2370   2369       */
  2371   2370       if( pC->iHdrOffset<aOffset[0] ){
  2372   2371         /* Make sure zData points to enough of the record to cover the header. */
................................................................................
  2378   2377             goto op_column_error;
  2379   2378           }
  2380   2379           zData = (u8*)sMem.z;
  2381   2380         }else{
  2382   2381           zData = pC->aRow;
  2383   2382         }
  2384   2383     
  2385         -      /* Fill in aType[i] and aOffset[i] values through the p2-th field. */
         2384  +      /* Fill in pC->aType[i] and aOffset[i] values through the p2-th field. */
  2386   2385         i = pC->nHdrParsed;
  2387   2386         offset = aOffset[i];
  2388   2387         zHdr = zData + pC->iHdrOffset;
  2389   2388         zEndHdr = zData + aOffset[0];
  2390   2389         assert( i<=p2 && zHdr<zEndHdr );
  2391   2390         do{
  2392   2391           if( zHdr[0]<0x80 ){
  2393   2392             t = zHdr[0];
  2394   2393             zHdr++;
  2395   2394           }else{
  2396   2395             zHdr += sqlite3GetVarint32(zHdr, &t);
  2397   2396           }
  2398         -        aType[i] = t;
         2397  +        pC->aType[i] = t;
  2399   2398           szField = sqlite3VdbeSerialTypeLen(t);
  2400   2399           offset += szField;
  2401   2400           if( offset<szField ){  /* True if offset overflows */
  2402   2401             zHdr = &zEndHdr[1];  /* Forces SQLITE_CORRUPT return below */
  2403   2402             break;
  2404   2403           }
  2405   2404           i++;
................................................................................
  2438   2437           MemSetTypeFlag(pDest, MEM_Null);
  2439   2438         }
  2440   2439         goto op_column_out;
  2441   2440       }
  2442   2441     }
  2443   2442   
  2444   2443     /* Extract the content for the p2+1-th column.  Control can only
  2445         -  ** reach this point if aOffset[p2], aOffset[p2+1], and aType[p2] are
         2444  +  ** reach this point if aOffset[p2], aOffset[p2+1], and pC->aType[p2] are
  2446   2445     ** all valid.
  2447   2446     */
  2448   2447     assert( p2<pC->nHdrParsed );
  2449   2448     assert( rc==SQLITE_OK );
  2450   2449     assert( sqlite3VdbeCheckMemInvariants(pDest) );
  2451   2450     if( VdbeMemDynamic(pDest) ) sqlite3VdbeMemSetNull(pDest);
         2451  +  t = pC->aType[p2];
  2452   2452     if( pC->szRow>=aOffset[p2+1] ){
  2453   2453       /* This is the common case where the desired content fits on the original
  2454   2454       ** page - where the content is not on an overflow page */
  2455         -    sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], aType[p2], pDest);
         2455  +    sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], t, pDest);
  2456   2456     }else{
  2457   2457       /* This branch happens only when content is on overflow pages */
  2458         -    t = aType[p2];
  2459   2458       if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
  2460   2459             && ((t>=12 && (t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0))
  2461   2460        || (len = sqlite3VdbeSerialTypeLen(t))==0
  2462   2461       ){
  2463   2462         /* Content is irrelevant for
  2464   2463         **    1. the typeof() function,
  2465   2464         **    2. the length(X) function if X is a blob, and
................................................................................
  2483   2482   
  2484   2483   op_column_out:
  2485   2484     /* If the column value is an ephemeral string, go ahead and persist
  2486   2485     ** that string in case the cursor moves before the column value is
  2487   2486     ** used.  The following code does the equivalent of Deephemeralize()
  2488   2487     ** but does it faster. */
  2489   2488     if( (pDest->flags & MEM_Ephem)!=0 && pDest->z ){
  2490         -    u16 f = pDest->flags & (MEM_Str|MEM_Blob);
  2491         -    assert( f!=0 );
         2489  +    fx = pDest->flags & (MEM_Str|MEM_Blob);
         2490  +    assert( fx!=0 );
  2492   2491       zData = (const u8*)pDest->z;
  2493   2492       len = pDest->n;
  2494   2493       if( sqlite3VdbeMemClearAndResize(pDest, len+2) ) goto no_mem;
  2495   2494       memcpy(pDest->z, zData, len);
  2496   2495       pDest->z[len] = 0;
  2497   2496       pDest->z[len+1] = 0;
  2498         -    pDest->flags = f|MEM_Term;
         2497  +    pDest->flags = fx|MEM_Term;
  2499   2498     }
  2500   2499   op_column_error:
  2501   2500     UPDATE_MAX_BLOBSIZE(pDest);
  2502   2501     REGISTER_TRACE(pOp->p3, pDest);
  2503   2502     break;
  2504   2503   }
  2505   2504