From: drh Date: Tue, 22 Feb 2011 03:34:56 +0000 (+0000) Subject: When a stale schema-cookie is seen, expire only the one statement that X-Git-Tag: version-3.7.6~131 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5b6c545ba153f032ec504a1294919316a2f34760;p=thirdparty%2Fsqlite.git When a stale schema-cookie is seen, expire only the one statement that encountered the bad cookie, not every statement on the database connection. Ticket [b72787b1a7cea1f] FossilOrigin-Name: 1bca0a7e198391202fd2bc1650c0a62028a9aaa5 --- diff --git a/install-sh b/install-sh old mode 100644 new mode 100755 diff --git a/manifest b/manifest index 9c2de2183e..fe60fecc90 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,8 @@ -C Fix\sa\sproblem\swith\s"EXPLAIN\sQUERY\sPLAN\sSELECT\scount(*)\sFROM\stbl". -D 2011-02-21T17:49:49 +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA1 + +C When\sa\sstale\sschema-cookie\sis\sseen,\sexpire\sonly\sthe\sone\sstatement\sthat\nencountered\sthe\sbad\scookie,\snot\severy\sstatement\son\sthe\sdatabase\s\nconnection.\s\sTicket\s[b72787b1a7cea1f] +D 2011-02-22T03:34:56.684 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 27701a1653595a1f2187dc61c8117e00a6c1d50f F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -98,7 +101,7 @@ F ext/rtree/rtree_util.tcl 06aab2ed5b826545bf215fff90ecb9255a8647ea F ext/rtree/sqlite3rtree.h 1af0899c63a688e272d69d8e746f24e76f10a3f0 F ext/rtree/tkt3363.test 142ab96eded44a3615ec79fba98c7bde7d0f96de F ext/rtree/viewrtree.tcl eea6224b3553599ae665b239bd827e182b466024 -F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 +F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F main.mk 54190fab7cdba523e311c274c95ea480f32abfb5 F mkdll.sh 7d09b23c05d56532e9d44a50868eb4b12ff4f74a @@ -229,7 +232,7 @@ F src/update.c 227e6cd512108b84f69421fc6c7aa1b83d60d6e0 F src/utf.c 1baeeac91707a4df97ccc6141ec0f808278af685 F src/util.c ab1c92426494f499f42b9e307537b03e923d75c1 F src/vacuum.c 924bd1bcee2dfb05376f79845bd3b4cec7b54b2f -F src/vdbe.c 167432ac0db5820b886685a7a6ad8f39520db4fb +F src/vdbe.c 34305497d81daafdb1e500bfaa21d044c64503de F src/vdbe.h 4de0efb4b0fdaaa900cf419b35c458933ef1c6d2 F src/vdbeInt.h 6e6f28e9bccc6c703dca1372fd661c57b5c15fb0 F src/vdbeapi.c 8e9324fd35eb70d0b5904bd1af40f2598744dc4d @@ -597,7 +600,7 @@ F test/permutations.test 5b2a4cb756ffb2407cb4743163668d1d769febb6 F test/pragma.test fdfc09067ea104a0c247a1a79d8093b56656f850 F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47 F test/printf.test 05970cde31b1a9f54bd75af60597be75a5c54fea -F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301 x +F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301 F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc F test/quick.test 1681febc928d686362d50057c642f77a02c62e57 F test/quota.test ddafe133653093eb9a99ccd6264884ae43f9c9b8 @@ -703,6 +706,7 @@ F test/tkt-8454a207b9.test c583a9f814a82a2b5ba95207f55001c9f0cd816c F test/tkt-94c04eaadb.test be5ea61cb04dfdc047d19b5c5a9e75fa3da67a7f F test/tkt-9d68c883.test 458f7d82a523d7644b54b497c986378a7d8c8b67 F test/tkt-b351d95f9.test d14a503c414c5c58fdde3e80f9a3cfef986498c0 +F test/tkt-b72787b1.test e6b62b2b2785c04d0d698d6a603507e384165049 F test/tkt-cbd054fa6b.test f14f97ea43662e6f70c9e63287081e8be5d9d589 F test/tkt-d11f09d36e.test fb44f7961aa6d4b632fb7b9768239832210b5fc7 F test/tkt-d82e3f3721.test 731359dfdcdb36fea0559cd33fec39dd0ceae8e6 @@ -883,7 +887,7 @@ F tool/genfkey.test 4196a8928b78f51d54ef58e99e99401ab2f0a7e5 F tool/lemon.c dfd81a51b6e27e469ba21d01a75ddf092d429027 F tool/lempar.c 01ca97f87610d1dac6d8cd96ab109ab1130e76dc F tool/mkkeywordhash.c d2e6b4a5965e23afb80fbe74bb54648cd371f309 -F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e x +F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97 F tool/mksqlite3c.tcl cf44512a48112b1ba09590548660a5a6877afdb3 F tool/mksqlite3h.tcl d76c226a5e8e1f3b5f6593bcabe5e98b3b1ec9ff @@ -908,7 +912,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 01076528a43b61ae20ef6969b7d326de9b5313e4 -R ea0b61d4a154cb9b4ce10e2d0f175950 -U dan -Z bee26eb130eb27a9686da9ca1f7baaf2 +P 9f9f32882501ac9b6e60f81195a64bdbf6e4497b +R 5f31f20137e37610967a0c8c09aa1cdf +U drh +Z efa7e00c780185dfb46b103f7c160f16 +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.4.6 (GNU/Linux) + +iD8DBQFNYy7koxKgR168RlERAptAAJ0SwgTWX7lSr3APOJLkJfc852ZtVgCfcyeE +jtbsyJxLadCeUXNXPwdyqQ0= +=vXCW +-----END PGP SIGNATURE----- diff --git a/manifest.uuid b/manifest.uuid index fa1d51f17d..0f0273c630 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9f9f32882501ac9b6e60f81195a64bdbf6e4497b \ No newline at end of file +1bca0a7e198391202fd2bc1650c0a62028a9aaa5 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index c2237ebf97..00ed1438b5 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -2920,7 +2920,7 @@ case OP_VerifyCookie: { sqlite3ResetInternalSchema(db, pOp->p1); } - sqlite3ExpirePreparedStatements(db); + p->expired = 1; rc = SQLITE_SCHEMA; } break; diff --git a/test/progress.test b/test/progress.test old mode 100755 new mode 100644 diff --git a/test/tkt-b72787b1.test b/test/tkt-b72787b1.test new file mode 100644 index 0000000000..11ea41ed7a --- /dev/null +++ b/test/tkt-b72787b1.test @@ -0,0 +1,77 @@ +# 2011 February 21 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests to verify that ticket [b72787b1a7] has been +# fixed. From the ticket: +# +# The sqlite3ExpirePreparedStatements routine marks all statements +# as expired. This includes statements that are not expired. +# +# Steps to reproduce: +# +# * Prepare a statement (A) +# * Alter the schema to invalidate cookie in A +# * Prepare a statement (B) +# * Run B and have A run as part of B +# * A will find a bad cookie and cause *all* statements +# to be expired including the currently running B by calling +# sqlite3ExpirePreparedStatements +# * When control returns to B it will then abort +# +# The bug is that sqlite3ExpirePreparedStatements expires all statements. +# Note that B was prepared after the schema change and hence is perfectly +# valid and then is marked as expired while running. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +unset -nocomplain ::STMT +proc runsql {} { + db eval {CREATE TABLE IF NOT EXISTS t4(q)} + sqlite3_step $::STMT + set rc [sqlite3_column_int $::STMT 0] + sqlite3_reset $::STMT + return $rc +} + +do_test tkt-b72787b1.1 { + db eval { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(1); + INSERT INTO t1 VALUES(2); + CREATE TABLE t2(y); + INSERT INTO t2 SELECT x+2 FROM t1; + INSERT INTO t2 SELECT x+4 FROM t1; + } + db func runsql ::runsql + set DB [sqlite3_connection_pointer db] + set sql {SELECT max(x) FROM t1} + set ::STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL] + + # The runsql() call on the second row of the first query will + # cause all $::STMT to hit an expired cookie. Prior to the fix + # for [b72787b1a7, the bad cookie would expire all statements, including + # the following compound SELECT, which would cause a fault when the + # second SELECT was reached. After the fix, the current statement + # continues to completion. + db eval { + SELECT CASE WHEN y=3 THEN y+100 WHEN y==4 THEN runsql()+200 + ELSE 300+y END FROM t2 + UNION ALL + SELECT * FROM t1; + } +} {103 202 305 306 1 2} + +sqlite3_finalize $::STMT + +finish_test diff --git a/tool/mkopts.tcl b/tool/mkopts.tcl old mode 100755 new mode 100644