]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix over-aggressive optimization of ORDER BY as reported on the mailing list. (CVS...
authordrh <drh@noemail.net>
Thu, 1 Sep 2005 17:47:51 +0000 (17:47 +0000)
committerdrh <drh@noemail.net>
Thu, 1 Sep 2005 17:47:51 +0000 (17:47 +0000)
FossilOrigin-Name: efbb4bc83cd86b6a26d58c5818c58c2e3edaab18

manifest
manifest.uuid
src/where.c
test/sort.test
test/where.test

index f8736b2964abecaea40f00ab77defdce365310c5..5c1e0ad09431d2279ec37b09f0b45121ce7e5b4e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C All\sregression\stests\snow\spass\swith\sthe\snew\sbounded-memory\ssort\scode.\nThere\sis\sstill\slots\sof\sopportunity\sfor\soptimization,\showever.\s(CVS\s2654)
-D 2005-09-01T12:16:29
+C Fix\sover-aggressive\soptimization\sof\sORDER\sBY\sas\sreported\son\sthe\smailing\slist.\s(CVS\s2655)
+D 2005-09-01T17:47:51
 F Makefile.in 12784cdce5ffc8dfb707300c34e4f1eb3b8a14f1
 F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -87,7 +87,7 @@ F src/vdbeapi.c f0d36ff0f06bb5315efac5645b62e99db2c175b8
 F src/vdbeaux.c afb689d2d5c413ec3448f8f697d07dcd35bd8766
 F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5
 F src/vdbemem.c 4732fd4d1a75dc38549493d7f9a81d02bf7c59b5
-F src/where.c bbb973cbbd862b6b872faac39716a3fe13adfb44
+F src/where.c 92ab208abe6bec15e81616b8c1a619be23ece506
 F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
 F test/all.test 7f0988442ab811dfa41793b5b550f5828ce316f3
 F test/alter.test 9d6837a3d946b73df692b7cef2a7644d2e2f6bc6
@@ -204,7 +204,7 @@ F test/select4.test c239f516aa31f42f2ef7c6d7cd01105f08f934ca
 F test/select5.test ae1b5ee2485c5fdc610207a391cfdc23e59c7834
 F test/select6.test 6559d16ad16edb7d6864f7e74a3d204d0af72486
 F test/select7.test 1bf795b948c133a15a2a5e99d3270e652ec58ce6
-F test/sort.test 3b871d6e032f0a6c84d9f3d2d4b226e8fda97de0
+F test/sort.test 0c33a8ae1c238377ad197387c3872175f40d3843
 F test/subquery.test ed4ecba1afacb586c86fad1cdb92756a48a90302
 F test/subselect.test 3f3f7a940dc3195c3139f4d530385cb54665d614
 F test/sync.test d769caaec48456119316775e35e0fdee2fa852d7
@@ -235,7 +235,7 @@ F test/vacuum.test 5d4857ae2afc9c20d0edb8acc58bdc8d630126a9
 F test/vacuum2.test 5d77e98c458bcdbeecc6327de5107179ba1aa095
 F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102
 F test/view.test ce0f0ad39fa4a3572acffcf1e634850ee151aae0
-F test/where.test 9a5d0aaf3dd32ecf7b555049a163e2111d95a274
+F test/where.test 1e9b990d64ca1d9175bcaa96e9f396e67c29ba07
 F test/where2.test 503e2e2b6abe14c5c10222e72d08ef84c1bf1ffb
 F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b
 F tool/lemon.c c88936c67f6411608db8fa4254d254f509fa40f6
@@ -306,7 +306,7 @@ F www/tclsqlite.tcl 3df553505b6efcad08f91e9b975deb2e6c9bb955
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 09db0a24241f9248584250d1728117b8a3159626
-R a28ffb891eb181a1cfb6d78b2bf4c660
+P 81259a01f1e85ba50a1d017b1282bf841b16f0a5
+R 9230534585e06aeccca811dde76702e9
 U drh
-Z 0218deeb57fbf0ef13b89eb807c70c2a
+Z 91850feb3a4a5d6eb41e5886f9a1b320
index 61bf402dc31652286ed31b9bffdc2aa6d77ecfb7..21e59d0f358aaeb7d8deaa9c39f6ecb817db07e9 100644 (file)
@@ -1 +1 @@
-81259a01f1e85ba50a1d017b1282bf841b16f0a5
\ No newline at end of file
+efbb4bc83cd86b6a26d58c5818c58c2e3edaab18
\ No newline at end of file
index 27b05e21dbaa354f02a39616a49078ce1d785cd5..c085f442f5fb6fd336dd88ebb66b203f52e3acd1 100644 (file)
@@ -16,7 +16,7 @@
 ** so is applicable.  Because this module is responsible for selecting
 ** indices, you might also think of this module as the "query optimizer".
 **
-** $Id: where.c,v 1.167 2005/08/29 16:40:53 drh Exp $
+** $Id: where.c,v 1.168 2005/09/01 17:47:51 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -813,7 +813,8 @@ static int sortableByRowid(
   assert( pOrderBy!=0 );
   assert( pOrderBy->nExpr>0 );
   p = pOrderBy->a[0].pExpr;
-  if( p->op==TK_COLUMN && p->iTable==base && p->iColumn==-1 ){
+  if( pOrderBy->nExpr==1 && p->op==TK_COLUMN && p->iTable==base
+          && p->iColumn==-1 ){
     *pbRev = pOrderBy->a[0].sortOrder;
     return 1;
   }
index 712ee276d9e8c104a65e2754a7358d8c8beb6c03..0bafd0090da540978dd0ed2ef04e00ddab99fc4a 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the CREATE TABLE statement.
 #
-# $Id: sort.test,v 1.22 2005/08/13 16:13:06 drh Exp $
+# $Id: sort.test,v 1.23 2005/09/01 17:47:52 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -447,4 +447,21 @@ do_test sort-11.1 {
   }
 } {3 4}
 
+# Trouble reported on the mailing list.  Check for overly aggressive
+# (which is to say, incorrect) optimization of order-by with a rowid
+# in a join.
+#
+do_test sort-12.1 {
+  execsql {
+    create table a (id integer primary key);
+    create table b (id integer primary key, aId integer, text);
+    insert into a values (1);
+    insert into b values (2, 1, 'xxx');
+    insert into b values (1, 1, 'zzz');
+    insert into b values (3, 1, 'yyy');
+    select a.id, b.id, b.text from a join b on (a.id = b.aId)
+      order by a.id, b.text;
+  }
+} {1 2 xxx 1 3 yyy 1 1 zzz}
+
 finish_test
index 25cb6314ef621e893990db6f535c5c224ff3356f..c56cec908b25ab9a54722e7c5d5000fb17d3f7e3 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the use of indices in WHERE clases.
 #
-# $Id: where.test,v 1.34 2005/09/01 12:16:29 drh Exp $
+# $Id: where.test,v 1.35 2005/09/01 17:47:52 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -590,22 +590,22 @@ do_test where-6.21 {
   cksort {
     SELECT y FROM t1 ORDER BY rowid, y LIMIT 3;
   }
-} {4 9 16 nosort}
+} {4 9 16 sort}
 do_test where-6.22 {
   cksort {
     SELECT y FROM t1 ORDER BY rowid, y DESC LIMIT 3;
   }
-} {4 9 16 nosort}
+} {4 9 16 sort}
 do_test where-6.23 {
   cksort {
     SELECT y FROM t1 WHERE y>4 ORDER BY rowid, w, x LIMIT 3;
   }
-} {9 16 25 nosort}
+} {9 16 25 sort}
 do_test where-6.24 {
   cksort {
     SELECT y FROM t1 WHERE y>=9 ORDER BY rowid, x DESC, w LIMIT 3;
   }
-} {9 16 25 nosort}
+} {9 16 25 sort}
 do_test where-6.25 {
   cksort {
     SELECT y FROM t1 WHERE y>4 AND y<25 ORDER BY rowid;
@@ -620,7 +620,7 @@ do_test where-6.27 {
   cksort {
     SELECT y FROM t1 WHERE y<=25 ORDER BY _rowid_, w+y;
   }
-} {4 9 16 25 nosort}
+} {4 9 16 25 sort}
 
 
 # Tests for reverse-order sorting.
@@ -782,19 +782,19 @@ do_test where-7.31 {
 } {10201 10000 9801 nosort}
 do_test where-7.32 {
   cksort {
-    SELECT y FROM t1 WHERE y<25 ORDER BY rowid DESC, x
+    SELECT y FROM t1 WHERE y<25 ORDER BY rowid DESC
   }
 } {16 9 4 nosort}
 do_test where-7.33 {
   cksort {
-    SELECT y FROM t1 WHERE y<=25 ORDER BY rowid DESC, x
+    SELECT y FROM t1 WHERE y<=25 ORDER BY rowid DESC
   }
 } {25 16 9 4 nosort}
 do_test where-7.34 {
   cksort {
     SELECT y FROM t1 WHERE y<25 AND y>4 ORDER BY rowid DESC, y DESC
   }
-} {16 9 nosort}
+} {16 9 sort}
 do_test where-7.35 {
   cksort {
     SELECT y FROM t1 WHERE y<25 AND y>=4 ORDER BY rowid DESC