/ Check-in [8125b74c]
Login

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

Overview
Comment:OP_Column optimization: Do not check for an oversize row header unless the row header size is larger than the content available on the local page.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:8125b74cb46c372b9a319f6270f1c396767accd7
User & Date: drh 2015-10-16 12:53:47
Context
2015-10-16
13:50
Simplify the OP_Column logic slightly. One very small performance improvement added. check-in: 0114b45d user: drh tags: trunk
12:53
OP_Column optimization: Do not check for an oversize row header unless the row header size is larger than the content available on the local page. check-in: 8125b74c user: drh tags: trunk
12:39
Improved header comment on the tool/vdbe_profile.tcl script. No changes to code. check-in: b17ad8fc user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

  2436   2436         }
  2437   2437       }
  2438   2438       pC->cacheStatus = p->cacheCtr;
  2439   2439       pC->iHdrOffset = getVarint32(pC->aRow, offset);
  2440   2440       pC->nHdrParsed = 0;
  2441   2441       aOffset[0] = offset;
  2442   2442   
  2443         -    /* Make sure a corrupt database has not given us an oversize header.
  2444         -    ** Do this now to avoid an oversize memory allocation.
  2445         -    **
  2446         -    ** Type entries can be between 1 and 5 bytes each.  But 4 and 5 byte
  2447         -    ** types use so much data space that there can only be 4096 and 32 of
  2448         -    ** them, respectively.  So the maximum header length results from a
  2449         -    ** 3-byte type for each of the maximum of 32768 columns plus three
  2450         -    ** extra bytes for the header length itself.  32768*3 + 3 = 98307.
  2451         -    */
  2452         -    if( offset > 98307 || offset > pC->payloadSize ){
  2453         -      rc = SQLITE_CORRUPT_BKPT;
  2454         -      goto op_column_error;
  2455         -    }
  2456   2443   
  2457   2444       if( avail<offset ){
  2458   2445         /* pC->aRow does not have to hold the entire row, but it does at least
  2459   2446         ** need to cover the header of the record.  If pC->aRow does not contain
  2460   2447         ** the complete header, then set it to zero, forcing the header to be
  2461   2448         ** dynamically allocated. */
  2462   2449         pC->aRow = 0;
  2463   2450         pC->szRow = 0;
         2451  +
         2452  +      /* Make sure a corrupt database has not given us an oversize header.
         2453  +      ** Do this now to avoid an oversize memory allocation.
         2454  +      **
         2455  +      ** Type entries can be between 1 and 5 bytes each.  But 4 and 5 byte
         2456  +      ** types use so much data space that there can only be 4096 and 32 of
         2457  +      ** them, respectively.  So the maximum header length results from a
         2458  +      ** 3-byte type for each of the maximum of 32768 columns plus three
         2459  +      ** extra bytes for the header length itself.  32768*3 + 3 = 98307.
         2460  +      */
         2461  +      if( offset > 98307 || offset > pC->payloadSize ){
         2462  +        rc = SQLITE_CORRUPT_BKPT;
         2463  +        goto op_column_error;
         2464  +      }
  2464   2465       }
  2465   2466   
  2466   2467       /* The following goto is an optimization.  It can be omitted and
  2467   2468       ** everything will still work.  But OP_Column is measurably faster
  2468   2469       ** by skipping the subsequent conditional, which is always true.
  2469   2470       */
  2470   2471       assert( pC->nHdrParsed<=p2 );         /* Conditional skipped */