Fix the query flattener so that it refuses a flattening that might leave both
an inner-join and outer-join ON-clause constraint (or equivalent) on the same term of the FROM clause. FossilOrigin-Name: f6c4fb48b65c2e8659aa0a1119c330e8bad5e42b2db2030850bfc9c04afef5c8
This commit is contained in:
commit
40357f0d5d
18
manifest
18
manifest
@ -1,5 +1,5 @@
|
||||
C Do\snot\sallow\sa\spartial\sindex\sscan\son\sthe\sleft\stable\sof\sa\sRIGHT\sJOIN,\sbecause\nsince\sthe\sindex\sis\spartial,\ssome\srows\swill\sbe\somitted\sfrom\sthe\sscan,\sand\nthose\srows\swill\ssubsequently\sbe\spicked\sup\sby\sthe\sno-match\slogic\sin\sthe\nright-join\spost-processing\sloop.\n[forum:/forumpost/c4676c4956|forum\spost\sc4676c4956].
|
||||
D 2022-06-08T12:46:58.728
|
||||
C Fix\sthe\squery\sflattener\sso\sthat\sit\srefuses\sa\sflattening\sthat\smight\sleave\sboth\nan\sinner-join\sand\souter-join\sON-clause\sconstraint\s(or\sequivalent)\son\sthe\ssame\nterm\sof\sthe\sFROM\sclause.
|
||||
D 2022-06-08T15:38:16.780
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@ -570,12 +570,12 @@ F src/printf.c 6166a30417b05c5b2f82e1f183f75faa2926ad60531c0b688a57dbc951441a20
|
||||
F src/random.c 097dc8b31b8fba5a9aca1697aeb9fd82078ec91be734c16bffda620ced7ab83c
|
||||
F src/resolve.c a4eb3c617027fd049b07432f3b942ea7151fa793a332a11a7d0f58c9539e104f
|
||||
F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
|
||||
F src/select.c 37d984cb3e007349ee5da55b3f3c9196e032e08938c9a58fd272acf1df873e61
|
||||
F src/select.c 0271d9099df40f210c45881ae6ce92e37d6a0e5d505179c56591383ebfb27844
|
||||
F src/shell.c.in 5d5f27f88c4661b2b6e6859890e9c7fe00eac9a628743a12c44632705fc38309
|
||||
F src/sqlite.h.in 172528c287399a34f188154017b7268bf82c6d5b780902e361958d2318c4e37c
|
||||
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
|
||||
F src/sqlite3ext.h a988810c9b21c0dc36dc7a62735012339dc76fc7ab448fb0792721d30eacb69d
|
||||
F src/sqliteInt.h bc88540ae44fa1a88c41b94bea247ff16709e95f0a81a1382a629e71f6b28426
|
||||
F src/sqliteInt.h 8353e96646372efdb0795a13cd9949831b4992c928de8f5c43b2524e8a4c6e7b
|
||||
F src/sqliteLimit.h d7323ffea5208c6af2734574bae933ca8ed2ab728083caa117c9738581a31657
|
||||
F src/status.c 4a3da6d77eeb3531cb0dbdf7047772a2a1b99f98c69e90ce009c75fe6328b2c0
|
||||
F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1
|
||||
@ -635,7 +635,7 @@ F src/test_window.c cdae419fdcea5bad6dcd9368c685abdad6deb59e9fc8b84b153de513d394
|
||||
F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
|
||||
F src/threads.c 4ae07fa022a3dc7c5beb373cf744a85d3c5c6c3c
|
||||
F src/tokenize.c a38f52058b517929e264094abd0b5fd1e8e145a1aa43bc6f6a72ae5218f96c98
|
||||
F src/treeview.c 73facf395c8841653b9a54e789d8c80e15bc3d0d1cb9d16104c2d889c15e33cd
|
||||
F src/treeview.c c48bbb4b04a951dcecf95b464d0fe94930339af56688a77f18ee50a526bc1706
|
||||
F src/trigger.c 61bea163b1fa3039bc572ed8312461b978e5c527e5301f302b078f4c1ccdec6a
|
||||
F src/update.c 2cfaded82ca80ff56afb8c3ae5e88284e0824bfd86119827cc22481959f96f92
|
||||
F src/upsert.c 8789047a8f0a601ea42fa0256d1ba3190c13746b6ba940fe2d25643a7e991937
|
||||
@ -1159,7 +1159,7 @@ F test/ioerr4.test f130fe9e71008577b342b8874d52984bd04ede2c
|
||||
F test/ioerr5.test 2edfa4fb0f896f733071303b42224df8bedd9da4
|
||||
F test/ioerr6.test a395a6ab144b26a9e3e21059a1ab6a7149cca65b
|
||||
F test/istrue.test e7f285bb70282625c258e866ce6337d4c762922f5a300e1b50f958aef6e7d9c9
|
||||
F test/join.test edeaff6edc1c1a2bcfebee343744e04d000f861c3d67cb653114f88565f8c955
|
||||
F test/join.test 5c7f917aa219a125d1df517d3df384c79f74860fdfb2e48c0a599f1e2b3e9ed8
|
||||
F test/join2.test 466b07233820f5deee66a6c3bf6e4500c8bbf7b83649e67606f5f649c07928c0
|
||||
F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0
|
||||
F test/join4.test 1a352e4e267114444c29266ce79e941af5885916
|
||||
@ -1975,8 +1975,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 ccbd6e774903f9202f9311954979f6fcc3b13eba1f3402a549a7aee6ed1d55eb
|
||||
R 9e5b91eaa709a211969f755ac60f2577
|
||||
P 615c0026119f7870c3b6ef9dcb57ce4ecf5acedea3e2b5cfc25aa450eb8f17a0 c585d6a4678b04f4cedc08852d01c44cdf52ae2c8ccd1174c3d5a395088bf528
|
||||
R f8496d9bd26e20227061fd94e4abecc2
|
||||
U drh
|
||||
Z 3fabe8df6bd5cac6e030c1017487aca1
|
||||
Z a75cd30dd4ee2a42502920737fd40d74
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
@ -1 +1 @@
|
||||
615c0026119f7870c3b6ef9dcb57ce4ecf5acedea3e2b5cfc25aa450eb8f17a0
|
||||
f6c4fb48b65c2e8659aa0a1119c330e8bad5e42b2db2030850bfc9c04afef5c8
|
20
src/select.c
20
src/select.c
@ -610,6 +610,7 @@ static int sqlite3ProcessJoin(Parse *pParse, Select *p){
|
||||
sqlite3SetJoinExpr(pRight->u3.pOn, pRight->iCursor, joinType);
|
||||
p->pWhere = sqlite3ExprAnd(pParse, p->pWhere, pRight->u3.pOn);
|
||||
pRight->u3.pOn = 0;
|
||||
pRight->fg.isOn = 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@ -4169,6 +4170,11 @@ static void renumberCursors(
|
||||
**
|
||||
** (28) The subquery is not a MATERIALIZED CTE.
|
||||
**
|
||||
** (29) Either the subquery is not the right-hand operand of a join with an
|
||||
** ON or USING clause nor the right-hand operand of a NATURAL JOIN, or
|
||||
** the right-most table within the FROM clause of the subquery
|
||||
** is not part of an outer join.
|
||||
**
|
||||
**
|
||||
** In this routine, the "p" parameter is a pointer to the outer query.
|
||||
** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query
|
||||
@ -4296,6 +4302,20 @@ static int flattenSubquery(
|
||||
return 0; /* (28) */
|
||||
}
|
||||
|
||||
if( pSubSrc->nSrc>=2
|
||||
&& (pSubSrc->a[pSubSrc->nSrc-1].fg.jointype & JT_OUTER)!=0
|
||||
){
|
||||
/* Reach here if the right-most term in the FROM clause of the subquery
|
||||
** is an outer join - the second half of (29) */
|
||||
if( pSubitem->fg.jointype & JT_NATURAL
|
||||
|| pSubitem->fg.isUsing
|
||||
|| pSubitem->u3.pOn!=0
|
||||
|| pSubitem->fg.isOn
|
||||
){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Restriction (17): If the sub-query is a compound SELECT, then it must
|
||||
** use only the UNION ALL operator. And none of the simple select queries
|
||||
** that make up the compound SELECT are allowed to be aggregate or distinct
|
||||
|
@ -3101,6 +3101,7 @@ struct SrcItem {
|
||||
unsigned isCte :1; /* This is a CTE */
|
||||
unsigned notCte :1; /* This item may not match a CTE */
|
||||
unsigned isUsing :1; /* u3.pUsing is valid */
|
||||
unsigned isOn :1; /* u3.pOn was once valid and non-NULL */
|
||||
unsigned isSynthUsing :1; /* u3.pUsing is synthensized from NATURAL */
|
||||
unsigned isNestedFrom :1; /* pSelect is a SF_NestedFrom subquery */
|
||||
} fg;
|
||||
|
@ -215,6 +215,9 @@ void sqlite3TreeViewSrcList(TreeView *pView, const SrcList *pSrc){
|
||||
if( pItem->fg.isCte ){
|
||||
sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse);
|
||||
}
|
||||
if( pItem->fg.isOn || (pItem->fg.isUsing==0 && pItem->u3.pOn!=0) ){
|
||||
sqlite3_str_appendf(&x, " ON");
|
||||
}
|
||||
sqlite3StrAccumFinish(&x);
|
||||
sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
|
||||
n = 0;
|
||||
|
@ -1067,4 +1067,38 @@ do_catchsql_test join-26.1 {
|
||||
SELECT * FROM t5 JOIN ((t4 JOIN (t5 JOIN t6)) t7);
|
||||
} {/1 {.*}/}
|
||||
|
||||
# 2022-06-09 Invalid subquery flattening caused by
|
||||
# check-in 3f45007d544e5f78 and detected by dbsqlfuzz
|
||||
#
|
||||
reset_db
|
||||
do_execsql_test join-27.1 {
|
||||
CREATE TABLE t1(a INT,b INT,c INT); INSERT INTO t1 VALUES(NULL,NULL,NULL);
|
||||
CREATE TABLE t2(d INT,e INT); INSERT INTO t2 VALUES(NULL,NULL);
|
||||
CREATE INDEX x2 ON t1(c,b);
|
||||
CREATE TABLE t3(x INT); INSERT INTO t3 VALUES(NULL);
|
||||
}
|
||||
do_execsql_test join-27.2 {
|
||||
WITH t99(b) AS MATERIALIZED (
|
||||
SELECT b FROM t2 LEFT JOIN t1 ON c IN (SELECT x FROM t3)
|
||||
)
|
||||
SELECT 5 FROM t2 JOIN t99 ON b IN (1,2,3);
|
||||
} {}
|
||||
do_execsql_test join-27.3 {
|
||||
WITH t99(b) AS NOT MATERIALIZED (
|
||||
SELECT b FROM t2 LEFT JOIN t1 ON c IN (SELECT x FROM t3)
|
||||
)
|
||||
SELECT 5 FROM t2 JOIN t99 ON b IN (1,2,3);
|
||||
} {}
|
||||
do_execsql_test join-27.4 {
|
||||
WITH t99(b) AS (SELECT b FROM t2 LEFT JOIN t1 ON c IN (SELECT x FROM t3))
|
||||
SELECT 5 FROM t2 JOIN t99 ON b IN (1,2,3);
|
||||
} {}
|
||||
do_execsql_test join-27.5 {
|
||||
SELECT 5
|
||||
FROM t2 JOIN (
|
||||
SELECT b FROM t2 LEFT JOIN t1 ON c IN (SELECT x FROM t3)
|
||||
) AS t99 ON b IN (1,2,3);
|
||||
} {}
|
||||
|
||||
|
||||
finish_test
|
||||
|
Loading…
Reference in New Issue
Block a user