Improved ORDER BY optimization for WITHOUT ROWID tables.
FossilOrigin-Name: 8f1709ff2d52d5ceca3da6a2a4e06da204d9e65a
This commit is contained in:
parent
d4ddae985b
commit
416846a362
14
manifest
14
manifest
@ -1,5 +1,5 @@
|
||||
C Disable\sthe\sOR\soptimization\sfor\sWITHOUT\sROWID\stables,\ssince\sit\srelies\son\nthe\suse\sof\srowids.
|
||||
D 2013-11-06T12:05:57.372
|
||||
C Improved\sORDER\sBY\soptimization\sfor\sWITHOUT\sROWID\stables.
|
||||
D 2013-11-06T12:56:04.047
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in 0522b53cdc1fcfc18f3a98e0246add129136c654
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
@ -292,7 +292,7 @@ F src/vtab.c 5a423b042eb1402ef77697d03d6a67378d97bc8d
|
||||
F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4
|
||||
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
|
||||
F src/walker.c e9e593d5bb798c3e67fc3893dfe7055c9e7d8d74
|
||||
F src/where.c 1df23d22ea530d384a3deb77af552a64af39334f
|
||||
F src/where.c ce16448190ba44d79749e83ffd8058cd5f104781
|
||||
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
|
||||
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
|
||||
F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6
|
||||
@ -717,7 +717,7 @@ F test/orderby1.test 9b524aff9147288da43a6d7ddfdcff47fa2303c6
|
||||
F test/orderby2.test bc11009f7cd99d96b1b11e57b199b00633eb5b04
|
||||
F test/orderby3.test 8619d06a3debdcd80a27c0fdea5c40b468854b99
|
||||
F test/orderby4.test 4d39bfbaaa3ae64d026ca2ff166353d2edca4ba4
|
||||
F test/orderby5.test 02eca502a0f97c77ce383b0dfa17e99c6a107b8d
|
||||
F test/orderby5.test 0eb82d5890c3f3d0563966560cfdc984ea69e30c
|
||||
F test/oserror.test 50417780d0e0d7cd23cf12a8277bb44024765df3
|
||||
F test/pager1.test 1acbdb14c5952a72dd43129cabdbf69aaa3ed1fa
|
||||
F test/pager2.test 67b8f40ae98112bcdba1f2b2d03ea83266418c71
|
||||
@ -1134,7 +1134,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
|
||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||
F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
|
||||
F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
|
||||
P 427612efc169c8ebe94a8b586d7abd0fcd43d0d0
|
||||
R 05a5a0a384486e31eb5a4b75f73a71ca
|
||||
P 6055dad2ba2f9256b1f2d0a9e32ca00f1b81b0cf
|
||||
R 5d33ef338e308554e8ff41606713ec29
|
||||
U drh
|
||||
Z bc0884f74e17c4194dbca32799c70173
|
||||
Z 4259ceef2368d05bf56ed248162d9e14
|
||||
|
@ -1 +1 @@
|
||||
6055dad2ba2f9256b1f2d0a9e32ca00f1b81b0cf
|
||||
8f1709ff2d52d5ceca3da6a2a4e06da204d9e65a
|
16
src/where.c
16
src/where.c
@ -5024,7 +5024,8 @@ static int wherePathSatisfiesOrderBy(
|
||||
u8 isOrderDistinct; /* All prior WhereLoops are order-distinct */
|
||||
u8 distinctColumns; /* True if the loop has UNIQUE NOT NULL columns */
|
||||
u8 isMatch; /* iColumn matches a term of the ORDER BY clause */
|
||||
u16 nKeyCol; /* Number of columns in pIndex */
|
||||
u16 nKeyCol; /* Number of key columns in pIndex */
|
||||
u16 nColumn; /* Total number of ordered columns in the index */
|
||||
u16 nOrderBy; /* Number terms in the ORDER BY clause */
|
||||
int iLoop; /* Index of WhereLoop in pPath being processed */
|
||||
int i, j; /* Loop counters */
|
||||
@ -5117,10 +5118,14 @@ static int wherePathSatisfiesOrderBy(
|
||||
if( pLoop->wsFlags & WHERE_IPK ){
|
||||
pIndex = 0;
|
||||
nKeyCol = 0;
|
||||
nColumn = 1;
|
||||
}else if( (pIndex = pLoop->u.btree.pIndex)==0 || pIndex->bUnordered ){
|
||||
return 0;
|
||||
}else{
|
||||
nKeyCol = pIndex->nKeyCol;
|
||||
nColumn = pIndex->nColumn;
|
||||
assert( nColumn==nKeyCol+1 || !HasRowid(pIndex->pTable) );
|
||||
assert( pIndex->aiColumn[nColumn-1]==(-1) || !HasRowid(pIndex->pTable));
|
||||
isOrderDistinct = pIndex->onError!=OE_None;
|
||||
}
|
||||
|
||||
@ -5129,7 +5134,7 @@ static int wherePathSatisfiesOrderBy(
|
||||
*/
|
||||
rev = revSet = 0;
|
||||
distinctColumns = 0;
|
||||
for(j=0; j<=nKeyCol; j++){
|
||||
for(j=0; j<nColumn; j++){
|
||||
u8 bOnce; /* True to run the ORDER BY search loop */
|
||||
|
||||
/* Skip over == and IS NULL terms */
|
||||
@ -5146,20 +5151,17 @@ static int wherePathSatisfiesOrderBy(
|
||||
/* Get the column number in the table (iColumn) and sort order
|
||||
** (revIdx) for the j-th column of the index.
|
||||
*/
|
||||
if( j<nKeyCol ){
|
||||
/* Normal index columns */
|
||||
if( pIndex ){
|
||||
iColumn = pIndex->aiColumn[j];
|
||||
revIdx = pIndex->aSortOrder[j];
|
||||
if( iColumn==pIndex->pTable->iPKey ) iColumn = -1;
|
||||
}else{
|
||||
/* The ROWID column at the end */
|
||||
assert( j==nKeyCol );
|
||||
iColumn = -1;
|
||||
revIdx = 0;
|
||||
}
|
||||
|
||||
/* An unconstrained column that might be NULL means that this
|
||||
** WhereLoop is not well-ordered
|
||||
** WhereLoop is not well-ordered
|
||||
*/
|
||||
if( isOrderDistinct
|
||||
&& iColumn>=0
|
||||
|
@ -94,4 +94,19 @@ do_execsql_test 2.7 {
|
||||
} {/B-TREE/}
|
||||
|
||||
|
||||
do_execsql_test 3.0 {
|
||||
CREATE TABLE t3(a INTEGER PRIMARY KEY, b, c, d, e, f);
|
||||
CREATE INDEX t3bcde ON t3(b, c, d, e);
|
||||
EXPLAIN QUERY PLAN
|
||||
SELECT a FROM t3 WHERE b=2 AND c=3 ORDER BY d DESC, e DESC, b, c, a DESC;
|
||||
} {~/B-TREE/}
|
||||
do_execsql_test 3.1 {
|
||||
DROP TABLE t3;
|
||||
CREATE TABLE t3(a INTEGER PRIMARY KEY, b, c, d, e, f) WITHOUT rowid;
|
||||
CREATE INDEX t3bcde ON t3(b, c, d, e);
|
||||
EXPLAIN QUERY PLAN
|
||||
SELECT a FROM t3 WHERE b=2 AND c=3 ORDER BY d DESC, e DESC, b, c, a DESC;
|
||||
} {~/B-TREE/}
|
||||
|
||||
|
||||
finish_test
|
||||
|
Loading…
x
Reference in New Issue
Block a user