SQLite4
Check-in [0d9860b35b]
Not logged in

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

Overview
Comment:Fix a problem with BT_SEEK_GE on the merge-tree when it contains partially merged deletes.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0d9860b35b652ef8ba5f2b6da6fe86dbb075e6eb
User & Date: dan 2014-01-21 20:40:10
Context
2014-01-23
18:00
Fix another bug in level merging. check-in: 24aea74e9f user: dan tags: trunk
2014-01-21
20:40
Fix a problem with BT_SEEK_GE on the merge-tree when it contains partially merged deletes. check-in: 0d9860b35b user: dan tags: trunk
18:59
Fix a problem preventing the database header from being written correctly. check-in: 7abccde8a3 user: dan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/bt_main.c.

1811
1812
1813
1814
1815
1816
1817
1818

1819

1820
1821
1822
1823
1824
1825












1826
1827
1828
1829
1830
1831
1832
1833
....
1900
1901
1902
1903
1904
1905
1906

1907









1908
1909
1910
1911
1912
1913
1914
....
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
....
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067

        if( rc==SQLITE4_NOTFOUND ){
          /* No keys to visit in this level */
          assert( pSub->mcsr.nPg==0 );
          assert( pSub->csr.nPg==0 );
          rc = SQLITE4_OK;
        }else if( rc==SQLITE4_OK || rc==SQLITE4_INEXACT ){
          const void *pV;

          int nV;

          u32 iRoot;
          sqlite4BtCsrData(&pM->base, 0, 4, &pV, &nV);
          iRoot = sqlite4BtGetU32((const u8*)pV);
          btCsrReset(&pSub->csr, 1);
          btCsrSetup(db, iRoot, &pSub->csr);













          rc = btCsrSeek(&pSub->csr, 0, pK, nK, eSeek, BT_CSRSEEK_SEEK);
          if( rc==SQLITE4_NOTFOUND ){
            if( eSeek==BT_SEEK_LE ){
              rc = fiSubCsrStep(pCsr, pSub, 0);
            }else{
              btCsrReset(pM, 0);
            }
          }else{
................................................................................
      const void *pV;
      int nV;
      int iRoot;
      btCsrData(&pSub->mcsr, 0, 4, &pV, &nV);
      iRoot = sqlite4BtGetU32((const u8*)pV);
      btCsrReset(&pSub->csr, 1);
      btCsrSetup(db, iRoot, &pSub->csr);

      rc = btCsrEnd(&pSub->csr, bLast);









    }else if( rc==SQLITE4_NOTFOUND ){
      btCsrReset(&pSub->mcsr, 0);
      rc = SQLITE4_OK;
    }
  }
  fiLevelIterCleanup(&iter);

................................................................................

  /* Save the value of the fast-insert flag. It will be restored before
  ** this function returns. Leaving it set here interferes with page 
  ** allocation if the meta-tree needs to be extended.  */
  const int bFastInsertOp = db->bFastInsertOp;
  db->bFastInsertOp = 0;
  
#if 1
  static int nCall = 0; nCall++;
  fprintf(stderr, "BEFORE %d\n", nCall);
  btPrintMetaTree(db->pPager, 1, pHdr);
#endif
  assert_summary_ok(db, SQLITE4_OK);

  memset(&csr, 0, sizeof(csr));
................................................................................
    }
  }

  btCsrReset(&csr, 1);
  btCsrReset(&mcsr, 1);
  sqlite4_buffer_clear(&buf);

#if 1
  if( rc==SQLITE4_OK ){
    btPrintMetaTree(db->pPager, 1, pHdr);
  }
#endif
  assert_summary_ok(db, SQLITE4_OK);
  db->bFastInsertOp = bFastInsertOp;
  return rc;







|
>
|
>






>
>
>
>
>
>
>
>
>
>
>
>
|







 







>
|
>
>
>
>
>
>
>
>
>







 







|







 







|







1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
....
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
....
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
....
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091

        if( rc==SQLITE4_NOTFOUND ){
          /* No keys to visit in this level */
          assert( pSub->mcsr.nPg==0 );
          assert( pSub->csr.nPg==0 );
          rc = SQLITE4_OK;
        }else if( rc==SQLITE4_OK || rc==SQLITE4_INEXACT ){
          const void *pV; int nV;
          const void *pSeek = pK; 
          int nSeek = nK;

          u32 iRoot;
          sqlite4BtCsrData(&pM->base, 0, 4, &pV, &nV);
          iRoot = sqlite4BtGetU32((const u8*)pV);
          btCsrReset(&pSub->csr, 1);
          btCsrSetup(db, iRoot, &pSub->csr);

          if( eSeek==BT_SEEK_GE ){
            const void *pMin; int nMin;
            rc = btCsrKey(pM, &pMin, &nMin);
            if( rc!=SQLITE4_OK ) break;
            nMin -= 8;
            pMin = (const void*)((const u8*)pMin + 8);
            if( btKeyCompare(pSeek, nSeek, pMin, nMin)<0 ){
              pSeek = pMin;
              nSeek = nMin;
            }
          }

          rc = btCsrSeek(&pSub->csr, 0, pSeek, nSeek, eSeek, BT_CSRSEEK_SEEK);
          if( rc==SQLITE4_NOTFOUND ){
            if( eSeek==BT_SEEK_LE ){
              rc = fiSubCsrStep(pCsr, pSub, 0);
            }else{
              btCsrReset(pM, 0);
            }
          }else{
................................................................................
      const void *pV;
      int nV;
      int iRoot;
      btCsrData(&pSub->mcsr, 0, 4, &pV, &nV);
      iRoot = sqlite4BtGetU32((const u8*)pV);
      btCsrReset(&pSub->csr, 1);
      btCsrSetup(db, iRoot, &pSub->csr);
      if( bLast ){
        rc = btCsrEnd(&pSub->csr, 1);
      }else{
        const void *pK; int nK;
        rc = btCsrKey(&pSub->mcsr, &pK, &nK);
        if( rc==SQLITE4_OK ){
          rc = btCsrSeek(&pSub->csr, 0, ((u8*)pK)+8, nK-8, BT_SEEK_GE, 0);
          if( rc==SQLITE4_INEXACT ) rc = SQLITE4_OK;
          if( rc==SQLITE4_NOTFOUND ) rc = btErrorBkpt(SQLITE4_CORRUPT);
        }
      }
    }else if( rc==SQLITE4_NOTFOUND ){
      btCsrReset(&pSub->mcsr, 0);
      rc = SQLITE4_OK;
    }
  }
  fiLevelIterCleanup(&iter);

................................................................................

  /* Save the value of the fast-insert flag. It will be restored before
  ** this function returns. Leaving it set here interferes with page 
  ** allocation if the meta-tree needs to be extended.  */
  const int bFastInsertOp = db->bFastInsertOp;
  db->bFastInsertOp = 0;
  
#if 0
  static int nCall = 0; nCall++;
  fprintf(stderr, "BEFORE %d\n", nCall);
  btPrintMetaTree(db->pPager, 1, pHdr);
#endif
  assert_summary_ok(db, SQLITE4_OK);

  memset(&csr, 0, sizeof(csr));
................................................................................
    }
  }

  btCsrReset(&csr, 1);
  btCsrReset(&mcsr, 1);
  sqlite4_buffer_clear(&buf);

#if 0
  if( rc==SQLITE4_OK ){
    btPrintMetaTree(db->pPager, 1, pHdr);
  }
#endif
  assert_summary_ok(db, SQLITE4_OK);
  db->bFastInsertOp = bFastInsertOp;
  return rc;