1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-12-07 20:22:20 +03:00

Fix a problem with estimating the number of rows visited by a query that uses a multi-column IN(SELECT...) constraint.

FossilOrigin-Name: 3c2f908f5b7312570cfa74afcf4252a857cb5237
This commit is contained in:
dan
2016-08-03 18:00:49 +00:00
parent 2c628ea9d9
commit 3d1fb1dd75
4 changed files with 48 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
C Fix\sanother\sproblem\sinvolving\svector\srange\sconstraints\sand\smixed\sASC/DESC\sindexes.
D 2016-08-03T16:39:04.109
C Fix\sa\sproblem\swith\sestimating\sthe\snumber\sof\srows\svisited\sby\sa\squery\sthat\suses\sa\smulti-column\sIN(SELECT...)\sconstraint.
D 2016-08-03T18:00:49.612
F Makefile.in 6c20d44f72d4564f11652b26291a214c8367e5db
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc 3340e479e5221f06c3d61726f8f7efff885e4233
@@ -463,7 +463,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
F src/wal.c 02eeecc265f6ffd0597378f5d8ae9070b62a406a
F src/wal.h 6dd221ed384afdc204bc61e25c23ef7fd5a511f2
F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354
F src/where.c 8bd54861755e2ca54bc36b0dbc655834f363c5ec
F src/where.c 0a0b8af3920f88467d93019acdf570c4f4192f26
F src/whereInt.h 14dd243e13b81cbb0a66063d38b70f93a7d6e613
F src/wherecode.c c2392fa30bcb0c555a8ae402d646b357ca428ad6
F src/whereexpr.c 4a8cefc7c122132ac9f3ed125c61629a0e3de094
@@ -1021,7 +1021,7 @@ F test/rowid.test 5b7509f384f4f6fae1af3c8c104c8ca299fea18d
F test/rowvalue.test 56b34d31d91340a6e922e753b798880170cc1aa7
F test/rowvalue2.test 8d5dfe75b8f4d1868a2f91f0356f20d36cba64ff
F test/rowvalue3.test dbe935260851b197dfbbbcb0ac2a15cb5f324fd4
F test/rowvalue4.test b902e053544469e06148f504962abf9afb28be65
F test/rowvalue4.test 1f0fa2d6e4485c2c35cdb997ba57f572fd9919e0
F test/rowvaluefault.test 7b16485e3f2b371f3e3d05455b8ded6d0c090244
F test/rtree.test 0c8d9dd458d6824e59683c19ab2ffa9ef946f798
F test/run-wordcount.sh 891e89c4c2d16e629cd45951d4ed899ad12afc09
@@ -1514,7 +1514,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 18af74abc8ceae47ab9fbee3e3e5bb37db8fcba5
R 411ee4bf09cf9ee92d07e741a8c6b68c
P 1559f4c43473e107f7196eea3ee91c53ede22999
R f540153e91f079ff5413a490814ad157
U dan
Z eb44e2dff5400ed92495955ac9fc17ab
Z 1ca41c3e8d4f391ec12438826156b785

View File

@@ -1 +1 @@
1559f4c43473e107f7196eea3ee91c53ede22999
3c2f908f5b7312570cfa74afcf4252a857cb5237

View File

@@ -2376,14 +2376,23 @@ static int whereLoopAddBtreeIndex(
pNew->wsFlags |= WHERE_COLUMN_IN;
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
/* "x IN (SELECT ...)": TUNING: the SELECT returns 25 rows */
int i;
nIn = 46; assert( 46==sqlite3LogEst(25) );
/* The expression may actually be of the form (x, y) IN (SELECT...).
** In this case there is a separate term for each of (x) and (y).
** However, the nIn multiplier should only be applied once, not once
** for each such term. The following loop checks that pTerm is the
** first such term in use, and sets nIn back to 0 if it is not. */
for(i=0; i<pNew->nLTerm-1; i++){
if( pNew->aLTerm[i]->pExpr==pExpr ) nIn = 0;
}
}else if( ALWAYS(pExpr->x.pList && pExpr->x.pList->nExpr) ){
/* "x IN (value, value, ...)" */
nIn = sqlite3LogEst(pExpr->x.pList->nExpr);
assert( nIn>0 ); /* RHS always has 2 or more terms... The parser
** changes "x IN (?)" into "x=?". */
}
assert( nIn>0 ); /* RHS always has 2 or more terms... The parser
** changes "x IN (?)" into "x=?". */
}else if( eOp & (WO_EQ|WO_IS) ){
int iCol = pProbe->aiColumn[saved_nEq];
pNew->wsFlags |= WHERE_COLUMN_EQ;

View File

@@ -212,5 +212,33 @@ ifcapable stat4 {
}
}
#------------------------------------------------------------------------
do_execsql_test 5.0 {
CREATE TABLE d1(x, y);
CREATE TABLE d2(a, b, c);
CREATE INDEX d2ab ON d2(a, b);
CREATE INDEX d2c ON d2(c);
WITH i(i) AS (
VALUES(1) UNION ALL SELECT i+1 FROM i WHERE i<1000
)
INSERT INTO d2 SELECT i/3, i%3, i/3 FROM i;
ANALYZE;
}
do_eqp_test 5.1 {
SELECT * FROM d2 WHERE
(a, b) IN (SELECT x, y FROM d1) AND
(c) IN (SELECT y FROM d1)
} {
0 0 0 {SEARCH TABLE d2 USING INDEX d2ab (a=? AND b=?)}
0 0 0 {EXECUTE LIST SUBQUERY 1}
1 0 0 {SCAN TABLE d1}
0 0 0 {EXECUTE LIST SUBQUERY 2}
2 0 0 {SCAN TABLE d1}
}
finish_test