Allow an index to be used for sorting even if prior terms of the index
are constrained by IN operators. FossilOrigin-Name: 98bf668ab1a8683b46ee8c94cb60f8215aabc517
This commit is contained in:
parent
928d9c6209
commit
1b8fc65b92
19
manifest
19
manifest
@ -1,5 +1,5 @@
|
||||
C Fix\sharmless\scompiler\swarnings.
|
||||
D 2013-02-07T09:33:56.594
|
||||
C Allow\san\sindex\sto\sbe\sused\sfor\ssorting\seven\sif\sprior\sterms\sof\sthe\sindex\nare\sconstrained\sby\sIN\soperators.
|
||||
D 2013-02-07T21:15:14.299
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in a48faa9e7dd7d556d84f5456eabe5825dd8a6282
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
@ -252,7 +252,7 @@ F src/vtab.c b05e5f1f4902461ba9f5fc49bb7eb7c3a0741a83
|
||||
F src/wal.c f5c7b5027d0ed0e9bc9afeb4a3a8dfea762ec7d2
|
||||
F src/wal.h 29c197540b19044e6cd73487017e5e47a1d3dac6
|
||||
F src/walker.c 3d75ba73de15e0f8cd0737643badbeb0e002f07b
|
||||
F src/where.c 427c6ec07c2150e6d2bd28aefd98ab234cc374c3
|
||||
F src/where.c 74f8a582895bd27e74885858f598cdf54c32682d
|
||||
F test/8_3_names.test 631ea964a3edb091cf73c3b540f6bcfdb36ce823
|
||||
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
|
||||
F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6
|
||||
@ -970,8 +970,8 @@ F test/walro.test a31deb621033442a76c3a61e44929250d06f81b1
|
||||
F test/walshared.test 6dda2293880c300baf5d791c307f653094585761
|
||||
F test/walslow.test e7be6d9888f83aa5d3d3c7c08aa9b5c28b93609a
|
||||
F test/walthread.test de8dbaf6d9e41481c460ba31ca61e163d7348f8e
|
||||
F test/where.test 9714e6f292d70c22e78e1cecb3d896457186b9b7
|
||||
F test/where2.test 43d4becaf5a5df854e6c21d624a1cb84c6904554
|
||||
F test/where.test 55f6780f986b38b870e0fc50c3d842c13e7946a0
|
||||
F test/where2.test 61acb16d8e67e0d8717b2ad1a132f3b1ad81fd62
|
||||
F test/where3.test 667e75642102c97a00bf9b23d3cb267db321d006
|
||||
F test/where4.test e9b9e2f2f98f00379e6031db6a6fca29bae782a2
|
||||
F test/where5.test fdf66f96d29a064b63eb543e28da4dfdccd81ad2
|
||||
@ -1034,7 +1034,10 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
|
||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
|
||||
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
|
||||
P e1640876df7ed6fb4e84292e5ce1f78635df64ab
|
||||
R ed650c137d06abf5e97862ecc9965eee
|
||||
P 4a7b4ee011fea911b981206c242e3d5553303b52
|
||||
R 5cc9a6226d6ff2cc56ed201a94d58505
|
||||
T *branch * IN-with-ORDERBY
|
||||
T *sym-IN-with-ORDERBY *
|
||||
T -sym-trunk *
|
||||
U drh
|
||||
Z 0e5ff063c96a5d0e787292d2749e52de
|
||||
Z 6d9a20d9ee8461cef5a45f6f7cc942b7
|
||||
|
@ -1 +1 @@
|
||||
4a7b4ee011fea911b981206c242e3d5553303b52
|
||||
98bf668ab1a8683b46ee8c94cb60f8215aabc517
|
@ -3010,10 +3010,15 @@ static int isSortingIndex(
|
||||
if( pConstraint==0 ){
|
||||
isEq = 0;
|
||||
}else if( (pConstraint->eOperator & WO_IN)!=0 ){
|
||||
#if 0
|
||||
/* Constraints of the form: "X IN ..." cannot be used with an ORDER BY
|
||||
** because we do not know in what order the values on the RHS of the IN
|
||||
** operator will occur. */
|
||||
break;
|
||||
#else
|
||||
if( termSortOrder ) break;
|
||||
isEq = 0;
|
||||
#endif
|
||||
}else if( (pConstraint->eOperator & WO_ISNULL)!=0 ){
|
||||
uniqueNotNull = 0;
|
||||
isEq = 1; /* "X IS NULL" means X has only a single value */
|
||||
@ -3317,8 +3322,8 @@ static void bestBtreeIndex(WhereBestIdx *p){
|
||||
** indicate this to the caller.
|
||||
**
|
||||
** Otherwise, if the search may find more than one row, test to see if
|
||||
** there is a range constraint on indexed column (pc.plan.nEq+1) that can be
|
||||
** optimized using the index.
|
||||
** there is a range constraint on indexed column (pc.plan.nEq+1) that
|
||||
** can be optimized using the index.
|
||||
*/
|
||||
if( pc.plan.nEq==pProbe->nColumn && pProbe->onError!=OE_None ){
|
||||
testcase( pc.plan.wsFlags & WHERE_COLUMN_IN );
|
||||
|
@ -379,11 +379,26 @@ ifcapable subquery {
|
||||
SELECT * FROM t1 WHERE rowid+0 IN (1,2,3,1234) order by 1;
|
||||
}
|
||||
} {1 0 4 2 1 9 3 1 16 102}
|
||||
do_test where-5.3 {
|
||||
do_test where-5.3a {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE w IN (-1,1,2,3) order by 1;
|
||||
}
|
||||
} {1 0 4 2 1 9 3 1 16 14}
|
||||
} {1 0 4 2 1 9 3 1 16 13}
|
||||
do_test where-5.3b {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE w IN (3,-1,1,2) order by 1;
|
||||
}
|
||||
} {1 0 4 2 1 9 3 1 16 13}
|
||||
do_test where-5.3c {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE w IN (3,2,-1,1,2) order by 1;
|
||||
}
|
||||
} {1 0 4 2 1 9 3 1 16 13}
|
||||
do_test where-5.3d {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE w IN (-1,1,2,3) order by 1 DESC;
|
||||
}
|
||||
} {3 1 16 2 1 9 1 0 4 14}
|
||||
do_test where-5.4 {
|
||||
count {
|
||||
SELECT * FROM t1 WHERE w+0 IN (-1,1,2,3) order by 1;
|
||||
@ -511,11 +526,16 @@ do_test where-6.7 {
|
||||
}
|
||||
} {1 100 4 2 99 9 3 98 16 nosort}
|
||||
ifcapable subquery {
|
||||
do_test where-6.8 {
|
||||
do_test where-6.8a {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a IN (3,5,7,1,9,4,2) ORDER BY a LIMIT 3
|
||||
}
|
||||
} {1 100 4 2 99 9 3 98 16 sort}
|
||||
} {1 100 4 2 99 9 3 98 16 nosort}
|
||||
do_test where-6.8b {
|
||||
cksort {
|
||||
SELECT * FROM t3 WHERE a IN (3,5,7,1,9,4,2) ORDER BY a DESC LIMIT 3
|
||||
}
|
||||
} {9 92 100 7 94 64 5 96 36 sort}
|
||||
}
|
||||
do_test where-6.9.1 {
|
||||
cksort {
|
||||
|
@ -167,24 +167,54 @@ ifcapable subquery {
|
||||
}
|
||||
} {99 6 10000 10006 100 6 10201 10207 sort t1 i1zyx}
|
||||
}
|
||||
do_test where2-4.6 {
|
||||
do_test where2-4.6a {
|
||||
queryplan {
|
||||
SELECT * FROM t1
|
||||
WHERE x IN (1,2,3,4,5,6,7,8)
|
||||
AND y IN (10000,10001,10002,10003,10004,10005)
|
||||
ORDER BY 2
|
||||
ORDER BY x
|
||||
}
|
||||
} {99 6 10000 10006 nosort t1 i1xy}
|
||||
do_test where2-4.6b {
|
||||
queryplan {
|
||||
SELECT * FROM t1
|
||||
WHERE x IN (1,2,3,4,5,6,7,8)
|
||||
AND y IN (10000,10001,10002,10003,10004,10005)
|
||||
ORDER BY x DESC
|
||||
}
|
||||
} {99 6 10000 10006 sort t1 i1xy}
|
||||
do_test where2-4.6c {
|
||||
queryplan {
|
||||
SELECT * FROM t1
|
||||
WHERE x IN (1,2,3,4,5,6,7,8)
|
||||
AND y IN (10000,10001,10002,10003,10004,10005)
|
||||
ORDER BY x, y
|
||||
}
|
||||
} {99 6 10000 10006 nosort t1 i1xy}
|
||||
do_test where2-4.6d {
|
||||
queryplan {
|
||||
SELECT * FROM t1
|
||||
WHERE x IN (1,2,3,4,5,6,7,8)
|
||||
AND y IN (10000,10001,10002,10003,10004,10005)
|
||||
ORDER BY x, y DESC
|
||||
}
|
||||
} {99 6 10000 10006 sort t1 i1xy}
|
||||
|
||||
# Duplicate entires on the RHS of an IN operator do not cause duplicate
|
||||
# output rows.
|
||||
#
|
||||
do_test where2-4.6 {
|
||||
do_test where2-4.6x {
|
||||
queryplan {
|
||||
SELECT * FROM t1 WHERE z IN (10207,10006,10006,10207)
|
||||
ORDER BY w
|
||||
}
|
||||
} {99 6 10000 10006 100 6 10201 10207 sort t1 i1zyx}
|
||||
do_test where2-4.6y {
|
||||
queryplan {
|
||||
SELECT * FROM t1 WHERE z IN (10207,10006,10006,10207)
|
||||
ORDER BY w DESC
|
||||
}
|
||||
} {100 6 10201 10207 99 6 10000 10006 sort t1 i1zyx}
|
||||
ifcapable compound {
|
||||
do_test where2-4.7 {
|
||||
queryplan {
|
||||
@ -207,10 +237,15 @@ do_test where2-5.1 {
|
||||
} {99 6 10000 10006 nosort t1 i1w}
|
||||
|
||||
ifcapable subquery {
|
||||
do_test where2-5.2 {
|
||||
do_test where2-5.2a {
|
||||
queryplan {
|
||||
SELECT * FROM t1 WHERE w IN (99) ORDER BY w
|
||||
}
|
||||
} {99 6 10000 10006 nosort t1 i1w}
|
||||
do_test where2-5.2b {
|
||||
queryplan {
|
||||
SELECT * FROM t1 WHERE w IN (99) ORDER BY w DESC
|
||||
}
|
||||
} {99 6 10000 10006 sort t1 i1w}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user