]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Do not flatten subqueries that contain an ORDER BY or GROUP BY clause and
authordrh <drh@noemail.net>
Thu, 28 Sep 2017 20:06:53 +0000 (20:06 +0000)
committerdrh <drh@noemail.net>
Thu, 28 Sep 2017 20:06:53 +0000 (20:06 +0000)
can be implemented using a co-routine.

FossilOrigin-Name: 042d655dd9002e8b89a798ad955b0285891aecf79f6978c5312e70ffe0609a46

manifest
manifest.uuid
src/select.c

index d11bdc4fb70dbbc79a42ad2253a1a10753267cf8..c63192e1bf123968ca52d8dd7f8efb6fd133a187 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Remove\sthe\s(undocumented)\squery-planner\scontrol\sthat\sprevents\s\na\s"SELECT\sALL"\ssubquery\sin\sFROM\sclause\sfrom\sbeing\simplemented\sas\sa\sco-routine.
-D 2017-09-28T17:29:24.426
+C Do\snot\sflatten\ssubqueries\sthat\scontain\san\sORDER\sBY\sor\sGROUP\sBY\sclause\sand\ncan\sbe\simplemented\susing\sa\sco-routine.
+D 2017-09-28T20:06:53.014
 F Makefile.in 4bc36d913c2e3e2d326d588d72f618ac9788b2fd4b7efda61102611a6495c3ff
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc 6033b51b6aea702ea059f6ab2d47b1d3cef648695f787247dd4fb395fe60673f
@@ -458,7 +458,7 @@ F src/printf.c 40aee47ae9be4bd3dbdc8968bd07fddc027be8edec8daddf24d3391d36698a1c
 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
 F src/resolve.c 4324a94573b1e29286f8121e4881db59eaedc014afeb274c8d3e07ed282e0e20
 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
-F src/select.c ff9551b1792d838d1973ca3f5062804e2a00b1fa2cef6d7931992d89f2b3744a
+F src/select.c d38163a76a0da425afd4a43f5dd0dc88fdbe0aa258c45f6a9cb44acf0a606bc5
 F src/shell.c c1206a23d9239f8f51751d3be9b8c3b02fa4103546bea1add7f864d84a8276ab
 F src/shell.c.in bb9720a8c5c98d3984b16ab7540e7142bcae959666ecf248bfc523a1d44220ee
 F src/sqlite.h.in ab4f8a29d1580dfaeb6891fa1b83cff8229ba0daa56994707ceaca71495d9ab7
@@ -1655,7 +1655,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P fd3267ef92384fcefaee7460a5ffbaf8ddcb6049eec36f72a7046a43e2871fbf
-R 5a9f08df25678ade0635d27ff9994d5e
+P ff2f5a31a2ac67a2fdbb25793e8013cb0e062ab90bdcba2d52a62d6d4d8b6d18
+R 2327508642786ef6d3dd975eaebc22c4
+T *branch * prefer-coroutine-sort-subquery
+T *sym-prefer-coroutine-sort-subquery *
+T -sym-trunk *
 U drh
-Z 15e07447876306f708cc7a309f77f755
+Z 34c1093fc7e9ecc2e1ce3f4d0b9d734a
index 6515252213e5915bdd3cec34fd1d5383659119e9..61c790dd191edb2d56fc10a82e827307faa13f16 100644 (file)
@@ -1 +1 @@
-ff2f5a31a2ac67a2fdbb25793e8013cb0e062ab90bdcba2d52a62d6d4d8b6d18
\ No newline at end of file
+042d655dd9002e8b89a798ad955b0285891aecf79f6978c5312e70ffe0609a46
\ No newline at end of file
index a5f04767bfa19f112b7e987340e6ff113a35d42b..7583fc24f1e23b270220225f3501740cb3085b2c 100644 (file)
@@ -5205,6 +5205,25 @@ int sqlite3Select(
       goto select_end;
     }
 
+    /* If the subquery contains an ORDER BY or GROUP BY clause and if
+    ** it will be implemented as a co-routine, then do not flatten.  This
+    ** restriction allows SQL constructs like this:
+    **
+    **  SELECT expensive_function(x)
+    **    FROM (SELECT x FROM tab ORDER BY y LIMIT 10);
+    **
+    ** The expensive_function() is only computed on the 10 rows that
+    ** are output, rather than every row of the table.
+    */
+    if( (pSub->pOrderBy!=0 || pSub->pGroupBy!=0)
+     && i==0
+     && (pTabList->nSrc==1
+         || (pTabList->a[1].fg.jointype&(JT_LEFT|JT_CROSS))!=0)
+     && OptimizationEnabled(db, SQLITE_SubqCoroutine)
+    ){
+      continue;
+    }
+
     isAggSub = (pSub->selFlags & SF_Aggregate)!=0;
     if( flattenSubquery(pParse, p, i, isAgg, isAggSub) ){
       /* This subquery can be absorbed into its parent. */