]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Account for the ASC/DESC properties of ORDER BY expressions when using the same index... experimental
authordan <dan@noemail.net>
Fri, 10 Oct 2014 20:52:53 +0000 (20:52 +0000)
committerdan <dan@noemail.net>
Fri, 10 Oct 2014 20:52:53 +0000 (20:52 +0000)
FossilOrigin-Name: 2a9573962b837973c4959465d8a5f2641d109a5a

manifest
manifest.uuid
src/where.c
test/tkt-ba7cbfaedc.test [new file with mode: 0644]

index d84631e2208f156271b0b0e22e7985895ff25506..ced935d9a06acee162623f0ad64ea0c413054cf5 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Restrict\sthe\sscope\sof\sthe\sexplainIndexRange()\sfunction\sin\swhere.c.
-D 2014-10-10T19:15:35.023
+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-10T20:52:53.529
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in cf57f673d77606ab0f2d9627ca52a9ba1464146a
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -302,7 +302,7 @@ F src/vtab.c 019dbfd0406a7447c990e1f7bd1dfcdb8895697f
 F src/wal.c 10e7de7ce90865a68153f001a61f1d985cd17983
 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804
-F src/where.c 75af78b4a4125e891f62d997d6d93b006a8c7d68
+F src/where.c 7137da023fa550b44f98251ab6fcf132ce4e371e
 F src/whereInt.h 124d970450955a6982e174b07c320ae6d62a595c
 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
@@ -933,6 +933,7 @@ F test/tkt-b1d3a2e531.test 8f7576e41ca179289ee1a8fee28386fd8e4b0550
 F test/tkt-b351d95f9.test d14a503c414c5c58fdde3e80f9a3cfef986498c0
 F test/tkt-b72787b1.test a95e8cdad0b98af1853ac7f0afd4ab27b77bf5f3
 F test/tkt-b75a9ca6b0.test 97cc2d5eeaf82799eb42138c0a1ff64370238ce4
+F test/tkt-ba7cbfaedc.test e76d88e572e489ee0d64fe4caf4af18b3d1dc688
 F test/tkt-bd484a090c.test 60460bf946f79a79712b71f202eda501ca99b898
 F test/tkt-bdc6bbbb38.test fc38bb09bdd440e3513a1f5f98fc60a075182d7d
 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.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 8541dfb3bbdf63dc9ab304d8a0ab8b290cdc9d96
-R 56927b83c6bc9f8ed8f382263f0b3a19
-U drh
-Z 9069bb5e423e6471fadcdc96cb083909
+P c30124520027f0f860223bf842e2f09db3dafb5f
+R 8de40b978c4dd5c8456f5f796f63e003
+T *branch * experimental
+T *sym-experimental *
+T -sym-trunk *
+U dan
+Z 060424e4e85bb8595890bea0de65ac0e
index ced410d581090e4b550806f2eadca1040baa76b5..604705047dfb2d0cedf4084e4e18f17d94edc75c 100644 (file)
@@ -1 +1 @@
-c30124520027f0f860223bf842e2f09db3dafb5f
\ No newline at end of file
+2a9573962b837973c4959465d8a5f2641d109a5a
\ No newline at end of file
index bd59055b4af6f5ce65051e2004c5e363db96f112..6a5e9186694c53909e2c8c110d0d83adeafd3c23 100644 (file)
@@ -5827,12 +5827,19 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
     if( (pWInfo->wctrlFlags & WHERE_SORTBYGROUP)
         && pWInfo->nOBSat==pWInfo->pOrderBy->nExpr
     ){
-      Bitmask notUsed = 0;
-      int nOrder = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy, 
-          pFrom, 0, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed
-      );
+      Bitmask revMask = 0;
+      int nOrder;
+      assert( pWInfo->wctrlFlags & WHERE_GROUPBY );
       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;
+      }
     }
   }
 
diff --git a/test/tkt-ba7cbfaedc.test b/test/tkt-ba7cbfaedc.test
new file mode 100644 (file)
index 0000000..a558d4c
--- /dev/null
@@ -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
+
+