Increase test coverage of where.c. Make sure OR-optimization works on

UPDATE and DELETE in addition to SELECT.  (Bug found by coverage tests.) (CVS 6139)

FossilOrigin-Name: 4b2c08e8984befb12fa2173ca89d9f54cf764d22
This commit is contained in:
drh 2009-01-08 03:11:19 +00:00
parent 7c2fbdeba2
commit 171256c45c
5 changed files with 248 additions and 22 deletions

View File

@ -1,5 +1,5 @@
C Add\snew\stest\scases\sto\sincrease\scoverage\sof\swhere.c.\s(CVS\s6138)
D 2009-01-07T20:58:57
C Increase\stest\scoverage\sof\swhere.c.\s\sMake\ssure\sOR-optimization\sworks\son\nUPDATE\sand\sDELETE\sin\saddition\sto\sSELECT.\s\s(Bug\sfound\sby\scoverage\stests.)\s(CVS\s6139)
D 2009-01-08T03:11:19
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 05461a9b5803d5ad10c79f989801e9fd2cc3e592
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -207,7 +207,7 @@ F src/vdbeblob.c b0dcebfafedcf9c0addc7901ad98f6f986c08935
F src/vdbemem.c 19f94b504d3da44b31aef200fa6c8e07862de2e8
F src/vtab.c e39e011d7443a8d574b1b9cde207a35522e6df43
F src/walker.c 488c2660e13224ff70c0c82761118efb547f8f0d
F src/where.c 92ef9d964b06ad2f6cba1ee4d19233ac229b2cb3
F src/where.c c67797ea657ed2ff68f46ba5da393812d7ad72e3
F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
F test/alias.test 597662c5d777a122f9a3df0047ea5c5bd383a911
@ -448,7 +448,7 @@ F test/mallocG.test 4584d0d8ddb8009f16ca0c8bab1fa37f6358efa2
F test/mallocH.test 79b65aed612c9b3ed2dcdaa727c85895fd1bfbdb
F test/mallocI.test 6e24fe6444bd2999ccc81f984977b44c0d6e5591
F test/mallocJ.test 44dfbbaca731cb933818ad300b4566265d652609
F test/mallocK.test c2404dc5f33ba1c3d0adffa1d9686a5b0e9b000b
F test/mallocK.test d3587f6215d34968d88ac8d145ff3d3ea20d9fe5
F test/malloc_common.tcl 984baeb6c6b185e798827d1187d426acc2bc4962
F test/manydb.test b3d3bc4c25657e7f68d157f031eb4db7b3df0d3c
F test/memdb.test a67c85a29d3187ac81d3628fcf9417d8a1be9ecb
@ -663,7 +663,7 @@ F test/where6.test 42c4373595f4409d9c6a9987b4a60000ad664faf
F test/where7.test 88eb7c53bdbd900cfd130e8f40bb3036bfab031d
F test/where8.test 1b9152a086408ee789166d0a954abc597372f868
F test/where8m.test c1010d61826412ff66abd29bfb32e5d6b37d965c
F test/where9.test 57c444e957c7c5065e9110e071e182e5b3ce8edc
F test/where9.test 45c2984ccb3022f09892c420806d827431c284c3
F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31
F test/zeroblob.test 792124852ec61458a2eb527b5091791215e0be95
F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b
@ -694,7 +694,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P fe90e9116b6e1e25cf3119d2777a8e9c135153ce
R 8adc87d95beb7782c7b1575af0e0d7a6
P 2e1ab51f05447f9c1f291636b53b1ec584003841
R 06029945ac0b9c710c414eee7029de66
U drh
Z 3fd090ae0444fbaab790074cb8a7ba0e
Z 504800df346d734b8d5c389a111de334

View File

@ -1 +1 @@
2e1ab51f05447f9c1f291636b53b1ec584003841
4b2c08e8984befb12fa2173ca89d9f54cf764d22

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.359 2009/01/07 20:58:57 drh Exp $
** $Id: where.c,v 1.360 2009/01/08 03:11:19 drh Exp $
*/
#include "sqliteInt.h"
@ -2719,6 +2719,8 @@ static Bitmask codeOneLoopStart(
/* sqlite3ReleaseTempReg(pParse, regOrRowset); // Preserve the RowSet */
pLevel->op = OP_Goto;
pLevel->p2 = addrCont;
}else{
pLevel->op = OP_Noop;
}
disableTerm(pLevel, pTerm);
}else
@ -3128,15 +3130,16 @@ WhereInfo *sqlite3WhereBegin(
** Return an error.
*/
pIdx = pTabList->a[bestJ].pIndex;
assert( !pIdx
|| (bestPlan.plan.wsFlags&WHERE_INDEXED)==0
|| pIdx==bestPlan.plan.u.pIdx );
if( pIdx
&& ((bestPlan.plan.wsFlags & WHERE_INDEXED)==0
|| bestPlan.plan.u.pIdx!=pIdx)
){
sqlite3ErrorMsg(pParse, "cannot use index: %s", pIdx->zName);
goto whereBeginError;
if( pIdx ){
if( (bestPlan.plan.wsFlags & WHERE_INDEXED)==0 ){
sqlite3ErrorMsg(pParse, "cannot use index: %s", pIdx->zName);
goto whereBeginError;
}else{
/* If an INDEXED BY clause is used, the bestIndex() function is
** guaranteed to find the index specified in the INDEXED BY clause
** if it find an index at all. */
assert( bestPlan.plan.u.pIdx==pIdx );
}
}
}
WHERETRACE(("*** Optimizer Finished ***\n"));

View File

@ -11,7 +11,7 @@
#
# This test script checks malloc failures in WHERE clause analysis.
#
# $Id: mallocK.test,v 1.1 2009/01/07 20:58:57 drh Exp $
# $Id: mallocK.test,v 1.2 2009/01/08 03:11:19 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -27,7 +27,7 @@ for {set x 1} {$x<5} {incr x} {
}
}
set sql {SELECT * FROM t1 WHERE a LIKE 'abc%'}
set sql {SELECT * FROM t1 WHERE a GLOB 'xyz*'}
for {set x 1} {$x<5} {incr x} {
append sql " AND b!=$x"
do_malloc_test mallocK-2.$x -sqlbody $sql -sqlprep {

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing the multi-index OR clause optimizer.
#
# $Id: where9.test,v 1.3 2008/12/30 17:55:00 drh Exp $
# $Id: where9.test,v 1.4 2009/01/08 03:11:19 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -452,4 +452,227 @@ ifcapable explain {
} {0 1}
}
############################################################################
# Make sure OR-clauses work correctly on UPDATE and DELETE statements.
do_test where9-6.2.1 {
db eval {SELECT count(*) FROM t1 UNION ALL SELECT a FROM t1 WHERE a>=85}
} {99 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99}
do_test where9-6.2.2 { ;# Deletes entries 90 91 92 96 97 99
count_steps {
BEGIN;
DELETE FROM t1
WHERE b IS NULL
OR c IS NULL
OR d IS NULL
}
} {scan 0 sort 0}
do_test where9-6.2.3 {
db eval {
SELECT count(*) FROM t1 UNION ALL
SELECT a FROM t1 WHERE a>=85;
ROLLBACK;
}
} {93 85 86 87 88 89 93 94 95 98}
do_test where9-6.2.4 { ;# Deletes entries 90 91 92 96 97 99
count_steps {
BEGIN;
DELETE FROM t1
WHERE +b IS NULL
OR c IS NULL
OR d IS NULL
}
} {scan 98 sort 0}
do_test where9-6.2.5 {
db eval {
SELECT count(*) FROM t1 UNION ALL
SELECT a FROM t1 WHERE a>=85;
ROLLBACK;
}
} {93 85 86 87 88 89 93 94 95 98}
do_test where9-6.2.6 {
count_steps {
BEGIN;
UPDATE t1 SET a=a+100
WHERE (b IS NULL
OR c IS NULL
OR d IS NULL)
AND a!=92
AND a!=97
}
} {scan 0 sort 0} ;# Add 100 to entries 90 91 96 99
do_test where9-6.2.7 {
db eval {
SELECT count(*) FROM t1 UNION ALL
SELECT a FROM t1 WHERE a>=85;
ROLLBACK
}
} {99 85 86 87 88 89 92 93 94 95 97 98 190 191 196 199}
do_test where9-6.2.8 { ;# Deletes entries 90 91 92 97 99
count_steps {
BEGIN;
DELETE FROM t1
WHERE (b IS NULL
OR c IS NULL
OR d IS NULL)
AND a!=96
}
} {scan 0 sort 0}
do_test where9-6.2.9 {
db eval {
SELECT count(*) FROM t1 UNION ALL SELECT a FROM t1 WHERE a>=85;
ROLLBACK;
}
} {94 85 86 87 88 89 93 94 95 96 98}
do_test where9-6.3.1 {
count_steps {
BEGIN;
DELETE FROM t1
WHERE (b IS NULL AND c NOT NULL AND d NOT NULL)
OR (b NOT NULL AND c IS NULL AND d NOT NULL)
OR (b NOT NULL AND c NOT NULL AND d IS NULL)
}
} {scan 0 sort 0} ;# DELETEs rows 90 91 92 97
do_test where9-6.3.2 {
db eval {
SELECT count(*) FROM t1 UNION ALL
SELECT a FROM t1 WHERE a BETWEEN 85 AND 100;
ROLLBACK;
}
} {95 85 86 87 88 89 93 94 95 96 98 99}
do_test where9-6.3.3 {
count_steps {
BEGIN;
UPDATE t1 SET a=a+100
WHERE (b IS NULL AND c NOT NULL AND d NOT NULL)
OR (b NOT NULL AND c IS NULL AND d NOT NULL)
OR (b NOT NULL AND c NOT NULL AND d IS NULL)
}
} {scan 0 sort 0} ;# Add 100 to rowids 90 91 92 97
do_test where9-6.3.4 {
db eval {
SELECT count(*) FROM t1 UNION ALL
SELECT a FROM t1 WHERE a BETWEEN 85 AND 200;
ROLLBACK;
}
} {99 85 86 87 88 89 93 94 95 96 98 99 190 191 192 197}
do_test where9-6.3.5 {
count_steps {
BEGIN;
DELETE FROM t1
WHERE (+b IS NULL AND c NOT NULL AND d NOT NULL)
OR (b NOT NULL AND c IS NULL AND d NOT NULL)
OR (b NOT NULL AND c NOT NULL AND d IS NULL)
}
} {scan 98 sort 0} ;# DELETEs rows 90 91 92 97
do_test where9-6.3.6 {
db eval {
SELECT count(*) FROM t1 UNION ALL
SELECT a FROM t1 WHERE a BETWEEN 85 AND 100;
ROLLBACK;
}
} {95 85 86 87 88 89 93 94 95 96 98 99}
do_test where9-6.3.7 {
count_steps {
BEGIN;
UPDATE t1 SET a=a+100
WHERE (b IS NULL AND c NOT NULL AND d NOT NULL)
OR (b NOT NULL AND +c IS NULL AND d NOT NULL)
OR (b NOT NULL AND c NOT NULL AND d IS NULL)
}
} {scan 98 sort 0} ;# Add 100 to rowids 90 91 92 97
do_test where9-6.3.8 {
db eval {
SELECT count(*) FROM t1 UNION ALL
SELECT a FROM t1 WHERE a BETWEEN 85 AND 100;
ROLLBACK;
}
} {99 85 86 87 88 89 93 94 95 96 98 99}
do_test where9-6.4.1 {
count_steps {
BEGIN;
DELETE FROM t1
WHERE (b>=950 AND b<=1010) OR (b IS NULL AND c NOT NULL)
}
} {scan 0 sort 0} ;# DELETE rows 87 88 89 90 91
do_test where9-6.4.2 {
db eval {
SELECT count(*) FROM t1 UNION ALL
SELECT a FROM t1 WHERE a BETWEEN 85 AND 100;
ROLLBACK;
}
} {94 85 86 92 93 94 95 96 97 98 99}
do_test where9-6.4.3 {
count_steps {
BEGIN;
UPDATE t1 SET a=a+100
WHERE (b>=950 AND b<=1010) OR (b IS NULL AND c NOT NULL)
}
} {scan 0 sort 0} ;# Add 100 to rowids 87 88 89 90 91
do_test where9-6.4.4 {
db eval {
SELECT count(*) FROM t1 UNION ALL
SELECT a FROM t1 WHERE a BETWEEN 85 AND 100;
ROLLBACK;
}
} {99 85 86 92 93 94 95 96 97 98 99}
do_test where9-6.5.1 {
count_steps {
BEGIN;
DELETE FROM t1
WHERE a=83
OR b=913
OR c=28028
OR (d>=82 AND d<83)
OR (e>2802 AND e<2803)
OR f='fghijklmn'
OR g='hgfedcb'
}
} {scan 0 sort 0} ;# DELETE rows 5 31 57 82 83 84 85 86 87
do_test where9-6.5.2 {
db eval {
SELECT count(*) FROM t1 UNION ALL
SELECT a FROM t1 WHERE a IN (5,31,57,82,83,84,85,86,87);
ROLLBACK;
}
} {90}
do_test where9-6.5.3 {
count_steps {
BEGIN;
UPDATE t1 SET a=a+100
WHERE a=83
OR b=913
OR c=28028
OR (d>=82 AND d<83)
OR (e>2802 AND e<2803)
OR f='fghijklmn'
OR g='hgfedcb'
}
} {scan 0 sort 0} ;# Add 100 to rowids 5 31 57 82 83 84 85 86 87
do_test where9-6.5.4 {
db eval {
SELECT count(*) FROM t1 UNION ALL
SELECT a FROM t1 WHERE a%100 IN (5,31,57,82,83,84,85,86,87);
ROLLBACK;
}
} {99 105 131 157 182 183 184 185 186 187}
finish_test