Account for the ASC/DESC properties of ORDER BY expressions when using the same index for GROUP BY and ORDER BY. Candidate fix for [ba7cbfaedc].

FossilOrigin-Name: 2a9573962b837973c4959465d8a5f2641d109a5a
This commit is contained in:
dan 2014-10-10 20:52:53 +00:00
parent 1f8817cb32
commit b6453201d2
4 changed files with 89 additions and 13 deletions

View File

@ -1,5 +1,5 @@
C Restrict\sthe\sscope\sof\sthe\sexplainIndexRange()\sfunction\sin\swhere.c. C Account\sfor\sthe\sASC/DESC\sproperties\sof\sORDER\sBY\sexpressions\swhen\susing\sthe\ssame\sindex\sfor\sGROUP\sBY\sand\sORDER\sBY.\sCandidate\sfix\sfor\s[ba7cbfaedc].
D 2014-10-10T19:15:35.023 D 2014-10-10T20:52:53.529
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in cf57f673d77606ab0f2d9627ca52a9ba1464146a F Makefile.in cf57f673d77606ab0f2d9627ca52a9ba1464146a
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -302,7 +302,7 @@ F src/vtab.c 019dbfd0406a7447c990e1f7bd1dfcdb8895697f
F src/wal.c 10e7de7ce90865a68153f001a61f1d985cd17983 F src/wal.c 10e7de7ce90865a68153f001a61f1d985cd17983
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804
F src/where.c 75af78b4a4125e891f62d997d6d93b006a8c7d68 F src/where.c 7137da023fa550b44f98251ab6fcf132ce4e371e
F src/whereInt.h 124d970450955a6982e174b07c320ae6d62a595c F src/whereInt.h 124d970450955a6982e174b07c320ae6d62a595c
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
@ -933,6 +933,7 @@ F test/tkt-b1d3a2e531.test 8f7576e41ca179289ee1a8fee28386fd8e4b0550
F test/tkt-b351d95f9.test d14a503c414c5c58fdde3e80f9a3cfef986498c0 F test/tkt-b351d95f9.test d14a503c414c5c58fdde3e80f9a3cfef986498c0
F test/tkt-b72787b1.test a95e8cdad0b98af1853ac7f0afd4ab27b77bf5f3 F test/tkt-b72787b1.test a95e8cdad0b98af1853ac7f0afd4ab27b77bf5f3
F test/tkt-b75a9ca6b0.test 97cc2d5eeaf82799eb42138c0a1ff64370238ce4 F test/tkt-b75a9ca6b0.test 97cc2d5eeaf82799eb42138c0a1ff64370238ce4
F test/tkt-ba7cbfaedc.test e76d88e572e489ee0d64fe4caf4af18b3d1dc688
F test/tkt-bd484a090c.test 60460bf946f79a79712b71f202eda501ca99b898 F test/tkt-bd484a090c.test 60460bf946f79a79712b71f202eda501ca99b898
F test/tkt-bdc6bbbb38.test fc38bb09bdd440e3513a1f5f98fc60a075182d7d F test/tkt-bdc6bbbb38.test fc38bb09bdd440e3513a1f5f98fc60a075182d7d
F test/tkt-c48d99d690.test ba61977d62ab612fc515b3c488a6fbd6464a2447 F test/tkt-c48d99d690.test ba61977d62ab612fc515b3c488a6fbd6464a2447
@ -1203,7 +1204,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 8541dfb3bbdf63dc9ab304d8a0ab8b290cdc9d96 P c30124520027f0f860223bf842e2f09db3dafb5f
R 56927b83c6bc9f8ed8f382263f0b3a19 R 8de40b978c4dd5c8456f5f796f63e003
U drh T *branch * experimental
Z 9069bb5e423e6471fadcdc96cb083909 T *sym-experimental *
T -sym-trunk *
U dan
Z 060424e4e85bb8595890bea0de65ac0e

View File

@ -1 +1 @@
c30124520027f0f860223bf842e2f09db3dafb5f 2a9573962b837973c4959465d8a5f2641d109a5a

View File

@ -5827,12 +5827,19 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP) if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP)
&& pWInfo->nOBSat==pWInfo->pOrderBy->nExpr && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr
){ ){
Bitmask notUsed = 0; Bitmask revMask = 0;
int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy, int nOrder;
pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed assert( pWInfo->wctrlFlags & WHERE_GROUPBY );
);
assert( pWInfo->sorted==0 ); assert( pWInfo->sorted==0 );
pWInfo->sorted = (nOrder==pWInfo->pOrderBy->nExpr); pWInfo->wctrlFlags &= ~WHERE_GROUPBY;
nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy,
pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &revMask
);
pWInfo->wctrlFlags |= WHERE_GROUPBY;
if( nOrder==pWInfo->pOrderBy->nExpr ){
pWInfo->sorted = 1;
pWInfo->revMask = revMask;
}
} }
} }

65
test/tkt-ba7cbfaedc.test Normal file
View File

@ -0,0 +1,65 @@
# 2014-10-11
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#*************************************************************************
#
# Test that ticket [ba7cbfaedc] has been fixed.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix tkt-ba7cbfaedc
do_execsql_test 1 {
CREATE TABLE t1 (x, y);
INSERT INTO t1 VALUES (3, 'a');
INSERT INTO t1 VALUES (1, 'a');
INSERT INTO t1 VALUES (2, 'b');
INSERT INTO t1 VALUES (2, 'a');
INSERT INTO t1 VALUES (3, 'b');
INSERT INTO t1 VALUES (1, 'b');
}
do_execsql_test 1.1 {
CREATE INDEX i1 ON t1(x, y);
}
foreach {n idx} {
1 { CREATE INDEX i1 ON t1(x, y) }
2 { CREATE INDEX i1 ON t1(x DESC, y) }
3 { CREATE INDEX i1 ON t1(x, y DESC) }
4 { CREATE INDEX i1 ON t1(x DESC, y DESC) }
} {
catchsql { DROP INDEX i1 }
execsql $idx
foreach {tn q res} {
1 "GROUP BY x, y ORDER BY x, y" {1 a 1 b 2 a 2 b 3 a 3 b}
2 "GROUP BY x, y ORDER BY x DESC, y" {3 a 3 b 2 a 2 b 1 a 1 b}
3 "GROUP BY x, y ORDER BY x, y DESC" {1 b 1 a 2 b 2 a 3 b 3 a}
4 "GROUP BY x, y ORDER BY x DESC, y DESC" {3 b 3 a 2 b 2 a 1 b 1 a}
} {
do_execsql_test 1.$n.$tn "SELECT * FROM t1 $q" $res
}
}
do_execsql_test 2.0 {
drop table if exists t1;
create table t1(id int);
insert into t1(id) values(1),(2),(3),(4),(5);
create index t1_idx_id on t1(id asc);
select * from t1 group by id order by id;
select * from t1 group by id order by id asc;
select * from t1 group by id order by id desc;
} {
1 2 3 4 5 1 2 3 4 5 5 4 3 2 1
}
finish_test