/ Check-in [c0689409]
Login

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

Overview
Comment:Minor cleanup changes on the OP_StackDepth opcode. Added the sidedelete test for additional testing of ticket #2832. (CVS 4619)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c0689409320de1532be0c0cae12b4b716f6bffb9
User & Date: drh 2007-12-12 22:24:13
Context
2007-12-13
02:45
Towards getting ORDER BY to match against the correctin columns. This version only looks at the left-most column in a compound SELECT. That is the correct thing to do, but not what SQLite has historically done. (CVS 4620) check-in: bbddf16a user: drh tags: trunk
2007-12-12
22:24
Minor cleanup changes on the OP_StackDepth opcode. Added the sidedelete test for additional testing of ticket #2832. (CVS 4619) check-in: c0689409 user: drh tags: trunk
18:05
Remove an (explain) accidentally left in tkt2832.test. (CVS 4618) check-in: 48947e2b user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

    39     39   **
    40     40   ** Various scripts scan this source file in order to generate HTML
    41     41   ** documentation, headers files, or other derived files.  The formatting
    42     42   ** of the code in this file is, therefore, important.  See other comments
    43     43   ** in this file for details.  If in doubt, do not deviate from existing
    44     44   ** commenting and indentation practices when changing or adding code.
    45     45   **
    46         -** $Id: vdbe.c,v 1.658 2007/12/12 12:25:22 drh Exp $
           46  +** $Id: vdbe.c,v 1.659 2007/12/12 22:24:13 drh Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include <ctype.h>
    50     50   #include "vdbeInt.h"
    51     51   
    52     52   /*
    53     53   ** The following global variable is incremented every time a cursor
................................................................................
   697    697   ** If P1 is less than zero, then store the current stack depth
   698    698   ** in P1.  If P1 is zero or greater, verify that the current stack
   699    699   ** depth is equal to P1 and throw an exception if it is not.
   700    700   **
   701    701   ** This opcode is used for internal consistency checking.
   702    702   */
   703    703   case OP_StackDepth: {       /* no-push */
          704  +  int n = pTos - p->aStack + 1;
   704    705     if( pOp->p1<0 ){
   705         -    pOp->p1 = pTos - p->aStack + 1;
   706         -  }else if( pOp->p1!=pTos - p->aStack + 1 ){
          706  +    pOp->p1 = n;
          707  +  }else if( pOp->p1!=n ){
   707    708       p->pTos = pTos;
   708    709       p->rc = rc = SQLITE_INTERNAL;
   709    710       p->pc = pc;
   710    711       p->errorAction = OE_Rollback;
   711    712       sqlite3SetString(&p->zErrMsg, "internal error: VDBE stack leak", (char*)0);
   712    713       goto vdbe_return;
   713    714     }

Added test/sidedelete.test.

            1  +# 2007 Dec 12
            2  +#
            3  +# The author disclaims copyright to this source code. In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +#
           12  +# This file contains test cases for stressing database
           13  +# changes that involve side effects that delete rows from
           14  +# the table being changed.  Ticket #2832 shows that in
           15  +# older versions of SQLite that behavior was implemented
           16  +# incorrectly and resulted in corrupt database files.
           17  +#
           18  +# $Id: sidedelete.test,v 1.1 2007/12/12 22:24:13 drh Exp $
           19  +#
           20  +
           21  +set testdir [file dirname $argv0]
           22  +source $testdir/tester.tcl
           23  +
           24  +# The sequence table is created to store a sequence of integers
           25  +# starting with 1.  This is used to reinitialize other tables
           26  +# as part of other tests.
           27  +#
           28  +do_test sidedelete-1.1 {
           29  +  execsql {
           30  +    CREATE TABLE sequence(a INTEGER PRIMARY KEY);
           31  +    INSERT INTO sequence VALUES(1);
           32  +    INSERT INTO sequence VALUES(2);
           33  +  }
           34  +  for {set i 0} {$i<8} {incr i} {
           35  +    execsql {
           36  +      INSERT INTO sequence SELECT a+(SELECT max(a) FROM sequence) FROM sequence;
           37  +    }
           38  +  }
           39  +  execsql {SELECT count(*) FROM sequence}
           40  +} {512}
           41  +
           42  +# Make a series of changes using an UPDATE OR REPLACE and a
           43  +# correlated subquery.  This would cause database corruption
           44  +# prior to the fix for ticket #2832.
           45  +#
           46  +do_test sidedelete-2.0 {
           47  +  execsql {
           48  +    CREATE TABLE t1(a PRIMARY KEY, b);
           49  +    CREATE TABLE chng(a PRIMARY KEY, b);
           50  +    SELECT count(*) FROM t1 UNION ALL SELECT count(*) FROM chng;
           51  +  }
           52  +} {0 0}
           53  +for {set i 2} {$i<=100} {incr i} {
           54  +  set n [expr {($i+2)/2}]
           55  +  do_test sidedelete-2.$i.1 {
           56  +    execsql {
           57  +      DELETE FROM t1;
           58  +      INSERT INTO t1 SELECT a, a FROM sequence WHERE a<=$i;
           59  +      DELETE FROM chng;
           60  +      INSERT INTO chng SELECT a*2, a*2+1 FROM sequence WHERE a<=$i/2;
           61  +      UPDATE OR REPLACE t1 SET a=(SELECT b FROM chng WHERE a=t1.a);
           62  +      SELECT count(*), sum(a) FROM t1;
           63  +    }
           64  +  } [list $n [expr {$n*$n-1}]]
           65  +  integrity_check sidedelete-2.$i.2
           66  +}
           67  +
           68  +# This will cause stacks leaks but not database corruption prior
           69  +# to the #2832 fix.
           70  +#
           71  +do_test sidedelete-3.0 {
           72  +  execsql {
           73  +     DROP TABLE t1;
           74  +     CREATE TABLE t1(a PRIMARY KEY);
           75  +     SELECT * FROM t1;
           76  +  }
           77  +} {}
           78  +for {set i 1} {$i<=100} {incr i} {
           79  +  set n [expr {($i+1)/2}]
           80  +  do_test sidedelete-3.$i.1 {
           81  +    execsql {
           82  +      DELETE FROM t1;
           83  +      INSERT INTO t1 SELECT a FROM sequence WHERE a<=$i;
           84  +      UPDATE OR REPLACE t1 SET a=a+1;
           85  +      SELECT count(*), sum(a) FROM t1;
           86  +    }
           87  +  } [list $n [expr {$n*($n+1)}]]
           88  +  integrity_check sidedelete-3.$i.2
           89  +}
           90  +
           91  +finish_test