When using an index for both DISTINCT and ORDER BY, do not confuse the number of columns required for distinctness with the number required to get the correct sort order. Fix for [6749cb3c].
FossilOrigin-Name: b47169319ad88e8ffdbe8fbb91f4cced81ebd5c0ee1b018be2d0256c9a1c5159
This commit is contained in:
parent
b8293a5bee
commit
a79a0e733f
19
manifest
19
manifest
@ -1,5 +1,5 @@
|
||||
C Update\sRBU\sso\sthat\sit\ssupports\sindexes\son\sexpressions.
|
||||
D 2019-07-26T20:33:23.040
|
||||
C When\susing\san\sindex\sfor\sboth\sDISTINCT\sand\sORDER\sBY,\sdo\snot\sconfuse\sthe\snumber\sof\scolumns\srequired\sfor\sdistinctness\swith\sthe\snumber\srequired\sto\sget\sthe\scorrect\ssort\sorder.\sFix\sfor\s[6749cb3c].
|
||||
D 2019-07-29T14:42:56.109
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@ -609,8 +609,8 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
|
||||
F src/wal.c bbd6838bd79c0a32144d482fb0b6a9d2d1a252fb3b16d5005ec30f2f80413b0d
|
||||
F src/wal.h 606292549f5a7be50b6227bd685fa76e3a4affad71bb8ac5ce4cb5c79f6a176a
|
||||
F src/walker.c d5a94907dcac990e31976be9dc769d17f6a806782593d6aec9d760ee01ec22cd
|
||||
F src/where.c 2f508c9a6dd2a42ad2b692105e77eb92cdec201d32916962ccdeff71836acb52
|
||||
F src/whereInt.h 1b728f71654ebf8421a1715497a587f02d6f538e819af58dc826908f8577e810
|
||||
F src/where.c a3c9a0e1215c0e67e508014084e8f47271895b56f780fc26ac57be34fac33c1a
|
||||
F src/whereInt.h 6fab4b6f7e4ae716f112ee09cd1343fc6dde3d4a1831feabc6b3ed3b54b8eef3
|
||||
F src/wherecode.c 37a1004237d630d785c47bba2290eac652a7a8b0047518eba3cb7c808b604c4a
|
||||
F src/whereexpr.c 5e559bdd24b06e3bc2e68f258bf751302954dc1e432daf71fdd8098a71462326
|
||||
F src/window.c 7728ba7a3d44084a44eefb60464a88fb2ff035eb20cdeb1160ae65ac3c0be6b9
|
||||
@ -812,7 +812,7 @@ F test/descidx2.test 9f1a0c83fd57f8667c82310ca21b30a350888b5d
|
||||
F test/descidx3.test 09ddbe3f5295f482d2f8b687cf6db8bad7acd9a2
|
||||
F test/diskfull.test 106391384780753ea6896b7b4f005d10e9866b6e
|
||||
F test/distinct.test a1783b960ad8c15a77cd9f207be072898db1026c
|
||||
F test/distinct2.test df0bb52b754661ea84ec9ff488d48913c97bd31d83ca17ce0bf1334645e660cf
|
||||
F test/distinct2.test 1a01038083535fa9431f4a22587ae58d52d0a794910c36bd2bec07ba1e0e7367
|
||||
F test/distinctagg.test 1a6ef9c87a58669438fc771450d7a72577417376
|
||||
F test/e_blobbytes.test 439a945953b35cb6948a552edaec4dc31fd70a05
|
||||
F test/e_blobclose.test 4b3c8c60c2171164d472059c73e9f3c1844bb66d
|
||||
@ -1838,7 +1838,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P e1ccf211aa975a6688a27f7dc4cea80784ed8dcfe1950b2fa6eb0a3cb938838a
|
||||
R d25f513b3e1c94b2e54a2b873df68d96
|
||||
P 6bfa44da226fd758a2ee924d1e8e3a742b0635b6d3f922a4a7919cb14b2418e6
|
||||
R 41a42b5a743b4824fb1ffd95dbeba40a
|
||||
T *branch * tkt-6749cb3c
|
||||
T *sym-tkt-6749cb3c *
|
||||
T -sym-trunk *
|
||||
U dan
|
||||
Z 99e04d0115a0c5741a15100c0c189bee
|
||||
Z 23a64fa9e8cd65c1486338cedc3724c0
|
||||
|
@ -1 +1 @@
|
||||
6bfa44da226fd758a2ee924d1e8e3a742b0635b6d3f922a4a7919cb14b2418e6
|
||||
b47169319ad88e8ffdbe8fbb91f4cced81ebd5c0ee1b018be2d0256c9a1c5159
|
10
src/where.c
10
src/where.c
@ -3695,8 +3695,8 @@ static i8 wherePathSatisfiesOrderBy(
|
||||
if( pLoop->wsFlags & WHERE_VIRTUALTABLE ){
|
||||
if( pLoop->u.vtab.isOrdered ) obSat = obDone;
|
||||
break;
|
||||
}else{
|
||||
pLoop->u.btree.nIdxCol = 0;
|
||||
}else if( wctrlFlags & WHERE_DISTINCTBY ){
|
||||
pLoop->u.btree.nDistinctCol = 0;
|
||||
}
|
||||
iCur = pWInfo->pTabList->a[pLoop->iTab].iCursor;
|
||||
|
||||
@ -3838,7 +3838,9 @@ static i8 wherePathSatisfiesOrderBy(
|
||||
pColl = sqlite3ExprNNCollSeq(pWInfo->pParse, pOrderBy->a[i].pExpr);
|
||||
if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
|
||||
}
|
||||
pLoop->u.btree.nIdxCol = j+1;
|
||||
if( wctrlFlags & WHERE_DISTINCTBY ){
|
||||
pLoop->u.btree.nDistinctCol = j+1;
|
||||
}
|
||||
isMatch = 1;
|
||||
break;
|
||||
}
|
||||
@ -5159,7 +5161,7 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){
|
||||
&& i==pWInfo->nLevel-1 /* Ticket [ef9318757b152e3] 2017-10-21 */
|
||||
&& (pLoop->wsFlags & WHERE_INDEXED)!=0
|
||||
&& (pIdx = pLoop->u.btree.pIndex)->hasStat1
|
||||
&& (n = pLoop->u.btree.nIdxCol)>0
|
||||
&& (n = pLoop->u.btree.nDistinctCol)>0
|
||||
&& pIdx->aiRowLogEst[n]>=36
|
||||
){
|
||||
int r1 = pParse->nMem+1;
|
||||
|
@ -128,7 +128,7 @@ struct WhereLoop {
|
||||
u16 nEq; /* Number of equality constraints */
|
||||
u16 nBtm; /* Size of BTM vector */
|
||||
u16 nTop; /* Size of TOP vector */
|
||||
u16 nIdxCol; /* Index column used for ORDER BY */
|
||||
u16 nDistinctCol; /* Index columns used to sort for DISTINCT */
|
||||
Index *pIndex; /* Index used, or NULL */
|
||||
} btree;
|
||||
struct { /* Information for virtual tables */
|
||||
|
@ -229,5 +229,51 @@ do_execsql_test 1020 {
|
||||
SELECT DISTINCT a FROM t1, t2 WHERE x=b;
|
||||
} {1 1}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
reset_db
|
||||
|
||||
do_execsql_test 2000 {
|
||||
CREATE TABLE t0 (c0, c1, c2, PRIMARY KEY (c0, c1));
|
||||
CREATE TABLE t1 (c2);
|
||||
INSERT INTO t0(c2) VALUES (0),(1),(3),(4),(5),(6),(7),(8),(9),(10),(11);
|
||||
INSERT INTO t0(c1) VALUES ('a');
|
||||
INSERT INTO t1(c2) VALUES (0);
|
||||
}
|
||||
do_execsql_test 2010 {
|
||||
SELECT DISTINCT t0.c0, t1._rowid_, t0.c1 FROM t1 CROSS JOIN t0 ORDER BY t0.c0;
|
||||
} {{} 1 {} {} 1 a}
|
||||
do_execsql_test 1.2 {
|
||||
ANALYZE;
|
||||
}
|
||||
do_execsql_test 2020 {
|
||||
SELECT DISTINCT t0.c0, t1._rowid_, t0.c1 FROM t1 CROSS JOIN t0 ORDER BY t0.c0;
|
||||
} {{} 1 {} {} 1 a}
|
||||
|
||||
|
||||
do_execsql_test 2030 {
|
||||
CREATE TABLE t2(a, b, c);
|
||||
CREATE INDEX t2ab ON t2(a, b);
|
||||
|
||||
WITH c(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM c WHERE i<64)
|
||||
INSERT INTO t2 SELECT 'one', i%2, 'one' FROM c;
|
||||
|
||||
WITH c(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM c WHERE i<64)
|
||||
INSERT INTO t2 SELECT 'two', i%2, 'two' FROM c;
|
||||
|
||||
CREATE TABLE t3(x INTEGER PRIMARY KEY);
|
||||
INSERT INTO t3 VALUES(1);
|
||||
|
||||
ANALYZE;
|
||||
}
|
||||
do_execsql_test 2040 {
|
||||
SELECT DISTINCT a, b, x FROM t3 CROSS JOIN t2 ORDER BY a;
|
||||
} {
|
||||
one 0 1
|
||||
one 1 1
|
||||
two 0 1
|
||||
two 1 1
|
||||
}
|
||||
|
||||
|
||||
|
||||
finish_test
|
||||
|
Loading…
Reference in New Issue
Block a user