mirror of https://github.com/sqlite/sqlite
Increase the estimated cost of using a virtual table as the outer loop of a join when there exists an ORDER BY clause that is not satisfied by the virtual table. Fix for [775b39dd3c].
FossilOrigin-Name: 9e075e70f0e2a1ad302d17150cd58f91669a97a6
This commit is contained in:
parent
1141ae2463
commit
c26c00495f
16
manifest
16
manifest
|
@ -1,5 +1,5 @@
|
|||
C Fix\sOOM\serror\son\sANALYZE\swith\sSTAT2\senabled\swith\szero-length\sdata.\sTicket\s[cbd054fa6b].
|
||||
D 2010-03-26T01:54:33
|
||||
C Increase\sthe\sestimated\scost\sof\susing\sa\svirtual\stable\sas\sthe\souter\sloop\sof\sa\sjoin\swhen\sthere\sexists\san\sORDER\sBY\sclause\sthat\sis\snot\ssatisfied\sby\sthe\svirtual\stable.\sFix\sfor\s[775b39dd3c].
|
||||
D 2010-03-27T09:44:42
|
||||
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
|
||||
F Makefile.in 4f2f967b7e58a35bb74fb7ec8ae90e0f4ca7868b
|
||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||
|
@ -221,7 +221,7 @@ F src/vdbemem.c 2a82f455f6ca6f78b59fb312f96054c04ae0ead1
|
|||
F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2
|
||||
F src/vtab.c 606adf51cd6d4ba51a8c6dccede06a6f7b0dd72d
|
||||
F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
|
||||
F src/where.c 399ea4c090284c9d16f76d685b9b44e8b9b4442b
|
||||
F src/where.c 71ef4e89715740f7af49e6f15a3fd987e040800a
|
||||
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
|
||||
F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87
|
||||
F test/all.test 14165b3e32715b700b5f0cbf8f6e3833dda0be45
|
||||
|
@ -408,7 +408,7 @@ F test/fts3expr.test 5e745b2b6348499d9ef8d59015de3182072c564c
|
|||
F test/fts3expr2.test 18da930352e5693eaa163a3eacf96233b7290d1a
|
||||
F test/fts3malloc.test 059592c4f37ccd30138bbf8e3e5b7982cb5c8f2e
|
||||
F test/fts3near.test 2e318ee434d32babd27c167142e2b94ddbab4844
|
||||
F test/fts3query.test 154fe4b015fd61af523ee083570a134f508f5be7
|
||||
F test/fts3query.test 1acb21b58d6aa7504e990f0f589be85e9a133969
|
||||
F test/fts3rnd.test 2f5761db9dd92f6fe09d08976ac658ef521846ed
|
||||
F test/fts3snippet.test 9f9a4a7e396c5d8ce2898be65ebabc429555430f
|
||||
F test/fts4aa.test eadf85621c0a113d4c7ad3ccbf8441130e007b8f
|
||||
|
@ -794,7 +794,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
|||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||
P d37034f7fc46b83be681247fde97823736c994cc
|
||||
R f632179d00144c3248d5550420baa55a
|
||||
U shaneh
|
||||
Z 000ac439cfaa4b57f906b494905bfe51
|
||||
P c33b38b59f733494ca0bce3f59a669fe7ed76b9f
|
||||
R 1048b4f005b8cf985bff319e6cd284fa
|
||||
U dan
|
||||
Z 25a9f1889e9ba9dd674533c69390c60b
|
||||
|
|
|
@ -1 +1 @@
|
|||
c33b38b59f733494ca0bce3f59a669fe7ed76b9f
|
||||
9e075e70f0e2a1ad302d17150cd58f91669a97a6
|
14
src/where.c
14
src/where.c
|
@ -1819,6 +1819,7 @@ static void bestVirtualIndex(
|
|||
WhereTerm *pTerm;
|
||||
int i, j;
|
||||
int nOrderBy;
|
||||
double rCost;
|
||||
|
||||
/* Make sure wsFlags is initialized to some sane value. Otherwise, if the
|
||||
** malloc in allocateIndexInfo() fails and this function returns leaving
|
||||
|
@ -1905,6 +1906,15 @@ static void bestVirtualIndex(
|
|||
}
|
||||
}
|
||||
|
||||
/* If there is an ORDER BY clause, and the selected virtual table index
|
||||
** does not satisfy it, increase the cost of the scan accordingly. This
|
||||
** matches the processing for non-virtual tables in bestBtreeIndex().
|
||||
*/
|
||||
rCost = pIdxInfo->estimatedCost;
|
||||
if( pOrderBy && pIdxInfo->orderByConsumed==0 ){
|
||||
rCost += estLog(rCost)*rCost;
|
||||
}
|
||||
|
||||
/* The cost is not allowed to be larger than SQLITE_BIG_DBL (the
|
||||
** inital value of lowestCost in this loop. If it is, then the
|
||||
** (cost<lowestCost) test below will never be true.
|
||||
|
@ -1912,10 +1922,10 @@ static void bestVirtualIndex(
|
|||
** Use "(double)2" instead of "2.0" in case OMIT_FLOATING_POINT
|
||||
** is defined.
|
||||
*/
|
||||
if( (SQLITE_BIG_DBL/((double)2))<pIdxInfo->estimatedCost ){
|
||||
if( (SQLITE_BIG_DBL/((double)2))<rCost ){
|
||||
pCost->rCost = (SQLITE_BIG_DBL/((double)2));
|
||||
}else{
|
||||
pCost->rCost = pIdxInfo->estimatedCost;
|
||||
pCost->rCost = rCost;
|
||||
}
|
||||
pCost->plan.u.pVtabIdx = pIdxInfo;
|
||||
if( pIdxInfo->orderByConsumed ){
|
||||
|
|
|
@ -101,5 +101,33 @@ do_test fts3query-3.3 {
|
|||
execsql { SELECT mit(matchinfo(foobar)) FROM foobar WHERE foobar MATCH 'the' }
|
||||
} {{1 1 3 3 1}}
|
||||
|
||||
# The following tests check that ticket 775b39dd3c has been fixed.
|
||||
#
|
||||
proc eqp {sql} {
|
||||
uplevel [list execsql "EXPLAIN QUERY PLAN $sql"]
|
||||
}
|
||||
do_test fts3query-4.1 {
|
||||
execsql {
|
||||
DROP TABLE IF EXISTS t1;
|
||||
CREATE TABLE t1(number INTEGER PRIMARY KEY, date);
|
||||
CREATE INDEX i1 ON t1(date);
|
||||
CREATE VIRTUAL TABLE ft USING fts3(title);
|
||||
CREATE TABLE bt(title);
|
||||
}
|
||||
} {}
|
||||
do_test fts3query-4.2 {
|
||||
eqp "SELECT t1.number FROM t1, ft WHERE t1.number=ft.rowid ORDER BY t1.date"
|
||||
} {0 0 {TABLE t1 WITH INDEX i1 ORDER BY} 1 1 {TABLE ft VIRTUAL TABLE INDEX 1:}}
|
||||
do_test fts3query-4.3 {
|
||||
eqp "SELECT t1.number FROM ft, t1 WHERE t1.number=ft.rowid ORDER BY t1.date"
|
||||
} {0 1 {TABLE t1 WITH INDEX i1 ORDER BY} 1 0 {TABLE ft VIRTUAL TABLE INDEX 1:}}
|
||||
do_test fts3query-4.4 {
|
||||
eqp "SELECT t1.number FROM t1, bt WHERE t1.number=bt.rowid ORDER BY t1.date"
|
||||
} {0 0 {TABLE t1 WITH INDEX i1 ORDER BY} 1 1 {TABLE bt USING PRIMARY KEY}}
|
||||
do_test fts3query-4.5 {
|
||||
eqp "SELECT t1.number FROM bt, t1 WHERE t1.number=bt.rowid ORDER BY t1.date"
|
||||
} {0 1 {TABLE t1 WITH INDEX i1 ORDER BY} 1 0 {TABLE bt USING PRIMARY KEY}}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
|
|
Loading…
Reference in New Issue