Ensure that the query planner knows that any column of a flattened LEFT JOIN

can be NULL even if that column is labeled with "NOT NULL".
Fix for ticket [892fc34f173e99d8].

FossilOrigin-Name: 483462682d3a57fb9dd85b4772596e9738f1694a454b8ebbc480b9452733e88d
This commit is contained in:
dan 2017-06-20 17:43:26 +00:00
parent 40db2fd7a3
commit bd11a2acbb
4 changed files with 32 additions and 12 deletions

View File

@ -1,5 +1,5 @@
C Fix\sa\smissing\scomma\sin\sthe\sprevious\scheck-in.
D 2017-06-17T18:49:50.823
C Ensure\sthat\sthe\squery\splanner\sknows\sthat\sany\scolumn\sof\sa\sflattened\sLEFT\sJOIN\ncan\sbe\sNULL\seven\sif\sthat\scolumn\sis\slabeled\swith\s"NOT\sNULL".\nFix\sfor\sticket\s[892fc34f173e99d8].
D 2017-06-20T17:43:26.613
F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc 8eeb80162074004e906b53d7340a12a14c471a83743aab975947e95ce061efcc
@ -405,7 +405,7 @@ F src/printf.c 8757834f1b54dae512fb25eb1acc8e94a0d15dd2290b58f2563f65973265adb2
F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
F src/resolve.c adf3ef9843135b1383321ad751f16f5a40c3f37925154555a3e61653d2a954e8
F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
F src/select.c 0d2afdbdba5fbc61432c5454a35e0236e7aa4aa3756986a7d51b81a508e8083a
F src/select.c 35ccfae64cecfa843d54a5898c4ab7d6595ce03d147267fa5eecdc8eab39cd6a
F src/shell.c bcd3358ad6cb3f3dc7ec76ad3bd8191f123ed2425360c5c48fe431780eceb729
F src/sqlite.h.in 67fa8bd29808e7988e0ce36c8d4c6043eb1727f94522fc612687aa5af51931e6
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
@ -908,7 +908,7 @@ F test/ioerr3.test d3cec5e1a11ad6d27527d0d38573fbff14c71bdd
F test/ioerr4.test f130fe9e71008577b342b8874d52984bd04ede2c
F test/ioerr5.test 2edfa4fb0f896f733071303b42224df8bedd9da4
F test/ioerr6.test a395a6ab144b26a9e3e21059a1ab6a7149cca65b
F test/join.test 302f164f4a41c240d16ebd780762834233be77b852f15232c9a48a6fe37ac0fa
F test/join.test 442c462eea85cf065d70a663c626b780a95af6e11585d909bb63b87598afe678
F test/join2.test a48f723c5692e2cbb23a9297ac2720cb77d51a70
F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0
F test/join4.test 1a352e4e267114444c29266ce79e941af5885916
@ -1583,7 +1583,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 9a443397a6b110f60cae32e1f758914d72931e16ddb423e4d4a119df526bf340
R 48cf46cf5e03c592f1eb729aae9e27b1
U drh
Z 1075564756c6da5b66b28900b7b4b32b
P f3db02f49073c3f08c3fd7816d85e5472d5e22df20d862fe4886eb2a97efb15f
R 65c6dcf56f692aabb1488a88a7fa82bd
U dan
Z a6ca5a5b1b0df383164124d4a74591e8

View File

@ -1 +1 @@
f3db02f49073c3f08c3fd7816d85e5472d5e22df20d862fe4886eb2a97efb15f
483462682d3a57fb9dd85b4772596e9738f1694a454b8ebbc480b9452733e88d

View File

@ -3205,9 +3205,12 @@ static Expr *substExpr(
pCopy = &ifNullRow;
}
pNew = sqlite3ExprDup(db, pCopy, 0);
if( pNew && (pExpr->flags & EP_FromJoin) ){
if( pNew && pSubst->isLeftJoin ){
ExprSetProperty(pNew, EP_CanBeNull);
}
if( pNew && ExprHasProperty(pExpr,EP_FromJoin) ){
pNew->iRightJoinTable = pExpr->iRightJoinTable;
pNew->flags |= EP_FromJoin;
ExprSetProperty(pNew, EP_FromJoin);
}
sqlite3ExprDelete(db, pExpr);
pExpr = pNew;
@ -3500,7 +3503,7 @@ static int flattenSubquery(
**
** If the subquery is the right operand of a LEFT JOIN, then the outer
** query cannot be an aggregate. This is an artifact of the way aggregates
** are processed - there is not mechanism to determine if the LEFT JOIN
** are processed - there is no mechanism to determine if the LEFT JOIN
** table should be all-NULL.
**
** See also tickets #306, #350, and #3300.

View File

@ -763,4 +763,21 @@ do_execsql_test join-14.12 {
SELECT *, '|' FROM t3 LEFT JOIN v2 ON a=x ORDER BY b;
} {4 {} {} | 2 2 1 |}
# Verify the fix for ticket
# https://www.sqlite.org/src/info/892fc34f173e99d8
#
db close
sqlite3 db :memory:
do_execsql_test join-14.20 {
CREATE TABLE t1(id INTEGER PRIMARY KEY);
CREATE TABLE t2(id INTEGER PRIMARY KEY, c2 INTEGER);
CREATE TABLE t3(id INTEGER PRIMARY KEY, c3 INTEGER);
INSERT INTO t1(id) VALUES(456);
INSERT INTO t3(id) VALUES(1),(2);
SELECT t1.id, x2.id, x3.id
FROM t1
LEFT JOIN (SELECT * FROM t2) AS x2 ON t1.id=x2.c2
LEFT JOIN t3 AS x3 ON x2.id=x3.c3;
} {456 {} {}}
finish_test