Multi-index OR optimizer response to ORDER BY rowid.

But fix in sqlite3_stmt_status(): report a full table scan
when "ORDER BY rowid" is used without constraints. (CVS 6069)

FossilOrigin-Name: 3464d369d3b6899ec726cf5b42b68b1dac2ba982
This commit is contained in:
drh 2008-12-28 20:47:02 +00:00
parent 294352578e
commit ca8c4667a8
4 changed files with 47 additions and 33 deletions

View File

@ -1,5 +1,5 @@
C Optimize\sWHERE\sclauses\sthat\sconstain\sAND,\sBETWEEN,\sand\sLIKE\sterms\sas\soperands\nof\san\sOR.\s(CVS\s6068)
D 2008-12-28T18:35:09
C Multi-index\sOR\soptimizer\sresponse\sto\sORDER\sBY\srowid.\nBut\sfix\sin\ssqlite3_stmt_status():\sreport\sa\sfull\stable\sscan\nwhen\s"ORDER\sBY\srowid"\sis\sused\swithout\sconstraints.\s(CVS\s6069)
D 2008-12-28T20:47:03
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 77635d0909c2067cee03889a1e04ce910d8fb809
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -207,7 +207,7 @@ F src/vdbeblob.c b0dcebfafedcf9c0addc7901ad98f6f986c08935
F src/vdbemem.c f9c859ac17e2e05a0f249868ce4f191f69edd31d
F src/vtab.c e39e011d7443a8d574b1b9cde207a35522e6df43
F src/walker.c 488c2660e13224ff70c0c82761118efb547f8f0d
F src/where.c 4050b918a379e23d5b645d888b91dba2e7c469a9
F src/where.c 29c57ed5b081164d77782a1224e74e0b06be2790
F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
F test/alias.test 597662c5d777a122f9a3df0047ea5c5bd383a911
@ -655,7 +655,7 @@ F test/where3.test 97d3936e6a443b968f1a61cdcc0f673252000e94
F test/where4.test e9b9e2f2f98f00379e6031db6a6fca29bae782a2
F test/where5.test fdf66f96d29a064b63eb543e28da4dfdccd81ad2
F test/where6.test 42c4373595f4409d9c6a9987b4a60000ad664faf
F test/where7.test c27e4865d69b35dc21b4cbff097cf02e9cdc9950
F test/where7.test 3ed6a8cb7d3e1e8c289e5e21f460c7a4d3f129e2
F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31
F test/zeroblob.test 792124852ec61458a2eb527b5091791215e0be95
F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b
@ -686,7 +686,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P fa95f843e179a38f663978d675607c4c3037928d
R 7f2475a8de47b6500bdb0400363621d0
P 67cf24b30e087796cfb0fccf47328e72ade5ecdc
R 4dc373b9ad303968012bfa905d6a842d
U drh
Z 2bf13b04bd3fbd90db56a109bb7f3eb1
Z 29937d7ee562a44850eb3aacdfc0a0a0

View File

@ -1 +1 @@
67cf24b30e087796cfb0fccf47328e72ade5ecdc
3464d369d3b6899ec726cf5b42b68b1dac2ba982

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.346 2008/12/28 18:35:09 drh Exp $
** $Id: where.c,v 1.347 2008/12/28 20:47:03 drh Exp $
*/
#include "sqliteInt.h"
@ -1877,6 +1877,12 @@ static void bestIndex(
pCost->nRow = nRow;
pCost->plan.wsFlags = WHERE_MULTI_OR;
pCost->plan.u.pTerm = pTerm;
if( pOrderBy!=0
&& sortableByRowid(iCur, pOrderBy, pWC->pMaskSet, &rev)
&& !rev
){
pCost->plan.wsFlags = WHERE_ORDERBY|WHERE_MULTI_OR;
}
}
}
}
@ -2426,6 +2432,7 @@ static Bitmask codeOneLoopStart(
pLevel->op = bRev ? OP_Prev : OP_Next;
pLevel->p1 = iCur;
pLevel->p2 = start;
pLevel->p5 = (pStart==0 && pEnd==0) ?1:0;
codeRowSetEarly = regRowSet>=0 ? whereRowReadyForOutput(pWC) : 0;
if( codeRowSetEarly || testOp!=OP_Noop ){
int r1 = sqlite3GetTempReg(pParse);

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: where7.test,v 1.2 2008/12/28 18:35:09 drh Exp $
# $Id: where7.test,v 1.3 2008/12/28 20:47:03 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -26,7 +26,7 @@ ifcapable !or_opt {
#
proc count_steps {sql} {
set r [db eval $sql]
lappend r scan [db status step]
lappend r scan [db status step] sort [db status sort]
}
# Build some test data
@ -46,60 +46,67 @@ do_test where7-1.1 {
} {1 2 3 4 2 3 4 5 3 4 6 8 4 5 10 15 5 10 100 1000}
do_test where7-1.2 {
count_steps {
SELECT a FROM t1 WHERE b=3 OR c=6
SELECT a FROM t1 WHERE b=3 OR c=6 ORDER BY a
}
} {2 3 scan 0}
} {2 3 scan 0 sort 0}
do_test where7-1.3 {
count_steps {
SELECT a FROM t1 WHERE b=3 OR +c=6
SELECT a FROM t1 WHERE b=3 OR +c=6 ORDER BY a
}
} {2 3 scan 4}
} {2 3 scan 4 sort 0}
do_test where7-1.4 {
count_steps {
SELECT a FROM t1 WHERE +b=3 OR c=6
SELECT a FROM t1 WHERE +b=3 OR c=6 ORDER BY 1
}
} {2 3 scan 4}
} {2 3 scan 4 sort 0}
do_test where7-1.5 {
count_steps {
SELECT a FROM t1 WHERE 3=b OR c=6
SELECT a FROM t1 WHERE 3=b OR c=6 ORDER BY rowid
}
} {2 3 scan 0}
} {2 3 scan 0 sort 0}
do_test where7-1.6 {
count_steps {
SELECT a FROM t1 WHERE (3=b OR c=6) AND +a>0
SELECT a FROM t1 WHERE (3=b OR c=6) AND +a>0 ORDER BY a
}
} {2 3 scan 0}
} {2 3 scan 0 sort 0}
do_test where7-1.7 {
count_steps {
SELECT a FROM t1 WHERE (b=3 OR c>10)
SELECT a FROM t1 WHERE (b=3 OR c>10) ORDER BY a
}
} {2 5 scan 0}
} {2 5 scan 0 sort 0}
do_test where7-1.8 {
count_steps {
SELECT a FROM t1 WHERE (b=3 OR c>=10)
SELECT a FROM t1 WHERE (b=3 OR c>=10) ORDER BY a
}
} {2 4 5 scan 0}
} {2 4 5 scan 0 sort 0}
do_test where7-1.9 {
count_steps {
SELECT a FROM t1 WHERE (b=3 OR c>=10 OR c=4)
SELECT a FROM t1 WHERE (b=3 OR c>=10 OR c=4) ORDER BY a
}
} {2 4 5 scan 0}
} {2 4 5 scan 0 sort 0}
do_test where7-1.10 {
count_steps {
SELECT a FROM t1 WHERE (b=3 OR c>=10 OR c=4 OR b>10)
SELECT a FROM t1 WHERE (b=3 OR c>=10 OR c=4 OR b>10) ORDER BY a
}
} {2 4 5 scan 0}
} {2 4 5 scan 0 sort 0}
do_test where7-1.11 {
count_steps {
SELECT a FROM t1 WHERE (d=5 AND b=3) OR c==100;
SELECT a FROM t1 WHERE (d=5 AND b=3) OR c==100 ORDER BY a;
}
} {2 5 scan 0}
} {2 5 scan 0 sort 0}
do_test where7-1.12 {
breakpoint
count_steps {
SELECT a FROM t1 WHERE (b BETWEEN 2 AND 4) OR c=100
SELECT a FROM t1 WHERE (b BETWEEN 2 AND 4) OR c=100 ORDER BY a
}
} {1 2 3 5 scan 0}
} {1 2 3 5 scan 0 sort 0}
do_test where7-1.13 {
breakpoint
count_steps {
SELECT a FROM t1 WHERE (b BETWEEN 0 AND 2) OR (c BETWEEN 9 AND 999)
ORDER BY a DESC
}
} {5 4 1 scan 0 sort 1}
finish_test