SQLite

Check-in [991ce81150]
Login

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

Overview
Comment:The new Btree code runs, but it does not yet work. (CVS 240)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 991ce8115052da9395d4bf8ff29f417e3c36dc7f
User & Date: drh 2001-09-13 15:21:32.000
Context
2001-09-13
16:18
It runs. Simple tables can be created. INSERT and SELECT work. Much more testing is needed, however. (CVS 241) (check-in: 9ac8399c99 user: drh tags: trunk)
15:21
The new Btree code runs, but it does not yet work. (CVS 240) (check-in: 991ce81150 user: drh tags: trunk)
14:46
The BTree changes are now integrated and the whole thing compiles and links. I have not yet tried to run it, though. (CVS 239) (check-in: a0a1e701ab user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to VERSION.
1
1.0.32
|
1
1.1.0
Changes to src/TODO.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

31
32
33
34
35
  *  Finish fleshing out the db.c file.
      - sqliteDbReadOvfl
      - sqliteDbSpreadLoad
      - sqliteDbSplit
      - sqliteDbNextIndexLevel
      - fix sqliteDbCursorNext to work right after sqliteDbCursorDelete
  *  Compile db.c with -Wall and get no errors.
  *  Make a pass over pg.c and db.c looking for errors.
      - correct handling of I/O errors, malloc failures, etc.
      - page leaks  (not calling sqlitePgUnref)
  *  Write a test interface for db.c.
  *  Compile and link against the db test interface.
  *  Generate tests for the db interface.
  *  Add read/write locks to pg.c
  *  Add an sqliteDbReorganize() function.
  *  Integrate db into vdbe.
  *  Modify code generation to take advantage of the new db interface.
      - Able to delete without disturbing scan order
      - Now keeps a count of number of table entries
         + Special processing for count(*)
         + Better selection of indices on a select
      - Transactions
  *  Modify sqlite_master to store the table number.
  *  Add a cache in DbCursor to speed up the sqliteDbReadOvfl() routine.
  *  Add cache information to speed up sqliteDbCursorMoveTo().

Longer term:
  *  Document all the changes and release Sqlite 2.0.
  *  Techniques for optimizing querys by grouping data with similar
     indices.

  *  "OPTIMIZE select" statement to automatically create and/or tune
     indices.
  *  "CREATE INDEX FOR select" to automatically generate needed indices.
  *  "VACUUM table USING index".
  *  Parse and use constraints.
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

<
<
>
|
|

|




























1


2
3
4
5
6
7



























  *  Document all the changes and release Sqlite 2.0.


  *  Implement CLUSTER command like in PostgreSQL.
  *  "OPTIMIZE select" statement to automatically create indices and/or
     invoke a CLUSTER command.
  *  "CREATE INDEX FOR select" to automatically generate needed indices.
  *  Implement a PRAGMA command
  *  Parse and use constraints.
Changes to src/main.c.
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.31 2001/09/13 14:46:10 drh Exp $
*/
#include "sqliteInt.h"
#if defined(HAVE_USLEEP) && HAVE_USLEEP
#include <unistd.h>
#endif

/*







|







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
**
*************************************************************************
** Main file for the SQLite library.  The routines in this file
** implement the programmer interface to the library.  Routines in
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.32 2001/09/13 15:21:32 drh Exp $
*/
#include "sqliteInt.h"
#if defined(HAVE_USLEEP) && HAVE_USLEEP
#include <unistd.h>
#endif

/*
178
179
180
181
182
183
184

185
186
187
188
189
190
191
    char *azArg[2];
    azArg[0] = master_schema;
    azArg[1] = 0;
    sqliteOpenCb(db, 1, azArg, 0);
    pTab = sqliteFindTable(db, MASTER_NAME);
    if( pTab ){
      pTab->readOnly = 1;

    }
    db->flags |= SQLITE_Initialized;
    sqliteCommitInternalChanges(db);
  }
  return rc;
}








>







178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
    char *azArg[2];
    azArg[0] = master_schema;
    azArg[1] = 0;
    sqliteOpenCb(db, 1, azArg, 0);
    pTab = sqliteFindTable(db, MASTER_NAME);
    if( pTab ){
      pTab->readOnly = 1;
      pTab->tnum = 2;
    }
    db->flags |= SQLITE_Initialized;
    sqliteCommitInternalChanges(db);
  }
  return rc;
}

Changes to src/vdbe.c.
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
** inplicit conversion from one type to the other occurs as necessary.
** 
** Most of the code in this file is taken up by the sqliteVdbeExec()
** function which does the work of interpreting a VDBE program.
** But other routines are also provided to help in building up
** a program instruction by instruction.
**
** $Id: vdbe.c,v 1.61 2001/09/13 14:46:11 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** SQL is translated into a sequence of instructions to be
** executed by a virtual machine.  Each instruction is an instance







|







37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
** inplicit conversion from one type to the other occurs as necessary.
** 
** Most of the code in this file is taken up by the sqliteVdbeExec()
** function which does the work of interpreting a VDBE program.
** But other routines are also provided to help in building up
** a program instruction by instruction.
**
** $Id: vdbe.c,v 1.62 2001/09/13 15:21:32 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** SQL is translated into a sequence of instructions to be
** executed by a virtual machine.  Each instruction is an instance
2593
2594
2595
2596
2597
2598
2599




























































2600
2601
2602
2603
2604
2605
2606
** Delete an entire database table or index whose root page in the database
** file is given by P1.
*/
case OP_Destroy: {
  sqliteBtreeDropTable(pBt, pOp->p1);
  break;
}





























































/* Opcode: Reorganize P1 * *
**
** Compress, optimize, and tidy up table or index whose root page in the
** database file is P1.
*/
case OP_Reorganize: {







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
** Delete an entire database table or index whose root page in the database
** file is given by P1.
*/
case OP_Destroy: {
  sqliteBtreeDropTable(pBt, pOp->p1);
  break;
}

/* Opcode: CreateTable * * *
**
** Allocate a new table in the main database file.  Push the page number
** for the root page of the new table onto the stack.
**
** The root page number is also written to a memory location which has
** be set up by the parser.  The difference between CreateTable and
** CreateIndex is that each writes its root page number into a different
** memory location.  This writing of the page number into a memory location
** is used by the SQL parser to record the page number in its internal
** data structures.
*/
case OP_CreateTable: {
  int i = ++p->tos;
  int pgno;
  VERIFY( if( NeedStack(p, p->tos) ) goto no_mem; )
  if( p->pTableRoot==0 ){
    rc = SQLITE_INTERNAL;
    goto abort_due_to_error;
  }
  rc = sqliteBtreeCreateTable(pBt, &pgno);
  if( rc==SQLITE_OK ){
    aStack[i].i = pgno;
    aStack[i].flags = STK_Int;
    *p->pTableRoot = pgno;
    p->pTableRoot = 0;
  }
  break;
}

/* Opcode: CreateIndex * * *
**
** Allocate a new Index in the main database file.  Push the page number
** for the root page of the new table onto the stack.
**
** The root page number is also written to a memory location which has
** be set up by the parser.  The difference between CreateTable and
** CreateIndex is that each writes its root page number into a different
** memory location.  This writing of the page number into a memory location
** is used by the SQL parser to record the page number in its internal
** data structures.
*/
case OP_CreateIndex: {
  int i = ++p->tos;
  int pgno;
  VERIFY( if( NeedStack(p, p->tos) ) goto no_mem; )
  if( p->pIndexRoot==0 ){
    rc = SQLITE_INTERNAL;
    goto abort_due_to_error;
  }
  rc = sqliteBtreeCreateTable(pBt, &pgno);
  if( rc==SQLITE_OK ){
    aStack[i].i = pgno;
    aStack[i].flags = STK_Int;
    *p->pIndexRoot = pgno;
    p->pIndexRoot = 0;
  }
  break;
}

/* Opcode: Reorganize P1 * *
**
** Compress, optimize, and tidy up table or index whose root page in the
** database file is P1.
*/
case OP_Reorganize: {
3619
3620
3621
3622
3623
3624
3625




3626
3627
3628
3629
3630
3631
3632
      fprintf(p->trace,"\n");
    }
#endif
  }

cleanup:
  Cleanup(p);




  if( rc!=SQLITE_OK && (db->flags & SQLITE_InTrans)!=0 ){
    sqliteBtreeRollback(pBt);
    sqliteRollbackInternalChanges(db);
    db->flags &= ~SQLITE_InTrans;
  }
  return rc;








>
>
>
>







3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
      fprintf(p->trace,"\n");
    }
#endif
  }

cleanup:
  Cleanup(p);
  if( p->pTableRoot || p->pIndexRoot ){
    rc = SQLITE_INTERNAL;
    sqliteSetString(pzErrMsg, "table or index root page not set", 0);
  }
  if( rc!=SQLITE_OK && (db->flags & SQLITE_InTrans)!=0 ){
    sqliteBtreeRollback(pBt);
    sqliteRollbackInternalChanges(db);
    db->flags &= ~SQLITE_InTrans;
  }
  return rc;