]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Avoid rewriting compound SELECT statements that use a different collation sequence...
authordan <dan@noemail.net>
Thu, 11 Jun 2020 15:53:54 +0000 (15:53 +0000)
committerdan <dan@noemail.net>
Thu, 11 Jun 2020 15:53:54 +0000 (15:53 +0000)
FossilOrigin-Name: 32a88bdd4be5acdc1b80856bf6e32724dc3a467d5050bec0fe1a3dfedcc06f34

manifest
manifest.uuid
src/select.c
test/window1.test

index 09e432bfe398c375dce9168f8a166117b7f2684e..228f95ace05e6682fcfd24833937b9d9a9329b84 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,12 +1,13 @@
 B fd5abb1a7b5a55127d5c0d5ff448020d8bccab44e4f5afe1eb88fc19578af735
-C Provide\sthe\sability\sto\suse\sthe\sSELECTTRACE()\sdebugging\smacro\soutside\sof\sthe\nselect.c\ssource\sfile.\s\sUse\sthis\sto\sadd\sa\snew\sSELECTTRACE()\sentry\sin\nwindow.c\sfor\simproved\stracing\sof\swindow-function\sparse-tree\srewriting.
-D 2020-06-11T00:57:09.771
+C Avoid\srewriting\scompound\sSELECT\sstatements\sthat\suse\sa\sdifferent\scollation\ssequence\sfor\sORDER\sBY\sand\srecord\sprocessing\sa\ssecond\stime\sif\sthey\scontain\swindow\sfunctions.\sFix\sfor\s[b706351c].
+D 2020-06-11T15:53:54.084
 F src/global.c 0409ae635839e0bef26a69b68be64126ab6cba62ac19bd7694f1652e591c4c17
-F src/select.c 733ae255f1d10d95bbb8a7c13203a62eb79badc775eb2b2315e7ab4e35d45bad
+F src/select.c 4cf6adb522701a8f9d31b813898c0ec0b3409d343ba131a6f9659d49b76e222a
 F src/sqliteInt.h fe320867c4f48eeeca523062c5668508b3f9b88d65690d42610bd138a5fdb5c4
 F src/test1.c e9f68f157f8fd027ee4c32c4b427f4eed274749bfb745427e2d954fa89d95ad3
 F src/window.c 88a63e6948ea924b3cf9ad8aff5ea1fa53bebdb2f13340867205fda16ed0f19c
-P fd5abb1a7b5a55127d5c0d5ff448020d8bccab44e4f5afe1eb88fc19578af735
-R b3d2143c6508e1f1efd9ec1303abeeea
-U drh
-Z 41a1b9acde17079fb4a53b14e25df793
+F test/window1.test 9d7f4990e5b36d95af93b189da4aa75216c6690ce95cced3c8b6d3234be51c2c
+P 30c6d895b573d5f2a53487b3b7a0d20be7e382c7a0bc87336bd43fbd2fa89bf4
+R d77969df2abe7d3c02ea74b2057f9f3a
+U dan
+Z 0af3852064f40e6db0fa611ce2dd7e61
index 850c7896e7897af61009e39f180f09f080ed0df8..3dc252ddbea9b88a052a8f3fbba93a8152de6ca3 100644 (file)
@@ -1 +1 @@
-30c6d895b573d5f2a53487b3b7a0d20be7e382c7a0bc87336bd43fbd2fa89bf4
\ No newline at end of file
+32a88bdd4be5acdc1b80856bf6e32724dc3a467d5050bec0fe1a3dfedcc06f34
\ No newline at end of file
index 123e0fb5fc4b27f65e5607b30eae606cac30dd2f..a8af1766045e2935dcfb6c76dd2b9620ecc5b59f 100644 (file)
@@ -4621,6 +4621,14 @@ static int convertCompoundSelectToSubquery(Walker *pWalker, Select *p){
   for(pX=p; pX && (pX->op==TK_ALL || pX->op==TK_SELECT); pX=pX->pPrior){}
   if( pX==0 ) return WRC_Continue;
   a = p->pOrderBy->a;
+#ifndef SQLITE_OMIT_WINDOWFUNC
+  /* If iOrderByCol is already non-zero, then it has already been matched
+  ** to a result column of the SELECT statement. This occurs when the
+  ** SELECT is rewritten for window-functions processing and then passed
+  ** to sqlite3SelectPrep() and similar a second time. The rewriting done
+  ** by this function is not required in this case. */
+  if( a[0].u.x.iOrderByCol ) return WRC_Continue;
+#endif
   for(i=p->pOrderBy->nExpr-1; i>=0; i--){
     if( a[i].pExpr->flags & EP_Collate ) break;
   }
index ea5b66459e98f784d2f31af9fb6e66f44da4c400..618d95e685360a995683a85d60da403c52ce534e 100644 (file)
@@ -1917,4 +1917,34 @@ do_execsql_test 62.4 {
       ) WHERE c>10;
 } {15.0 30.0}
 
+#-------------------------------------------------------------------------
+reset_db
+do_execsql_test 63.1 {
+  CREATE TABLE t1(b, x);
+  CREATE TABLE t2(c, d);
+  CREATE TABLE t3(e, f);
+}
+
+do_execsql_test 63.2 {
+  SELECT max(b) OVER(
+      ORDER BY SUM(
+        (SELECT c FROM t2 UNION SELECT x ORDER BY c)
+      )
+  ) FROM t1;
+} {{}}
+
+do_execsql_test 63.3 {
+  SELECT sum(b) over(
+      ORDER BY (
+        SELECT max(b) OVER(
+          ORDER BY sum(
+            (SELECT x AS c UNION SELECT 1234 ORDER BY c)
+          )
+        ) AS e
+        ORDER BY e
+      )
+    )
+  FROM t1;
+} {{}}
+
 finish_test