]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Bug fix in the LEFT JOIN strength reduction optimization of
authordrh <drh@noemail.net>
Sat, 24 Mar 2018 13:24:02 +0000 (13:24 +0000)
committerdrh <drh@noemail.net>
Sat, 24 Mar 2018 13:24:02 +0000 (13:24 +0000)
check-in [dd568c27b1d76563].  The sqlite3ExprImpliesNotNull() routine was
mistakenly assuming that a CASE expression must always be NULL if contained
any reference to a variable that was NULL.

FossilOrigin-Name: cf171abe954a5f25262161dd69f2e8cecdbf9446c3f6b298201507dbc743567e

manifest
manifest.uuid
src/expr.c
test/join.test

index 7a73eed6171effc0c94ad32c6df8d0fd0a22c6e0..2230b97f25488d3b158c695f35553005fcf84d37 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Prepend\slinkage\smacros\sto\sthe\ssqlite3rebaser\sinterfaces.
-D 2018-03-24T00:19:18.417
+C Bug\sfix\sin\sthe\sLEFT\sJOIN\sstrength\sreduction\soptimization\sof\ncheck-in\s[dd568c27b1d76563].\s\sThe\ssqlite3ExprImpliesNotNull()\sroutine\swas\nmistakenly\sassuming\sthat\sa\sCASE\sexpression\smust\salways\sbe\sNULL\sif\scontained\nany\sreference\sto\sa\svariable\sthat\swas\sNULL.
+D 2018-03-24T13:24:02.696
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3
@@ -443,7 +443,7 @@ F src/date.c ebe1dc7c8a347117bb02570f1a931c62dd78f4a2b1b516f4837d45b7d6426957
 F src/dbpage.c 8db4c97f630e7d83f884ea75caf1ffd0988c160e9d530194d93721c80821e0f6
 F src/dbstat.c 7a4ba8518b6369ef3600c49cf9c918ad979acba610b2aebef1b656d649b96720
 F src/delete.c 20c8788451dc737a967c87ea53ad43544d617f5b57d32ccce8bd52a0daf9e89b
-F src/expr.c 21ba8e1f8b9bc035053941d4f8df3ca5376be5e63ff62f945c2bc4f9b8890362
+F src/expr.c c370003225a891f2adf2bb0366655734a2433dfc53160b4f1c979459e6db278d
 F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
 F src/fkey.c d617daf66b5515e2b42c1405b2b4984c30ca50fb705ab164271a9bf66c69e331
 F src/func.c 94f42cba2cc1c34aeaa441022ba0170ec3fec4bba54db4e0ded085c6dc0fdc51
@@ -1005,7 +1005,7 @@ F test/ioerr4.test f130fe9e71008577b342b8874d52984bd04ede2c
 F test/ioerr5.test 2edfa4fb0f896f733071303b42224df8bedd9da4
 F test/ioerr6.test a395a6ab144b26a9e3e21059a1ab6a7149cca65b
 F test/istrue.test d6e659764da5ccc03adcdba18fe77d7917ba5e4abd04ef14bd4e4cf43e024b5b
-F test/join.test 442c462eea85cf065d70a663c626b780a95af6e11585d909bb63b87598afe678
+F test/join.test cffed24d43d2aef94aa2d853458246cb6178498ba47801040d8a5e85a0283bbe
 F test/join2.test 2339e3a8089178607a718c7fa1f6c3826579132396f5304a0f8e9dbefa60c84f
 F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0
 F test/join4.test 1a352e4e267114444c29266ce79e941af5885916
@@ -1717,7 +1717,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 de974235a8fefab0d08673c1b1da4e425e1d8bbfc8c35dac30943c05337b2950
-R d4bdb1788d4d4dfb03fac1718122533d
+P c64e8f377fe4fa321ebd04806cc27b19287e6fc3523b9988c0a70cad9fce1c18
+R ee78cea46d41e1faef615dfed55546a7
 U drh
-Z 6b81992f6d9930cde8e20b5fb53471c1
+Z 1b638429618a7e928141a9385c5b609e
index 99df632900985c6b4413b602b46fbfc62fe7a8b9..3c06975adc0fc939dfea16add24ae2faafdf11e7 100644 (file)
@@ -1 +1 @@
-c64e8f377fe4fa321ebd04806cc27b19287e6fc3523b9988c0a70cad9fce1c18
\ No newline at end of file
+cf171abe954a5f25262161dd69f2e8cecdbf9446c3f6b298201507dbc743567e
\ No newline at end of file
index 0bb7a8d8f9a41d06c0fbb6e9a7698e44423f93a1..c09c0c56ce329f13406672b733aa81e6ba9edec3 100644 (file)
@@ -5012,6 +5012,7 @@ static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
     case TK_ISNULL:
     case TK_IS:
     case TK_OR:
+    case TK_CASE:
     case TK_FUNCTION:
     case TK_AGG_FUNCTION:
       return WRC_Prune;
index 4df586d8ab918e21ad46ad4b4563befba4bf63b5..35131fd3129f4e4a45e1d927f7447f6765b694da 100644 (file)
@@ -780,4 +780,53 @@ do_execsql_test join-14.20 {
   LEFT JOIN t3 AS x3 ON x2.id=x3.c3;
 } {456 {} {}}
 
+# 2018-03-24.
+# E.Pasma discovered that the LEFT JOIN strength reduction optimization
+# was misbehaving.  The problem turned out to be that the
+# sqlite3ExprImpliesNotNull() routine was saying that CASE expressions
+# like
+#
+#     CASE WHEN true THEN true ELSE x=0 END
+#
+# could never be true if x is NULL.  The following test cases verify
+# that this error has been resolved.
+#
+db close
+sqlite3 db :memory:
+do_execsql_test join-15.100 {
+  CREATE TABLE t1(a INT, b INT);
+  INSERT INTO t1 VALUES(1,2),(3,4);
+  CREATE TABLE t2(x INT, y INT);
+  SELECT *, 'x'
+    FROM t1 LEFT JOIN t2
+   WHERE CASE WHEN FALSE THEN a=x ELSE 1 END;
+} {1 2 {} {} x 3 4 {} {} x}
+do_execsql_test join-15.110 {
+  DROP TABLE t1;
+  DROP TABLE t2;
+  CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER);
+  INSERT INTO t1(a,b) VALUES(1,0),(11,1),(12,1),(13,1),(121,12);
+  CREATE INDEX t1b ON t1(b);
+  CREATE TABLE t2(x INTEGER PRIMARY KEY);
+  INSERT INTO t2(x) VALUES(0),(1);
+  SELECT  a1, a2, a3, a4, a5
+   FROM (SELECT a AS a1 FROM t1 WHERE b=0)
+        JOIN (SELECT x AS x1 FROM t2)
+        LEFT JOIN (SELECT a AS a2, b AS b2 FROM t1)
+          ON x1 IS TRUE AND b2=a1
+        JOIN (SELECT x AS x2 FROM t2)
+          ON x2<=CASE WHEN x1 THEN CASE WHEN a2 THEN 1 ELSE -1 END ELSE 0 END
+        LEFT JOIN (SELECT a AS a3, b AS b3 FROM t1)
+          ON x2 IS TRUE AND b3=a2
+        JOIN (SELECT x AS x3 FROM t2)
+          ON x3<=CASE WHEN x2 THEN CASE WHEN a3 THEN 1 ELSE -1 END ELSE 0 END
+        LEFT JOIN (SELECT a AS a4, b AS b4 FROM t1)
+          ON x3 IS TRUE AND b4=a3
+        JOIN (SELECT x AS x4 FROM t2)
+          ON x4<=CASE WHEN x3 THEN CASE WHEN a4 THEN 1 ELSE -1 END ELSE 0 END
+        LEFT JOIN (SELECT a AS a5, b AS b5 FROM t1)
+          ON x4 IS TRUE AND b5=a4
+   ORDER BY a1, a2, a3, a4, a5;
+} {1 {} {} {} {} 1 11 {} {} {} 1 12 {} {} {} 1 12 121 {} {} 1 13 {} {} {}}
+
 finish_test