Do not use a partial index as a table scan in an IN operator.

Fix for ticket [1d958d90596593a77420e59].

FossilOrigin-Name: 15bc915dd7ae25bfdfbe357c3792db3639799e4d121c6b5b24297af2d6d7129e
This commit is contained in:
drh 2018-12-08 20:30:31 +00:00
parent 83da91b7bd
commit d4a4a36171
4 changed files with 27 additions and 9 deletions

View File

@ -1,5 +1,5 @@
C Remove\sa\sline\sof\scode\sfrom\sVACUUM\sthat\sis\sno\slonger\sneeded,\sdue\sto\sthe\nchange\sthat\sallows\sATTACH\sto\srun\swithin\sa\stransaction.
D 2018-12-07T20:26:29.949
C Do\snot\suse\sa\spartial\sindex\sas\sa\stable\sscan\sin\san\sIN\soperator.\nFix\sfor\sticket\s[1d958d90596593a77420e59].
D 2018-12-08T20:30:31.225
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F Makefile.in 68d0ba0f0b533d5bc84c78c13a6ce84ee81183a67014caa47a969e67f028fa1c
@ -459,7 +459,7 @@ F src/date.c ebe1dc7c8a347117bb02570f1a931c62dd78f4a2b1b516f4837d45b7d6426957
F src/dbpage.c 135eb3b5e74f9ef74bde5cec2571192c90c86984fa534c88bf4a055076fa19b7
F src/dbstat.c 3c8bd4e77f0244fd2bd7cc90acf116ad2f8e82d70e536637f35ac2bc99b726f9
F src/delete.c f7938125847e8ef485448db5fbad29acb2991381a02887dd854c1617315ab9fb
F src/expr.c b83e2056086e364293ce741509d885d1646a32d62727fe3169b23231c7e4f62f
F src/expr.c 494a778ee193d99127c72adefcec3e8e133f482acf5f1c267652a8f51029e9ae
F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
F src/fkey.c 972a4ba14296bef2303a0abbad1e3d82bc3c61f9e6ce4e8e9528bdee68748812
F src/func.c 7c288b4ce309b5a8b8473514b88e1f8e69a80134509a8c0db8e39c858e367e7f
@ -1015,7 +1015,7 @@ F test/index2.test f835d5e13ca163bd78c4459ca15fd2e4ed487407
F test/index3.test 51685f39345462b84fcf77eb8537af847fdf438cc96b05c45d6aaca4e473ade0
F test/index4.test ab92e736d5946840236cd61ac3191f91a7856bf6
F test/index5.test 8621491915800ec274609e42e02a97d67e9b13e7
F test/index6.test d07ea75b8c21f125c6f325522e8df8c05c91e9251ec923a31d0582b2ba4a617d
F test/index6.test 7cb66c4e54da73f51e874dcf4a761411c0f8f3f5a4fdf7022d8a505b0194296b
F test/index7.test 72b59b8ddc5c13f4962886b4011eb9975014317d17ef36c6297921362fb7dd98
F test/index8.test bc2e3db70e8e62459aaa1bd7e4a9b39664f8f9d7
F test/index9.test 0aa3e509dddf81f93380396e40e9bb386904c1054924ba8fa9bcdfe85a8e7721
@ -1782,7 +1782,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 0d8e150434bbd179696f1ffe71d1e06cb3d43e6468496c7e481fca8486387bad
R 4426cbb4a0e989d65734a42a486b3458
P a92c398fc5df142ff1459c1be4a6832f2219bc7fabe5789535be3bbd41a4269b
R b6f349da580def7412aedbdbd15fbe9b
U drh
Z 888d594bf1edeab12c4e75c4f15da299
Z 66d01b11a28cdf2981ee67c4d1459164

View File

@ -1 +1 @@
a92c398fc5df142ff1459c1be4a6832f2219bc7fabe5789535be3bbd41a4269b
15bc915dd7ae25bfdfbe357c3792db3639799e4d121c6b5b24297af2d6d7129e

View File

@ -2443,6 +2443,7 @@ int sqlite3FindInIndex(
Bitmask colUsed; /* Columns of the index used */
Bitmask mCol; /* Mask for the current column */
if( pIdx->nColumn<nExpr ) continue;
if( pIdx->pPartIdxWhere!=0 ) continue;
/* Maximum nColumn is BMS-2, not BMS-1, so that we can compute
** BITMASK(nExpr) without overflowing */
testcase( pIdx->nColumn==BMS-2 );

View File

@ -389,6 +389,23 @@ do_execsql_test index6-11.1 {
do_execsql_test index6-11.2 {
EXPLAIN QUERY PLAN SELECT a FROM t11 WHERE b<>99 AND c<>98;
} {/USING INDEX t11x/}
# 2018-12-08
# Ticket https://www.sqlite.org/src/info/1d958d90596593a7
# NOT IN operator fails when using a partial index.
#
do_execsql_test index6-12.1 {
DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS t2;
CREATE TABLE t1(a,b);
INSERT INTO t1 VALUES(1,1);
INSERT INTO t1 VALUES(2,2);
CREATE TABLE t2(x);
INSERT INTO t2 VALUES(1);
INSERT INTO t2 VALUES(2);
SELECT 'one', * FROM t2 WHERE x NOT IN (SELECT a FROM t1);
CREATE INDEX t1a ON t1(a) WHERE b=1;
SELECT 'two', * FROM t2 WHERE x NOT IN (SELECT a FROM t1);
} {}
finish_test