/ Check-in [684ef458]
Login

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

Overview
Comment:When doing the sqlite3BtreeInsert() overwrite optimization, make sure the memcpy() does not extend off the end of the page.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:684ef4582ed19b2af22dda6fc085c70464f92f1b
User & Date: drh 2016-12-09 19:42:18
Context
2016-12-10
04:06
Avoid signed integer overflow when dealing with a LIMIT and OFFSET whose sum exceeds the maximum integer value. check-in: c9bdf7ad user: drh tags: trunk
00:14
In balance_nonroot, try to combine dropCell/insertCell combinations for the dividers into a cell overwrites. This results in a very small (0.05%) performance gain which is probably not worth the added complexity. Closed-Leaf check-in: 478627c9 user: drh tags: failed-dropCell-opt
2016-12-09
19:42
When doing the sqlite3BtreeInsert() overwrite optimization, make sure the memcpy() does not extend off the end of the page. check-in: 684ef458 user: drh tags: trunk
18:09
Additional comments and an assert on the sqlite3BtreeInsert() overwrite optimization. check-in: c1f0ae9d user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/btree.c.

8064
8065
8066
8067
8068
8069
8070

8071
8072
8073
8074
8075
8076
8077
    if( info.nSize==szNew && info.nLocal==info.nPayload ){
      /* Overwrite the old cell with the new if they are the same size.
      ** We could also try to do this if the old cell is smaller, then add
      ** the leftover space to the free list.  But experiments show that
      ** doing that is no faster then skipping this optimization and just
      ** calling dropCell() and insertCell(). */
      assert( rc==SQLITE_OK ); /* clearCell never fails when nLocal==nPayload */

      memcpy(oldCell, newCell, szNew);
      return SQLITE_OK;
    }
    dropCell(pPage, idx, info.nSize, &rc);
    if( rc ) goto end_insert;
  }else if( loc<0 && pPage->nCell>0 ){
    assert( pPage->leaf );







>







8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
    if( info.nSize==szNew && info.nLocal==info.nPayload ){
      /* Overwrite the old cell with the new if they are the same size.
      ** We could also try to do this if the old cell is smaller, then add
      ** the leftover space to the free list.  But experiments show that
      ** doing that is no faster then skipping this optimization and just
      ** calling dropCell() and insertCell(). */
      assert( rc==SQLITE_OK ); /* clearCell never fails when nLocal==nPayload */
      if( oldCell+szNew > pPage->aDataEnd ) return SQLITE_CORRUPT_BKPT;
      memcpy(oldCell, newCell, szNew);
      return SQLITE_OK;
    }
    dropCell(pPage, idx, info.nSize, &rc);
    if( rc ) goto end_insert;
  }else if( loc<0 && pPage->nCell>0 ){
    assert( pPage->leaf );