]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Make sure the ORDER BY LIMIT optimization is not applied if the inner-most
authordrh <drh@noemail.net>
Thu, 4 Aug 2016 09:09:44 +0000 (09:09 +0000)
committerdrh <drh@noemail.net>
Thu, 4 Aug 2016 09:09:44 +0000 (09:09 +0000)
loop can only have a single iteration and is hence not really a loop.

FossilOrigin-Name: 13e3bd3de6b434b6182ef36be108d7ee0be8ca53

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

index 558a3d8e2dd3768d129f4ebb9a37a9b54a30ec4f..3ea36916cca9bdf170c7dcfa06d98d82f49ff697 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\stypo\sin\sa\scomment\sin\sbtree.c.\s\s\sNo\schanges\sto\scode.
-D 2016-08-03T14:51:16.394
+C Make\ssure\sthe\sORDER\sBY\sLIMIT\soptimization\sis\snot\sapplied\sif\sthe\sinner-most\nloop\scan\sonly\shave\sa\ssingle\siteration\sand\sis\shence\snot\sreally\sa\sloop.
+D 2016-08-04T09:09:44.760
 F Makefile.in 6c20d44f72d4564f11652b26291a214c8367e5db
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc 3340e479e5221f06c3d61726f8f7efff885e4233
@@ -463,7 +463,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
 F src/wal.c 02eeecc265f6ffd0597378f5d8ae9070b62a406a
 F src/wal.h 6dd221ed384afdc204bc61e25c23ef7fd5a511f2
 F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354
-F src/where.c bb1444f6ae6bc3cbd086cc61cd9c6e3a6168d89b
+F src/where.c 5c9df42d50888be8274a5a0eb062eb0629869bd3
 F src/whereInt.h e5b939701a7ceffc5a3a8188a37f9746416ebcd0
 F src/wherecode.c 99707d11907c71d289ee9553d2d1a22f1fd8ba41
 F src/whereexpr.c d7dcbf14ce1b5876c1f76496162c30fcba669563
@@ -888,7 +888,7 @@ F test/like.test 81632c437a947bf1f7130b19537da6a1a844806a
 F test/like2.test 3b2ee13149ba4a8a60b59756f4e5d345573852da
 F test/like3.test 3608a2042b6f922f900fbfd5d3ce4e7eca57f7c4
 F test/limit.test 0c99a27a87b14c646a9d583c7c89fd06c352663e
-F test/limit2.test 55c9f4d08c89311e00afd75045ee1a2aca205cb4
+F test/limit2.test 40e79f3d95f2077742aa5b7676f58c9af1735d83
 F test/loadext.test d077450695ddb5c1ea3ad7d48e5f5850fe732ad9
 F test/loadext2.test 0408380b57adca04004247179837a18e866a74f7
 F test/lock.test be4fe08118fb988fed741f429b7dd5d65e1c90db
@@ -1509,7 +1509,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P b91444b5db8465f09d112455e722c888b3f94329
-R aa712e9e7089879865bbb38d4c2c515d
+P 722c12816347ee9fce7a090cfebef2c5841e7445
+R fd11dfb179ebaeb65493cf49055d4419
 U drh
-Z 2b4f8b48b03032bd1efbc47f9457218f
+Z c8d986adc7b509414bb3aed9ed932c87
index a6f1d523fabbfdf876d342023d3b8e58c9826874..832eed621e3e2aafc6019048fc0aa55f06c2d515 100644 (file)
@@ -1 +1 @@
-722c12816347ee9fce7a090cfebef2c5841e7445
\ No newline at end of file
+13e3bd3de6b434b6182ef36be108d7ee0be8ca53
\ No newline at end of file
index 9b3c281efc49b305b6b3077247d94d0bd4f5f367..c2706dc5ddc38b5f0b24ae22911052fe82b4220e 100644 (file)
@@ -3971,7 +3971,7 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
       pWInfo->revMask = pFrom->revLoop;
       if( pWInfo->nOBSat<=0 ){
         pWInfo->nOBSat = 0;
-        if( nLoop>0 ){
+        if( nLoop>0 && (pFrom->aLoop[nLoop-1]->wsFlags & WHERE_ONEROW)==0 ){
           Bitmask m = 0;
           int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pOrderBy, pFrom,
                       WHERE_ORDERBY_LIMIT, nLoop-1, pFrom->aLoop[nLoop-1], &m);
index f415f3263b3cc5ae7ad3cad347fefe2545c3918a..fb4c89644f0ec4c972d24fd1d0f3bcc552815cd8 100644 (file)
@@ -77,6 +77,28 @@ do_test limit2-120.3 {
   expr {$fast_count < 0.02*$slow_count}
 } {1}
 
+# Bug report against the new ORDER BY LIMIT optimization just prior to
+# release.  (Unreleased so there is no ticket).
+#
+# Make sure the optimization is not applied if the inner loop can only
+# provide a single row of output.
+#
+do_execsql_test limit2-200 {
+  CREATE TABLE t200(a, b);
+  WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<1000)
+    INSERT INTO t200(a,b) SELECT x, x FROM c;
+  CREATE TABLE t201(x INTEGER PRIMARY KEY, y);
+  INSERT INTO t201(x,y) VALUES(2,12345);
+
+  SELECT *, '|' FROM t200, t201 WHERE x=b ORDER BY y LIMIT 3;
+} {2 2 2 12345 |}
+do_execsql_test limit2-210 {
+  SELECT *, '|' FROM t200 LEFT JOIN t201 ON x=b ORDER BY y LIMIT 3;
+} {1 1 {} {} | 3 3 {} {} | 4 4 {} {} |}
+
+
+
+
 
 
 finish_test