Improved detection of when the LEFT JOIN strength reduction optimization

can be applied.

FossilOrigin-Name: f544a8e47cdd5ad7233887a558489983f4f305a39391ff463c43e2e4157da087
This commit is contained in:
drh 2023-05-31 18:35:12 +00:00
parent d3b54d624f
commit 29e70da4a4
4 changed files with 39 additions and 19 deletions

View File

@ -1,5 +1,5 @@
C Minor\senhancement\sto\sthe\ssqlite3_trace_v2()\sdocumentation.\s\sNo\scode\nchanges.
D 2023-05-31T12:42:09.417
C Improved\sdetection\sof\swhen\sthe\sLEFT\sJOIN\sstrength\sreduction\soptimization\ncan\sbe\sapplied.
D 2023-05-31T18:35:12.759
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -587,7 +587,7 @@ F src/date.c cb71f73d5df5303ec6630971b9c8b8c7df466fa3233dbdc643d613806e53e554
F src/dbpage.c f3eea5f7ec47e09ee7da40f42b25092ecbe961fc59566b8e5f705f34335b2387
F src/dbstat.c ec92074baa61d883de58c945162d9e666c13cd7cf3a23bc38b4d1c4d0b2c2bef
F src/delete.c 05e27e3a55dcfeadf2f7ca95a5c5e0928f182c04640ec1954ffa42f3d5c19341
F src/expr.c 83bbb161972e74ee3efed50d817b8489242dc30b10a1831e2b23676a518bddb4
F src/expr.c 0081058153a329c21204efd87c6f25bcbc2d70d2d9fd4441c7824778cd056ef3
F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
F src/fkey.c 03c134cc8bffe54835f742ddea0b72ebfc8f6b32773d175c71b8afeea6cb5c83
F src/func.c 03e6b501f3056d0ba398bda17df938b2b566aa0b3ca7e1942a3cd1925d04ec36
@ -1236,7 +1236,7 @@ F test/join.test f7abfef3faeaf2800308872e33a57e5b6e4a2b44fb8c6b90c6068412e71a6cf
F test/join2.test 8561fe82ce434ac96de91544072e578dc2cadddf2d9bc9cd802f866a9b92502e
F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0
F test/join4.test 1a352e4e267114444c29266ce79e941af5885916
F test/join5.test 91f1f4c7d81fd87b58e9ba7cf4a2b5d39e3583b4f8e498a162722a60259c5208
F test/join5.test 7cc3f3595bb41e60f3f96d5cb6dd8cfcbc31212f0136bba6fc081c082994a94a
F test/join6.test f809c025fa253f9e150c0e9afd4cef8813257bceeb6f46e04041228c9403cc2c
F test/join7.test 2268dcbb54b724391dda3748ea95c60d960607ffeed67885675998e7117697f6
F test/join8.test d384d63985e3991c404afccadaf3efd1cdf9cd72680167f80e3cb80b95c18c68
@ -2072,8 +2072,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 5a516c6c7a25cec4d0a0cca530017a3299f7a332319f3e1f7cf12f53c32b88ca
R cacc8a191b93d60c3dec13cca68a7ad7
P fba97230e38276f2a02fc24353c3d911dfa24f3a4f75f691de9461d4daf3ae54
R 720aef041ed3aa114fee5b5cb6f34a65
U drh
Z b50e82fb9b47f682e06c6896a0420558
Z d35ccb01f44f9df429a5fed4d723f477
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
fba97230e38276f2a02fc24353c3d911dfa24f3a4f75f691de9461d4daf3ae54
f544a8e47cdd5ad7233887a558489983f4f305a39391ff463c43e2e4157da087

View File

@ -6009,23 +6009,18 @@ static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
case TK_ISNULL:
case TK_NOTNULL:
case TK_IS:
case TK_OR:
case TK_VECTOR:
case TK_CASE:
case TK_IN:
case TK_FUNCTION:
case TK_TRUTH:
testcase( pExpr->op==TK_ISNOT );
testcase( pExpr->op==TK_ISNULL );
testcase( pExpr->op==TK_NOTNULL );
testcase( pExpr->op==TK_IS );
testcase( pExpr->op==TK_OR );
testcase( pExpr->op==TK_VECTOR );
testcase( pExpr->op==TK_CASE );
testcase( pExpr->op==TK_IN );
testcase( pExpr->op==TK_FUNCTION );
testcase( pExpr->op==TK_TRUTH );
return WRC_Prune;
case TK_COLUMN:
if( pWalker->u.iCur==pExpr->iTable ){
pWalker->eCode = 1;
@ -6033,7 +6028,10 @@ static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
}
return WRC_Prune;
case TK_OR:
case TK_AND:
testcase( pExpr->op==TK_OR );
testcase( pExpr->op==TK_AND );
if( pWalker->eCode==0 ){
sqlite3WalkExpr(pWalker, pExpr->pLeft);
if( pWalker->eCode ){
@ -6043,11 +6041,13 @@ static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
}
return WRC_Prune;
case TK_CASE:
case TK_IN:
case TK_BETWEEN:
if( sqlite3WalkExpr(pWalker, pExpr->pLeft)==WRC_Abort ){
assert( pWalker->eCode );
return WRC_Abort;
}
testcase( pExpr->op==TK_CASE );
testcase( pExpr->op==TK_IN );
testcase( pExpr->op==TK_BETWEEN );
sqlite3WalkExpr(pWalker, pExpr->pLeft);
return WRC_Prune;
/* Virtual tables are allowed to use constraints like x=NULL. So

View File

@ -302,14 +302,34 @@ do_execsql_test 7.3 {
ANALYZE sqlite_schema;
}
# If both sides of the OR reference the right-hand side of the LEFT JOIN
# then simplify the LEFT JOIN.
#
do_eqp_test 7.4 {
SELECT * FROM t3 LEFT JOIN t4 ON (t4.x = t3.x) WHERE (t4.y = ? OR t4.z = ?);
} {
QUERY PLAN
|--SCAN t4
`--SEARCH t3 USING COVERING INDEX t3x (x=?)
}
# If only one side of the OR references the right-hand side of the LEFT JOIN
# then do not do the simplification
#
do_eqp_test 7.4b {
SELECT * FROM t3 LEFT JOIN t4 ON (t4.x = t3.x) WHERE (t4.y = ? OR t3.x = ?);
} {
QUERY PLAN
|--SCAN t3
`--SEARCH t4 USING INDEX t4xz (x=?) LEFT-JOIN
}
do_eqp_test 7.4b {
do_eqp_test 7.4c {
SELECT * FROM t3 LEFT JOIN t4 ON (t4.x = t3.x) WHERE (t3.x = ? OR t4.z = ?);
} {
QUERY PLAN
|--SCAN t3
`--SEARCH t4 USING INDEX t4xz (x=?) LEFT-JOIN
}
do_eqp_test 7.4d {
SELECT * FROM t3 CROSS JOIN t4 ON (t4.x = t3.x) WHERE (+t4.y = ? OR t4.z = ?);
} {
QUERY PLAN