]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix handling the case where a sub-query in a FROM clause is itself a UNION
authordan <dan@noemail.net>
Thu, 5 Jan 2017 17:25:53 +0000 (17:25 +0000)
committerdan <dan@noemail.net>
Thu, 5 Jan 2017 17:25:53 +0000 (17:25 +0000)
ALL, and one side of that UNION ALL is a query on a view that includes an
ORDER BY. Fix for ticket [190c2507].

FossilOrigin-Name: ec1e85a657a6fad77102c440326cfa0c788da12d

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

index c070380072e73d7e72a2261aec16dfca8ebf677a..0087ccd75dae6f2c91da51704e918610a43fab2a 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Version\s3.16.2\srelease\scandidate
-D 2017-01-05T15:50:26.758
+C Fix\shandling\sthe\scase\swhere\sa\ssub-query\sin\sa\sFROM\sclause\sis\sitself\sa\sUNION\nALL,\sand\sone\sside\sof\sthat\sUNION\sALL\sis\sa\squery\son\sa\sview\sthat\sincludes\san\nORDER\sBY.\sFix\sfor\sticket\s[190c2507].
+D 2017-01-05T17:25:53.835
 F Makefile.in 41bd4cad981487345c4a84081074bcdb876e4b2e
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da
@@ -388,7 +388,7 @@ F src/printf.c 0c8579432f47948d9be5077eb590e8c4a01be667
 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
 F src/resolve.c bb070cf5f23611c44ab7e4788803684e385fc3fb
 F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
-F src/select.c dfb6cadc3dcfba1b1bdbfba62ebba2b4b673413e
+F src/select.c 4437d9d5d56b6ffdedabf394c7fe3a07ff521ce9
 F src/shell.c 6095531aa900decdaa765e0f3993fba7153c92c1
 F src/sqlite.h.in e8e2d108d82647f0a812fdb74accf91c1ec08ddc
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
@@ -1073,7 +1073,7 @@ F test/select8.test 8c8f5ae43894c891efc5755ed905467d1d67ad5d
 F test/select9.test aebc2bb0c3bc44606125033cbcaac2c8d1f33a95
 F test/selectA.test 101e722370ac6e84978c2958b8931c78b10a1709
 F test/selectB.test 954e4e49cf1f896d61794e440669e03a27ceea25
-F test/selectC.test 871fb55d884d3de5943c4057ebd22c2459e71977
+F test/selectC.test e25243f8ca503e06f252eb0218976d07cfeceac3
 F test/selectD.test b0f02a04ef7737decb24e08be2c39b9664b43394
 F test/selectE.test a8730ca330fcf40ace158f134f4fe0eb00c7edbf
 F test/selectF.test 21c94e6438f76537b72532fa9fd4710cdd455fc3
@@ -1542,7 +1542,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 9592cbcf351296613a340c6ff5a627ebf9e0abc0
-R 3f7c85ea5091e1d05567add9d05d28cb
-U drh
-Z 371b671165d6dfb968572061f2630965
+P 9d8ffe13bdf4d5d48f1a5f733158c59ea93d8f72
+Q +590ca83b8e8cdd5d24ed7f10f43e540aa0627f22
+R 42407bde9ee368b93f4388bebc25862e
+U dan
+Z 8928f4bba4dd7c0b5cc38003f2cdb321
index 4698bdebe5acc142b29a917c8a3a6c9ab7175f98..c9b780126e84db5d52aeb1ac8911013ba619a918 100644 (file)
@@ -1 +1 @@
-9d8ffe13bdf4d5d48f1a5f733158c59ea93d8f72
\ No newline at end of file
+ec1e85a657a6fad77102c440326cfa0c788da12d
\ No newline at end of file
index e5f4c7fcdff8465faf1cd2441fc81ff63814b259..75ae082e962ee03d116a3ba60467dd56b8fbcfb5 100644 (file)
@@ -742,8 +742,7 @@ static void selectInnerLoop(
     }else{
       ecelFlags = 0;
     }
-    assert( eDest!=SRT_Table || pSort==0 );
-    if( pSort && hasDistinct==0 && eDest!=SRT_EphemTab ){
+    if( pSort && hasDistinct==0 && eDest!=SRT_EphemTab && eDest!=SRT_Table ){
       /* For each expression in pEList that is a copy of an expression in
       ** the ORDER BY clause (pSort->pOrderBy), set the associated 
       ** iOrderByCol value to one more than the index of the ORDER BY 
@@ -1285,6 +1284,7 @@ static void generateSortTail(
     VdbeComment((v, "%s", aOutEx[i].zName ? aOutEx[i].zName : aOutEx[i].zSpan));
   }
   switch( eDest ){
+    case SRT_Table:
     case SRT_EphemTab: {
       sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, regRowid);
       sqlite3VdbeAddOp3(v, OP_Insert, iParm, regRow, regRowid);
index dedac41fc474dd816bf798a114fbdbcd4cc159c3..4d7996300745a89bd6d91de6dedc9300a59f2626 100644 (file)
@@ -14,6 +14,7 @@
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
+set testprefix selectC
 
 # Ticket #
 do_test selectC-1.1 {
@@ -233,4 +234,37 @@ do_execsql_test selectC-4.3 {
   select a, udf() from (select distinct a, b from t_distinct_bug)
 } {1 1 1 2 1 3}
 
+#-------------------------------------------------------------------------
+# Test that the problem in ticket #190c2507 has been fixed.
+#
+do_execsql_test 5.0 {
+  CREATE TABLE x1(a);
+  CREATE TABLE x2(b);
+  CREATE TABLE x3(c);
+  CREATE VIEW vvv AS SELECT b FROM x2 ORDER BY 1;
+
+  INSERT INTO x1 VALUES('a'), ('b');
+  INSERT INTO x2 VALUES(22), (23), (25), (24), (21);
+  INSERT INTO x3 VALUES(302), (303), (301);
+}
+
+do_execsql_test 5.1 {
+  CREATE TABLE x4 AS SELECT b FROM vvv UNION ALL SELECT c from x3;
+  SELECT * FROM x4;
+} {21 22 23 24 25 302 303 301}
+
+do_execsql_test 5.2 {
+  SELECT * FROM x1, x4
+} {
+  a 21 a 22 a 23 a 24 a 25 a 302 a 303 a 301
+  b 21 b 22 b 23 b 24 b 25 b 302 b 303 b 301
+}
+
+do_execsql_test 5.3 {
+  SELECT * FROM x1, (SELECT b FROM vvv UNION ALL SELECT c from x3);
+} {
+  a 21 a 22 a 23 a 24 a 25 a 302 a 303 a 301
+  b 21 b 22 b 23 b 24 b 25 b 302 b 303 b 301
+}
+
 finish_test