Bring testing coverage of the analyze.c file up to 100%. Bugs found and

fixed in the process. (CVS 2599)

FossilOrigin-Name: 2fe0ac4fa4d5911e266979021fa7e413d96c558d
This commit is contained in:
drh 2005-08-19 00:14:42 +00:00
parent 91124b3545
commit 8b3d990b71
8 changed files with 123 additions and 22 deletions

View File

@ -1,5 +1,5 @@
C Comment\sfixes.\s\sNo\schanges\sto\sthe\sunderlying\scode.\s(CVS\s2598)
D 2005-08-18T18:15:06
C Bring\stesting\scoverage\sof\sthe\sanalyze.c\sfile\sup\sto\s100%.\s\sBugs\sfound\sand\nfixed\sin\sthe\sprocess.\s(CVS\s2599)
D 2005-08-19T00:14:42
F Makefile.in b109ddb46a5550d0732dcd6caca01c123f6d5cdd
F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -60,16 +60,16 @@ F src/pager.c ee3bbc4cd590a0266c791b4ed537cbd9a9d03566
F src/pager.h 0d9153d6269d60d04af3dd84a0cc0a96253cf4a4
F src/parse.y d57cdd2adc0923762b40314f08683c836a2e0c90
F src/pragma.c 69413fbdc0c6aaa493a776ea52c1b3e6cf35dfb2
F src/prepare.c fa0f6068d9b8ec6d5c419c65d4d8ff747d49c5c6
F src/prepare.c 86f0d8e744b8d956eff6bc40e29049efee017610
F src/printf.c 772b15c3395fa60bdbf3aaa03d480ecde38bf192
F src/random.c 90adff4e73a3b249eb4f1fc2a6ff9cf78c7233a4
F src/select.c f441648eb191dcf1e67ae61475ea3b40a0eeb787
F src/shell.c 86c16f0d534aa51cc82cf9f66903d4eb681580e7
F src/sqlite.h.in a3b75a6b2e66865fba4ec1b698d00c7d95fe27a2
F src/sqliteInt.h 40370b51b902b4789ca6d4a016d00fa981803661
F src/sqliteInt.h e5fb91af1d607f3bc84bfb7da8534fd3298a38b0
F src/table.c 25b3ff2b39b7d87e8d4a5da0713d68dfc06cbee9
F src/tclsqlite.c e86b5483de6cb1ec1154cc5b76e3427d4b214961
F src/test1.c a2333add4a25e47c268ea83df32cc7adf086d5d9
F src/test1.c 6a36fa85e9d0d4f0eaa7eadd087e40ce9cf35074
F src/test2.c 792f203be69fea88668fa221321194f0a28dfdfa
F src/test3.c f4e6a16a602091696619a1171bda25c0e3df49f7
F src/test4.c a8fd681e139e1c61f22a77d07fc3a99cb28fff3f
@ -87,13 +87,13 @@ F src/vdbeapi.c dc5b78cabf8d6e33318bd3d4ed25307d2aadce9a
F src/vdbeaux.c 6b2e54ac0b8ea95411029efff5404eb68d12d28c
F src/vdbefifo.c b8805850afe13b43f1de78d58088cb5d66f88e1e
F src/vdbemem.c 89154caae3b8d4d0397e1235390fc4ff8aba4233
F src/where.c de4b36842d64b6d12fc1896407d526bf88b67d22
F src/where.c a8401eb8eb8db37996e4c835cd4373de875c1488
F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
F test/all.test 7f0988442ab811dfa41793b5b550f5828ce316f3
F test/alter.test 9d6837a3d946b73df692b7cef2a7644d2e2f6bc6
F test/alter2.test 60ba0a7057dc71ad630a1cc7c487104346849d50
F test/alter3.test d4eecd8dbd008d0e66f1c201fa6dc2edca853c38
F test/analyze.test ac50d2a24118ce5f0f9b50cc563a1a1498a948c4
F test/analyze.test a1206c7430606ffa20bcbb220c87c2873f5efdd4
F test/attach.test f320e98bcca68d100cab7666a0c9a93ac5f236bd
F test/attach2.test 3396c012a39ddf7ba6b528d80bd79554168aa115
F test/attach3.test 63013383adc4380af69779f34f4af19bd49f7cbe
@ -160,7 +160,7 @@ F test/join4.test 1a352e4e267114444c29266ce79e941af5885916
F test/journal1.test 36f2d1bb9bf03f790f43fbdb439e44c0657fab19
F test/lastinsert.test eaa89c6ee1f13062d87139fd32c1e56753d2fd89
F test/laststmtchanges.test 19a6d0c11f7a31dc45465b495f7b845a62cbec17
F test/like.test b94052f73f10504f61cf102774a6048297d35aab
F test/like.test b1e77e327add19ac4ddc371cbf4f208b344ab878
F test/limit.test 270b076f31c5c32f7187de5727e74da4de43e477
F test/lock.test 9b7afcb24f53d24da502abb33daaad2cd6d44107
F test/lock2.test 59c3dd7d9b24d1bf7ec91b2d1541c37e97939d5f
@ -293,7 +293,7 @@ F www/tclsqlite.tcl 3df553505b6efcad08f91e9b975deb2e6c9bb955
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P 32efcd24612908516fb5bc58ab3fe4790586a220
R ced5bebb2351f8c1207ade49d6285b42
P b865e243ee772f009dbf466d69525f2cdef78c0e
R d80e488a663ed9391ee71a30f9bfe38b
U drh
Z e23c5432bca86a11aa997bf8f8f76646
Z db420958562db69c6ce814b79165077a

View File

@ -1 +1 @@
b865e243ee772f009dbf466d69525f2cdef78c0e
2fe0ac4fa4d5911e266979021fa7e413d96c558d

View File

@ -13,7 +13,7 @@
** interface, and routines that contribute to loading the database schema
** from disk.
**
** $Id: prepare.c,v 1.2 2005/07/23 03:18:40 drh Exp $
** $Id: prepare.c,v 1.3 2005/08/19 00:14:42 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@ -375,7 +375,7 @@ int sqlite3ReadSchema(Parse *pParse){
rc = sqlite3Init(db, &pParse->zErrMsg);
}
}
assert( rc!=SQLITE_OK || (db->flags & SQLITE_Initialized)||db->init.busy );
assert( rc!=SQLITE_OK || (db->flags & SQLITE_Initialized) || db->init.busy );
if( rc!=SQLITE_OK ){
pParse->rc = rc;
pParse->nErr++;

View File

@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.402 2005/08/14 01:20:39 drh Exp $
** @(#) $Id: sqliteInt.h,v 1.403 2005/08/19 00:14:42 drh Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
@ -751,7 +751,7 @@ struct Index {
char *zName; /* Name of this index */
int nColumn; /* Number of columns in the table used by this index */
int *aiColumn; /* Which columns are used by this index. 1st is 0 */
int *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */
unsigned *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */
Table *pTable; /* The SQL table being indexed */
int tnum; /* Page containing root of this index in database file */
u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */

View File

@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
** $Id: test1.c,v 1.154 2005/08/14 01:20:39 drh Exp $
** $Id: test1.c,v 1.155 2005/08/19 00:14:42 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@ -3113,6 +3113,9 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
extern int sqlite3_memMax;
extern char sqlite3_query_plan[];
extern int sqlite3_like_count;
#ifdef SQLITE_DEBUG
extern int sqlite3_vdbe_addop_trace;
#endif
static char *query_plan = sqlite3_query_plan;
for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
@ -3138,6 +3141,10 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
(char*)&sqlite3_os_trace, TCL_LINK_INT);
Tcl_LinkVar(interp, "sqlite_where_trace",
(char*)&sqlite3_where_trace, TCL_LINK_INT);
#ifdef SQLITE_DEBUG
Tcl_LinkVar(interp, "sqlite_addop_trace",
(char*)&sqlite3_vdbe_addop_trace, TCL_LINK_INT);
#endif
#ifdef SQLITE_MEMDEBUG
Tcl_LinkVar(interp, "sqlite_memused",
(char*)&sqlite3_memUsed, TCL_LINK_INT | TCL_LINK_READ_ONLY);

View File

@ -16,7 +16,7 @@
** so is applicable. Because this module is responsible for selecting
** indices, you might also think of this module as the "query optimizer".
**
** $Id: where.c,v 1.162 2005/08/14 01:20:39 drh Exp $
** $Id: where.c,v 1.163 2005/08/19 00:14:42 drh Exp $
*/
#include "sqliteInt.h"
@ -1198,7 +1198,7 @@ static void codeAllEqualityTerms(
/* Evaluate the equality constraints
*/
for(j=0; 1; j++){
for(j=0; j<pIdx->nColumn; j++){
int k = pIdx->aiColumn[j];
pTerm = findTerm(pWC, iCur, k, notReady, WO_EQ|WO_IN, pIdx);
if( pTerm==0 ) break;
@ -1739,7 +1739,7 @@ WhereInfo *sqlite3WhereBegin(
int nEq = pLevel->nEq;
/* Generate code to evaluate all constraint terms using == or IN
** and level the values of those terms on the stack.
** and leave the values of those terms on the stack.
*/
codeAllEqualityTerms(pParse, pLevel, &wc, notReady, brk);

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library.
# This file implements tests for the ANALYZE command.
#
# $Id: analyze.test,v 1.2 2005/07/23 14:52:12 drh Exp $
# $Id: analyze.test,v 1.3 2005/08/19 00:14:43 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -186,5 +186,66 @@ do_test analyze-3.8 {
}
} {t3i1 {5 3} t3i2 {5 3 1 1 1} t3i3 {5 5 2 1 1}}
# Try corrupting the sqlite_stat1 table and make sure the
# database is still able to function.
#
do_test analyze-4.0 {
sqlite3 db2 test.db
db2 eval {
CREATE TABLE t4(x,y,z);
CREATE INDEX t4i1 ON t4(x);
CREATE INDEX t4i2 ON t4(y);
INSERT INTO t4 SELECT a,b,c FROM t3;
}
db2 close
db close
sqlite3 db test.db
execsql {
ANALYZE;
SELECT idx, stat FROM sqlite_stat1 ORDER BY idx;
}
} {t3i1 {5 3} t3i2 {5 3 1 1 1} t3i3 {5 5 2 1 1} t4i1 {5 3} t4i2 {5 2}}
do_test analyze-4.1 {
execsql {
PRAGMA writable_schema=on;
INSERT INTO sqlite_stat1 VALUES(null,null,null);
PRAGMA writable_schema=off;
}
db close
sqlite3 db test.db
execsql {
SELECT * FROM t4 WHERE x=1234;
}
} {}
do_test analyze-4.2 {
execsql {
PRAGMA writable_schema=on;
DELETE FROM sqlite_stat1;
INSERT INTO sqlite_stat1 VALUES('t4','t4i1','nonsense');
INSERT INTO sqlite_stat1 VALUES('t4','t4i2','120897349817238741092873198273409187234918720394817209384710928374109827172901827349871928741910');
PRAGMA writable_schema=off;
}
db close
sqlite3 db test.db
execsql {
SELECT * FROM t4 WHERE x=1234;
}
} {}
# This test corrupts the database file so it must be the last test
# in the series.
#
do_test analyze-99.1 {
execsql {
PRAGMA writable_schema=on;
UPDATE sqlite_master SET sql='nonsense';
}
db close
sqlite3 db test.db
catchsql {
ANALYZE
}
} {1 {malformed database schema - near "nonsense": syntax error}}
finish_test

View File

@ -13,7 +13,7 @@
# in particular the optimizations that occur to help those operators
# run faster.
#
# $Id: like.test,v 1.1 2005/08/14 01:20:40 drh Exp $
# $Id: like.test,v 1.2 2005/08/19 00:14:43 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -280,4 +280,37 @@ do_test like-3.24 {
set sqlite_like_count
} 6
# No optimization if the LHS of the LIKE is not a column name or
# if the RHS is not a string.
#
do_test like-4.1 {
execsql {PRAGMA case_sensitive_like=on}
set sqlite_like_count 0
queryplan {
SELECT x FROM t1 WHERE x LIKE 'abc%' ORDER BY 1
}
} {abc abcd nosort {} i1}
do_test like-4.2 {
set sqlite_like_count
} 0
do_test like-4.3 {
set sqlite_like_count 0
queryplan {
SELECT x FROM t1 WHERE +x LIKE 'abc%' ORDER BY 1
}
} {abc abcd nosort {} i1}
do_test like-4.4 {
set sqlite_like_count
} 12
do_test like-4.5 {
set sqlite_like_count 0
queryplan {
SELECT x FROM t1 WHERE x LIKE ('ab' || 'c%') ORDER BY 1
}
} {abc abcd nosort {} i1}
do_test like-4.6 {
set sqlite_like_count
} 12
finish_test