]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Bug fix in the ORDER BY optimizer. Ticket #1435. (CVS 2707)
authordrh <drh@noemail.net>
Sat, 17 Sep 2005 13:29:23 +0000 (13:29 +0000)
committerdrh <drh@noemail.net>
Sat, 17 Sep 2005 13:29:23 +0000 (13:29 +0000)
FossilOrigin-Name: 553b7ba8f8ae4cb865494f2d301690149d7edb9f

manifest
manifest.uuid
src/where.c
test/tkt1435.test [new file with mode: 0644]
test/tkt1443.test

index 1f0347ee5c44091a31401b1e026fb6842330cf5f..0d1be186047fc19e8f40040cd2193ea0d165cd7e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Make\ssure\sdependencies\son\sthe\sright-hand\sside\sof\sIN\soperators\sare\schecked\ncorrectly.\s\sTicket\s#1433.\s(CVS\s2706)
-D 2005-09-17T13:07:13
+C Bug\sfix\sin\sthe\sORDER\sBY\soptimizer.\s\sTicket\s#1435.\s(CVS\s2707)
+D 2005-09-17T13:29:24
 F Makefile.in 12784cdce5ffc8dfb707300c34e4f1eb3b8a14f1
 F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -87,7 +87,7 @@ F src/vdbeapi.c 85bbe1d0243a89655433d60711b4bd71979b59cd
 F src/vdbeaux.c e3a815a88bbf68f17880f5bc077e1c35d14b9409
 F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5
 F src/vdbemem.c fea0744936008831daa17cdc75056c3ca1469690
-F src/where.c a595744df3ce50c5d875bae06798054bbef1d7f9
+F src/where.c 1cc55c9aa142c7ef09b427f5fd0bf0488e365fc4
 F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42
 F test/all.test 7f0988442ab811dfa41793b5b550f5828ce316f3
 F test/alter.test 9d6837a3d946b73df692b7cef2a7644d2e2f6bc6
@@ -217,7 +217,8 @@ F test/tester.tcl 98ecdc5723b3b2be5a8a5c3a7f38fa53031466ee
 F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35
 F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b
 F test/threadtest2.c 97a830d53c24c42290501fdfba4a6e5bdd34748b
-F test/tkt1443.test c056bfdabb6c3144bca6f70ce52d32d25101c3b4
+F test/tkt1435.test f768e5415d102fa1d8de3f548469d8fd1b79abd8
+F test/tkt1443.test 1e83b6a1e7f6e261682e67106ab3bc05f6c70e90
 F test/trace.test 9fd28695c463b90c2d32c387a432e01eb26e8ccf
 F test/trans.test 10506dc30305cfb8c4098359f7f6f64786f69c5e
 F test/trigger1.test 152aed5a1fa90709fe171f2ca501a6b7f7901479
@@ -308,7 +309,7 @@ F www/tclsqlite.tcl ddcf912ea48695603c8ed7efb29f0812ef8d1b49
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 0eaf430d9538ece1a3d1300db91f269577a5e028
-R 56daf0fd324c3c63c9831d6786cf42e7
+P 21740794ab81924442f358a6adbbe6d5590cf58d
+R b32fca0d91a2191c1cb4e71d6f5df25e
 U drh
-Z 3c070837de28d59d54c656780119322f
+Z c7d6a04f82149f6121e1279552dd9d04
index dbf5b651489198164588deb6d3b629a441707c9d..af6aad807b3965eaff8de1ce297303c1298a69d9 100644 (file)
@@ -1 +1 @@
-21740794ab81924442f358a6adbbe6d5590cf58d
\ No newline at end of file
+553b7ba8f8ae4cb865494f2d301690149d7edb9f
\ No newline at end of file
index 1c507b3b23ac669a1eecfa5407e451946d974fdf..498821024e89974c3f93a4c437baaa025c8a652d 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.173 2005/09/17 13:07:13 drh Exp $
+** $Id: where.c,v 1.174 2005/09/17 13:29:24 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -1471,7 +1471,7 @@ WhereInfo *sqlite3WhereBegin(
         continue;
       }
       cost = bestIndex(pParse, &wc, pTabItem, notReady,
-                       (j==0 && ppOrderBy) ? *ppOrderBy : 0,
+                       (i==0 && ppOrderBy) ? *ppOrderBy : 0,
                        &pIdx, &flags, &nEq);
       if( cost<lowestCost ){
         lowestCost = cost;
diff --git a/test/tkt1435.test b/test/tkt1435.test
new file mode 100644 (file)
index 0000000..aae879e
--- /dev/null
@@ -0,0 +1,107 @@
+# 2005 September 17
+#
+# 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.
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library.
+#
+# This file implements tests to verify that ticket #1435 has been
+# fixed.  
+#
+#
+# $Id: tkt1435.test,v 1.1 2005/09/17 13:29:24 drh Exp $
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+
+# Construct the sample database.
+#
+do_test tkt1435-1.0 {
+  sqlite3 db :memory:
+  execsql {
+    CREATE TABLE Instances(
+       instanceId INTEGER PRIMARY KEY,
+       troveName STR,
+       versionId INT,
+       flavorId INT,
+       timeStamps STR,
+       isPresent INT,
+       pinned BOOLEAN
+    );
+    INSERT INTO "Instances"
+       VALUES(1, 'libhello:runtime', 1, 1, 1126929880.094, 1, 1);
+    INSERT INTO "Instances"
+       VALUES(2, 'libhello:user', 1, 1, 1126929880.094, 1, 0);
+    INSERT INTO "Instances"
+       VALUES(3, 'libhello:script', 1, 1, 1126929880.094, 1, 0);
+    INSERT INTO "Instances"
+       VALUES(4, 'libhello', 1, 1, 1126929880.094, 1, 0);
+    
+    CREATE TABLE Versions(versionId INTEGER PRIMARY KEY,version STR UNIQUE);
+    INSERT INTO "Versions" VALUES(0, NULL);
+    INSERT INTO "Versions" VALUES(1, '/localhost@rpl:linux/0-1-1');
+    
+    CREATE TABLE Flavors(flavorId integer primary key, flavor str unique);
+    INSERT INTO "Flavors" VALUES(0, NULL);
+    INSERT INTO "Flavors" VALUES(1, '1#x86');
+    
+    CREATE TEMPORARY TABLE tlList (
+       row INTEGER PRIMARY KEY,
+       name STRING,
+       version STRING,
+       flavor STRING
+    );
+    
+    INSERT INTO tlList 
+      values(NULL, 'libhello:script', '/localhost@rpl:linux/0-1-1', '1#x86');
+    INSERT INTO tlList 
+      values(NULL, 'libhello:user', '/localhost@rpl:linux/0-1-1', '1#x86');
+    INSERT INTO tlList 
+      values(NULL, 'libhello:runtime', '/localhost@rpl:linux/0-1-1', '1#x86');
+  }
+} {}
+
+# Run the query with an index
+#
+do_test tkt1435-1.1 {
+  execsql {
+    select row, pinned from tlList, Instances, Versions, Flavors
+        where
+            Instances.troveName = tlList.name
+        and Versions.version = tlList.version
+        and Instances.versionId = Versions.versionId
+        and (    Flavors.flavor = tlList.flavor or Flavors.flavor is NULL
+             and tlList.flavor = '')
+        and Instances.flavorId = Flavors.flavorId
+    order by row asc;
+  }
+} {1 0 2 0 3 1}
+
+# Create a indices, analyze and rerun the query. 
+# Verify that the results are the same
+#
+do_test tkt1435-1.2 {
+  execsql {
+    CREATE INDEX InstancesNameIdx ON Instances(troveName);
+    CREATE UNIQUE INDEX InstancesIdx 
+      ON Instances(troveName, versionId, flavorId);
+    ANALYZE;
+    select row, pinned from tlList, Instances, Versions, Flavors
+        where
+            Instances.troveName = tlList.name
+        and Versions.version = tlList.version
+        and Instances.versionId = Versions.versionId
+        and (    Flavors.flavor = tlList.flavor or Flavors.flavor is NULL
+             and tlList.flavor = '')
+        and Instances.flavorId = Flavors.flavorId
+    order by row asc;
+  }
+} {1 0 2 0 3 1}
+
+finish_test
index 3f9bd3c1552801bc214316dfd9fa16417867be1f..3814b4b9e9910c0b2e18bca06bc4c8c5fbc58342 100644 (file)
 # parts of the system all at once, that it seemed like a good one to
 # include in the test suite. 
 #
-# $Id: tkt1443.test,v 1.1 2005/09/17 13:07:13 drh Exp $
+# NOTE:  Yes, in spite of the name of this file (tkt1443.test) this
+# test is for ticket #1433 not #1443.  I mistyped the name when I was
+# creating the file and I had already checked in the file by the wrong
+# name be the time I noticed the error.  With CVS it is a really hassle
+# to change filenames, so I'll just leave it as is.  No harm done.
+#
+# $Id: tkt1443.test,v 1.2 2005/09/17 13:29:24 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -36,7 +42,7 @@ source $testdir/tester.tcl
 
 # Construct the sample database.
 #
-do_test tkt1433-1.0 {
+do_test tkt1443-1.0 {
   sqlite3 db :memory:
   execsql {
     CREATE TABLE Items(