In cases where stat4 data is available but cannot be used because the rhs of a range constraint is too complex a expression, fall back to using the default estimates for number of rows scanned.
FossilOrigin-Name: e06dc6f0c35f87c44292c71677111b74f073a5c4
This commit is contained in:
parent
c137807a87
commit
f741e0491e
16
manifest
16
manifest
@ -1,5 +1,5 @@
|
||||
C Remove\sthe\spager_lookup()\sfunction\ssince\sit\sis\sredundant\swith\s\nsqlite3PagerLookup().
|
||||
D 2014-08-25T11:33:41.726
|
||||
C In\scases\swhere\sstat4\sdata\sis\savailable\sbut\scannot\sbe\sused\sbecause\sthe\srhs\sof\sa\srange\sconstraint\sis\stoo\scomplex\sa\sexpression,\sfall\sback\sto\susing\sthe\sdefault\sestimates\sfor\snumber\sof\srows\sscanned.
|
||||
D 2014-08-25T18:29:38.998
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
@ -297,7 +297,7 @@ F src/vtab.c 019dbfd0406a7447c990e1f7bd1dfcdb8895697f
|
||||
F src/wal.c 264df50a1b33124130b23180ded2e2c5663c652a
|
||||
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
|
||||
F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45
|
||||
F src/where.c 4c499d185827a492643cf017ae5e3aa0523f9f18
|
||||
F src/where.c 4e2770a1914b8ce30f3e44ad954b720eca3b5efd
|
||||
F src/whereInt.h 923820bee9726033a501a08d2fc69b9c1ee4feb3
|
||||
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
|
||||
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
|
||||
@ -317,7 +317,7 @@ F test/analyze5.test 765c4e284aa69ca172772aa940946f55629bc8c4
|
||||
F test/analyze6.test f1c552ce39cca4ec922a7e4e0e5d0203d6b3281f
|
||||
F test/analyze7.test bb1409afc9e8629e414387ef048b8e0e3e0bdc4f
|
||||
F test/analyze8.test 093d15c1c888eed5034304a98c992f7360130b88
|
||||
F test/analyze9.test 3ef1b471247308e710a794b6e50a6ab536c5604b
|
||||
F test/analyze9.test 72795c8113604b5dcd47a1498a61d6d7fb5d041a
|
||||
F test/analyzeA.test 1a5c40079894847976d983ca39c707aaa44b6944
|
||||
F test/analyzeB.test 8bf35ee0a548aea831bf56762cb8e7fdb1db083d
|
||||
F test/analyzeC.test 555a6cc388b9818b6eda6df816f01ce0a75d3a93
|
||||
@ -1188,7 +1188,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
|
||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
|
||||
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
||||
P 3ca5846da7da5e08192a4c96288197be3b7ab6f7
|
||||
R e183e353a27fb2d0c63a06eeb0b66e97
|
||||
U drh
|
||||
Z 12acde8fd951a315f106f1112e06c5c6
|
||||
P 54164ce47cfc3ad5dd8797114e4ba78811f23bef
|
||||
R 2f8cc3122e94f945065c591b14dad548
|
||||
U dan
|
||||
Z ef14939a1b480c479e36ded151638132
|
||||
|
@ -1 +1 @@
|
||||
54164ce47cfc3ad5dd8797114e4ba78811f23bef
|
||||
e06dc6f0c35f87c44292c71677111b74f073a5c4
|
@ -2220,6 +2220,7 @@ static int whereRangeScanEst(
|
||||
iNew = a[0] + ((pLower->eOperator & WO_GT) ? a[1] : 0);
|
||||
if( iNew>iLower ) iLower = iNew;
|
||||
nOut--;
|
||||
pLower = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2235,6 +2236,7 @@ static int whereRangeScanEst(
|
||||
iNew = a[0] + ((pUpper->eOperator & WO_LE) ? a[1] : 0);
|
||||
if( iNew<iUpper ) iUpper = iNew;
|
||||
nOut--;
|
||||
pUpper = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2248,10 +2250,8 @@ static int whereRangeScanEst(
|
||||
if( nNew<nOut ){
|
||||
nOut = nNew;
|
||||
}
|
||||
pLoop->nOut = (LogEst)nOut;
|
||||
WHERETRACE(0x10, ("range scan regions: %u..%u est=%d\n",
|
||||
(u32)iLower, (u32)iUpper, nOut));
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}else{
|
||||
int bDone = 0;
|
||||
@ -2262,8 +2262,8 @@ static int whereRangeScanEst(
|
||||
#else
|
||||
UNUSED_PARAMETER(pParse);
|
||||
UNUSED_PARAMETER(pBuilder);
|
||||
#endif
|
||||
assert( pLower || pUpper );
|
||||
#endif
|
||||
assert( pUpper==0 || (pUpper->wtFlags & TERM_VNULL)==0 );
|
||||
nNew = whereRangeAdjust(pLower, nOut);
|
||||
nNew = whereRangeAdjust(pUpper, nNew);
|
||||
|
@ -1088,4 +1088,50 @@ foreach {tn where eqp} {
|
||||
do_eqp_test 24.$tn "SeLeCt * FROM t5 WHERE $where" $eqp
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test that if stat4 data is available but cannot be used because the
|
||||
# rhs of a range constraint is a complex expression, the default estimates
|
||||
# are used instead.
|
||||
ifcapable stat4&&cte {
|
||||
do_execsql_test 25.1 {
|
||||
CREATE TABLE t6(a, b);
|
||||
WITH ints(i,j) AS (
|
||||
SELECT 1,1 UNION ALL SELECT i+1,j+1 FROM ints WHERE i<100
|
||||
) INSERT INTO t6 SELECT * FROM ints;
|
||||
CREATE INDEX aa ON t6(a);
|
||||
CREATE INDEX bb ON t6(b);
|
||||
ANALYZE;
|
||||
}
|
||||
|
||||
# Term (b<?) is estimated at 25%. Better than (a<30) but not as
|
||||
# good as (a<20).
|
||||
do_eqp_test 25.2.1 { SELECT * FROM t6 WHERE a<30 AND b<? } {
|
||||
0 0 0 {SEARCH TABLE t6 USING INDEX bb (b<?)}
|
||||
}
|
||||
do_eqp_test 25.2.2 { SELECT * FROM t6 WHERE a<20 AND b<? } {
|
||||
0 0 0 {SEARCH TABLE t6 USING INDEX aa (a<?)}
|
||||
}
|
||||
|
||||
# Term (b BETWEEN ? AND ?) is estimated at 1/64.
|
||||
do_eqp_test 25.3.1 {
|
||||
SELECT * FROM t6 WHERE a BETWEEN 5 AND 10 AND b BETWEEN ? AND ?
|
||||
} {
|
||||
0 0 0 {SEARCH TABLE t6 USING INDEX bb (b>? AND b<?)}
|
||||
}
|
||||
|
||||
# Term (b BETWEEN ? AND 60) is estimated to return roughly 15 rows -
|
||||
# 60 from (b<=60) multiplied by 0.25 for the b>=? term. Better than
|
||||
# (a<20) but not as good as (a<10).
|
||||
do_eqp_test 25.4.1 {
|
||||
SELECT * FROM t6 WHERE a < 10 AND (b BETWEEN ? AND 60)
|
||||
} {
|
||||
0 0 0 {SEARCH TABLE t6 USING INDEX aa (a<?)}
|
||||
}
|
||||
do_eqp_test 25.4.2 {
|
||||
SELECT * FROM t6 WHERE a < 20 AND (b BETWEEN ? AND 60)
|
||||
} {
|
||||
0 0 0 {SEARCH TABLE t6 USING INDEX bb (b>? AND b<?)}
|
||||
}
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
Loading…
Reference in New Issue
Block a user