]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Make the root page of an ephemeral index be page 1 instead of page 2.
authordrh <drh@noemail.net>
Wed, 5 Feb 2014 17:08:07 +0000 (17:08 +0000)
committerdrh <drh@noemail.net>
Wed, 5 Feb 2014 17:08:07 +0000 (17:08 +0000)
FossilOrigin-Name: a332908b70afa4e77e60b30a3b96d8a8504363a2

manifest
manifest.uuid
src/btree.c
src/btree.h
src/vdbe.c

index da13307c6cf74caf3fec90846cb8d3bc0a8d7367..b266fad71944531dfb5a900a4cad9e9407794824 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C In\sthe\sWin32\sVFS,\sthe\swinSysInfo\svariable\sshould\sbe\sstatic.
-D 2014-02-05T11:05:47.687
+C Make\sthe\sroot\spage\sof\san\sephemeral\sindex\sbe\spage\s1\sinstead\sof\spage\s2.
+D 2014-02-05T17:08:07.143
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -166,8 +166,8 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
 F src/backup.c a729e63cf5cd1829507cb7b8e89f99b95141bb53
 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb
 F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7
-F src/btree.c 7b2c3cd16deedff7f4904f2e871e7b77328b9872
-F src/btree.h a61ddebc78c66795a2b93181321a116746302cc9
+F src/btree.c ae408b77caf025df8c1baab52aad8a5a393bed35
+F src/btree.h f1c65e0511d7a228fd1a7c7463ef842525364348
 F src/btreeInt.h f038e818bfadf75afbd09819ed93c26a333d39e0
 F src/build.c 7e6c275ab1731510d6f793d0f88373ab3e858e69
 F src/callback.c 174e3c8656bc29f91d710ab61550d16eea34be98
@@ -280,7 +280,7 @@ F src/update.c a7df6fffce6bfedc578fda6136dd33e34a63f8ee
 F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269
 F src/util.c 15ac2627f548f5481d0d7e6c4eb67be673027695
 F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179
-F src/vdbe.c e703913e9a3b56d7824f3eb8b76d99f496ff6dc1
+F src/vdbe.c 361f6e555755cdde80ee64afc2e03ae992118b62
 F src/vdbe.h e6c4c610fcabad4fa80ebb1efc6822a9367e2b26
 F src/vdbeInt.h 42db251e9f863401ff847b90d5fe1614c89a6a56
 F src/vdbeapi.c ce4e68ea4842cc6081046f533d088dcf01d247ad
@@ -1152,7 +1152,7 @@ F tool/vdbe-compress.tcl 0cf56e9263a152b84da86e75a5c0cdcdb7a47891
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
-P f2504089df0bf4011864e67825b37f6aa3d03458
-R f919fd88b0fe2a17b41d9c03ff44720f
-U mistachkin
-Z fecb65c3944a970d4d7662e030506246
+P 4a4dd371a72b7d475185923bebb4cd9bd83e1bd9
+R bf307b76d3eec71eba23d35d1544e183
+U drh
+Z c36144694714d745eac22adf0a8b4378
index e178daa36c35519dafa725d0104fae7351bebc3c..e9b702e1094022fb022538fb161634233044e8ca 100644 (file)
@@ -1 +1 @@
-4a4dd371a72b7d475185923bebb4cd9bd83e1bd9
\ No newline at end of file
+a332908b70afa4e77e60b30a3b96d8a8504363a2
\ No newline at end of file
index cf135b1e14726d72685fcd74306284912073f86b..acbf364389a8eeeec62286713f1bcb7eaa6a3368 100644 (file)
@@ -1527,7 +1527,7 @@ static int btreeInitPage(MemPage *pPage){
 ** Set up a raw page so that it looks like a database page holding
 ** no entries.
 */
-static void zeroPage(MemPage *pPage, int flags){
+static void zeroPage(MemPage *pPage, u8 flags){
   unsigned char *data = pPage->aData;
   BtShared *pBt = pPage->pBt;
   u8 hdr = pPage->hdrOffset;
@@ -2585,6 +2585,7 @@ static int newDatabase(BtShared *pBt){
   MemPage *pP1;
   unsigned char *data;
   int rc;
+  u8 flags;
 
   assert( sqlite3_mutex_held(pBt->mutex) );
   if( pBt->nPage>0 ){
@@ -2607,7 +2608,9 @@ static int newDatabase(BtShared *pBt){
   data[22] = 32;
   data[23] = 32;
   memset(&data[24], 0, 100-24);
-  zeroPage(pP1, PTF_INTKEY|PTF_LEAF|PTF_LEAFDATA );
+  flags = (pBt->openFlags&BTREE_SINGLE_INDEX) ? PTF_ZERODATA|PTF_LEAF
+                                              : PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF;
+  zeroPage(pP1, flags);
   pBt->btsFlags |= BTS_PAGESIZE_FIXED;
 #ifndef SQLITE_OMIT_AUTOVACUUM
   assert( pBt->autoVacuum==1 || pBt->autoVacuum==0 );
@@ -6109,7 +6112,7 @@ static int balance_nonroot(
   u16 leafCorrection;          /* 4 if pPage is a leaf.  0 if not */
   int leafData;                /* True if pPage is a leaf of a LEAFDATA tree */
   int usableSpace;             /* Bytes in pPage beyond the header */
-  int pageFlags;               /* Value of pPage->aData[0] */
+  u8 pageFlags;                /* Value of pPage->aData[0] */
   int subtotal;                /* Subtotal of bytes in cells on one page */
   int iSpace1 = 0;             /* First unused byte of aSpace1[] */
   int iOvflSpace = 0;          /* First unused byte of aOvflSpace[] */
@@ -7210,7 +7213,7 @@ static int btreeCreateTable(Btree *p, int *piTable, int createTabFlags){
   MemPage *pRoot;
   Pgno pgnoRoot;
   int rc;
-  int ptfFlags;          /* Page-type flage for the root page of new table */
+  u8 ptfFlags;          /* Page-type flage for the root page of new table */
 
   assert( sqlite3BtreeHoldsMutex(p) );
   assert( pBt->inTransaction==TRANS_WRITE );
index 3eb5906955f883b8a941f8362cd4a5e52828116a..3266fbca3cf2376427ae994d4a8c827f6d5fc81c 100644 (file)
@@ -56,10 +56,11 @@ int sqlite3BtreeOpen(
 ** NOTE:  These values must match the corresponding PAGER_ values in
 ** pager.h.
 */
-#define BTREE_OMIT_JOURNAL  1  /* Do not create or use a rollback journal */
-#define BTREE_MEMORY        2  /* This is an in-memory DB */
-#define BTREE_SINGLE        4  /* The file contains at most 1 b-tree */
-#define BTREE_UNORDERED     8  /* Use of a hash implementation is OK */
+#define BTREE_OMIT_JOURNAL  0x01  /* Do not create or use a rollback journal */
+#define BTREE_MEMORY        0x02  /* This is an in-memory DB */
+#define BTREE_SINGLE        0x04  /* The file contains at most 1 b-tree */
+#define BTREE_UNORDERED     0x08  /* Use of a hash implementation is OK */
+#define BTREE_SINGLE_INDEX  0x10  /* File contains one index btree */
 
 int sqlite3BtreeClose(Btree*);
 int sqlite3BtreeSetCacheSize(Btree*,int);
index 037b02f12afdb3897ead928cefa8b50a24255f75..22501fbf62ca2aa87685bc9134a023aa891d94e6 100644 (file)
@@ -3324,7 +3324,7 @@ case OP_OpenWrite: {
 case OP_OpenAutoindex: 
 case OP_OpenEphemeral: {
   VdbeCursor *pCx;
-  KeyInfo *pKeyInfo;
+  int btreeFlags;
 
   static const int vfsFlags = 
       SQLITE_OPEN_READWRITE |
@@ -3337,34 +3337,21 @@ case OP_OpenEphemeral: {
   pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
   if( pCx==0 ) goto no_mem;
   pCx->nullRow = 1;
-  rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBt, 
-                        BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
+  btreeFlags = BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5;
+  if( pOp->p4.pKeyInfo ) btreeFlags |= BTREE_SINGLE_INDEX;
+  rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBt, btreeFlags, vfsFlags);
   if( rc==SQLITE_OK ){
     rc = sqlite3BtreeBeginTrans(pCx->pBt, 1);
   }
+  assert( pOp->p4.pKeyInfo==0 || pOp->p4type==P4_KEYINFO );
+  assert( pOp->p4.pKeyInfo==0 || pOp->p4.pKeyInfo->db==db );
+  assert( pOp->p4.pKeyInfo==0 || pOp->p4.pKeyInfo->enc==ENC(db) );
   if( rc==SQLITE_OK ){
-    /* If a transient index is required, create it by calling
-    ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
-    ** opening it. If a transient table is required, just use the
-    ** automatically created table with root-page 1 (an BLOB_INTKEY table).
-    */
-    if( (pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
-      int pgno;
-      assert( pOp->p4type==P4_KEYINFO );
-      rc = sqlite3BtreeCreateTable(pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5); 
-      if( rc==SQLITE_OK ){
-        assert( pgno==MASTER_ROOT+1 );
-        assert( pKeyInfo->db==db );
-        assert( pKeyInfo->enc==ENC(db) );
-        pCx->pKeyInfo = pKeyInfo;
-        rc = sqlite3BtreeCursor(pCx->pBt, pgno, 1, pKeyInfo, pCx->pCursor);
-      }
-      pCx->isTable = 0;
-    }else{
-      rc = sqlite3BtreeCursor(pCx->pBt, MASTER_ROOT, 1, 0, pCx->pCursor);
-      pCx->isTable = 1;
-    }
+    rc = sqlite3BtreeCursor(pCx->pBt, MASTER_ROOT, 1, pOp->p4.pKeyInfo,
+                            pCx->pCursor);
   }
+  pCx->pKeyInfo = pOp->p4.pKeyInfo;
+  pCx->isTable = pCx->pKeyInfo==0;
   pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
   break;
 }