Do not allow a term in the WHERE clause of the query to qualify a partial
index on the right table of a LEFT JOIN. Ticket [7f39060a24b47353] FossilOrigin-Name: 4066a34da7bcdcece6c438c27f3a11bc49b8c8373b7e1603f30f6225e2bc800a
This commit is contained in:
parent
61cb4ed7f1
commit
ca7a26b5a1
14
manifest
14
manifest
@ -1,5 +1,5 @@
|
|||||||
C Add\scomments\sin\sthe\sparse.sql\sfile\sto\shelp\sdemonstrate\show\srules\sare\nencoded.
|
C Do\snot\sallow\sa\sterm\sin\sthe\sWHERE\sclause\sof\sthe\squery\sto\squalify\sa\spartial\nindex\son\sthe\sright\stable\sof\sa\sLEFT\sJOIN.\s\sTicket\s[7f39060a24b47353]
|
||||||
D 2019-11-29T13:01:57.677
|
D 2019-11-30T19:29:19.742
|
||||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||||
@ -612,7 +612,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
|
|||||||
F src/wal.c 15a2845769f51ba132f9cf0b2c7a6887a91fc8437892dbcce9fcdc68b66d60a1
|
F src/wal.c 15a2845769f51ba132f9cf0b2c7a6887a91fc8437892dbcce9fcdc68b66d60a1
|
||||||
F src/wal.h 606292549f5a7be50b6227bd685fa76e3a4affad71bb8ac5ce4cb5c79f6a176a
|
F src/wal.h 606292549f5a7be50b6227bd685fa76e3a4affad71bb8ac5ce4cb5c79f6a176a
|
||||||
F src/walker.c a137468bf36c92e64d2275caa80c83902e3a0fc59273591b96c6416d3253d05d
|
F src/walker.c a137468bf36c92e64d2275caa80c83902e3a0fc59273591b96c6416d3253d05d
|
||||||
F src/where.c 874845fb5d93b3bc07123df8fee805e9650bd091e3ed62988273c7e2141ab8bd
|
F src/where.c 2a5389e75730f2777801cc5b7bc65bc29ceb626217702c892964736d2275bc0c
|
||||||
F src/whereInt.h 4a296fd4fa79fdcbc2b5e8c1b898901617655811223e1082b899c23ecb092217
|
F src/whereInt.h 4a296fd4fa79fdcbc2b5e8c1b898901617655811223e1082b899c23ecb092217
|
||||||
F src/wherecode.c 909325b98d5cb313f24e5c8cb304a3e3c73ca6631cdb19cfa1f580dde182fedb
|
F src/wherecode.c 909325b98d5cb313f24e5c8cb304a3e3c73ca6631cdb19cfa1f580dde182fedb
|
||||||
F src/whereexpr.c 39b6a538804c6e1248c22b33e09d00f89ae6a099c849c4d841ce3995562287b4
|
F src/whereexpr.c 39b6a538804c6e1248c22b33e09d00f89ae6a099c849c4d841ce3995562287b4
|
||||||
@ -1083,7 +1083,7 @@ F test/ioerr4.test f130fe9e71008577b342b8874d52984bd04ede2c
|
|||||||
F test/ioerr5.test 2edfa4fb0f896f733071303b42224df8bedd9da4
|
F test/ioerr5.test 2edfa4fb0f896f733071303b42224df8bedd9da4
|
||||||
F test/ioerr6.test a395a6ab144b26a9e3e21059a1ab6a7149cca65b
|
F test/ioerr6.test a395a6ab144b26a9e3e21059a1ab6a7149cca65b
|
||||||
F test/istrue.test 75327829744e65cc8700e69340b8e6c192e10e39dfae7ccb0e970d3c4f49090a
|
F test/istrue.test 75327829744e65cc8700e69340b8e6c192e10e39dfae7ccb0e970d3c4f49090a
|
||||||
F test/join.test debdadab636bb35c73084902c12ce4d2012bfa7a5f8a2c693bb3ba13059f2224
|
F test/join.test f787ee2716efe5beeb9888d10630f917b112c32b6b3e612e48a17ea8aed3a8eb
|
||||||
F test/join2.test 10f7047e723ebd68b2f47189be8eed20451a6f665d8bf46f1774c640d1062417
|
F test/join2.test 10f7047e723ebd68b2f47189be8eed20451a6f665d8bf46f1774c640d1062417
|
||||||
F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0
|
F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0
|
||||||
F test/join4.test 1a352e4e267114444c29266ce79e941af5885916
|
F test/join4.test 1a352e4e267114444c29266ce79e941af5885916
|
||||||
@ -1851,7 +1851,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
|||||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||||
P 3a82c554c3bde4640df6865686f8f70e2c1e07c581fed4772b6b0a8ec1b10bb6
|
P 2c4f714892327a1a9a303267b1f9685e310cca5dcea9c61287d95e26291b0506
|
||||||
R 195e960e1bbc2b566cf81ba2c2725539
|
R d57d82e28b1d820fe0fa0d700752c88b
|
||||||
U drh
|
U drh
|
||||||
Z b39324cde45990609591babb79636823
|
Z fd88fafab2d1693d4af494080aae55d5
|
||||||
|
@ -1 +1 @@
|
|||||||
2c4f714892327a1a9a303267b1f9685e310cca5dcea9c61287d95e26291b0506
|
4066a34da7bcdcece6c438c27f3a11bc49b8c8373b7e1603f30f6225e2bc800a
|
15
src/where.c
15
src/where.c
@ -2790,12 +2790,17 @@ static int indexMightHelpWithOrderBy(
|
|||||||
/* Check to see if a partial index with pPartIndexWhere can be used
|
/* Check to see if a partial index with pPartIndexWhere can be used
|
||||||
** in the current query. Return true if it can be and false if not.
|
** in the current query. Return true if it can be and false if not.
|
||||||
*/
|
*/
|
||||||
static int whereUsablePartialIndex(int iTab, WhereClause *pWC, Expr *pWhere){
|
static int whereUsablePartialIndex(
|
||||||
|
int iTab, /* The table for which we want an index */
|
||||||
|
int isLeft, /* True if iTab is the right table of a LEFT JOIN */
|
||||||
|
WhereClause *pWC, /* The WHERE clause of the query */
|
||||||
|
Expr *pWhere /* The WHERE clause from the partial index */
|
||||||
|
){
|
||||||
int i;
|
int i;
|
||||||
WhereTerm *pTerm;
|
WhereTerm *pTerm;
|
||||||
Parse *pParse = pWC->pWInfo->pParse;
|
Parse *pParse = pWC->pWInfo->pParse;
|
||||||
while( pWhere->op==TK_AND ){
|
while( pWhere->op==TK_AND ){
|
||||||
if( !whereUsablePartialIndex(iTab,pWC,pWhere->pLeft) ) return 0;
|
if( !whereUsablePartialIndex(iTab,isLeft,pWC,pWhere->pLeft) ) return 0;
|
||||||
pWhere = pWhere->pRight;
|
pWhere = pWhere->pRight;
|
||||||
}
|
}
|
||||||
if( pParse->db->flags & SQLITE_EnableQPSG ) pParse = 0;
|
if( pParse->db->flags & SQLITE_EnableQPSG ) pParse = 0;
|
||||||
@ -2803,6 +2808,7 @@ static int whereUsablePartialIndex(int iTab, WhereClause *pWC, Expr *pWhere){
|
|||||||
Expr *pExpr;
|
Expr *pExpr;
|
||||||
pExpr = pTerm->pExpr;
|
pExpr = pTerm->pExpr;
|
||||||
if( (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab)
|
if( (!ExprHasProperty(pExpr, EP_FromJoin) || pExpr->iRightJoinTable==iTab)
|
||||||
|
&& (isLeft==0 || ExprHasProperty(pExpr, EP_FromJoin))
|
||||||
&& sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab)
|
&& sqlite3ExprImpliesExpr(pParse, pExpr, pWhere, iTab)
|
||||||
){
|
){
|
||||||
return 1;
|
return 1;
|
||||||
@ -2965,8 +2971,11 @@ static int whereLoopAddBtree(
|
|||||||
for(; rc==SQLITE_OK && pProbe;
|
for(; rc==SQLITE_OK && pProbe;
|
||||||
pProbe=(pSrc->pIBIndex ? 0 : pProbe->pNext), iSortIdx++
|
pProbe=(pSrc->pIBIndex ? 0 : pProbe->pNext), iSortIdx++
|
||||||
){
|
){
|
||||||
|
int isLeft = (pSrc->fg.jointype & JT_OUTER)!=0;
|
||||||
if( pProbe->pPartIdxWhere!=0
|
if( pProbe->pPartIdxWhere!=0
|
||||||
&& !whereUsablePartialIndex(pSrc->iCursor, pWC, pProbe->pPartIdxWhere) ){
|
&& !whereUsablePartialIndex(pSrc->iCursor, isLeft, pWC,
|
||||||
|
pProbe->pPartIdxWhere)
|
||||||
|
){
|
||||||
testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */
|
testcase( pNew->iTab!=pSrc->iCursor ); /* See ticket [98d973b8f5] */
|
||||||
continue; /* Partial index inappropriate for this query */
|
continue; /* Partial index inappropriate for this query */
|
||||||
}
|
}
|
||||||
|
@ -953,4 +953,26 @@ do_execsql_test join-20.2 {
|
|||||||
SELECT * FROM t0 LEFT JOIN t1 WHERE NULL IN (c1);
|
SELECT * FROM t0 LEFT JOIN t1 WHERE NULL IN (c1);
|
||||||
} {}
|
} {}
|
||||||
|
|
||||||
|
# 2019-11-30 ticket 7f39060a24b47353
|
||||||
|
# Do not allow a WHERE clause term to qualify a partial index on the
|
||||||
|
# right table of a LEFT JOIN.
|
||||||
|
#
|
||||||
|
do_execsql_test join-21.10 {
|
||||||
|
DROP TABLE t0;
|
||||||
|
DROP TABLE t1;
|
||||||
|
CREATE TABLE t0(aa);
|
||||||
|
CREATE TABLE t1(bb);
|
||||||
|
INSERT INTO t0(aa) VALUES (1);
|
||||||
|
INSERT INTO t1(bb) VALUES (1);
|
||||||
|
SELECT 11, * FROM t1 LEFT JOIN t0 WHERE aa ISNULL;
|
||||||
|
SELECT 12, * FROM t1 LEFT JOIN t0 WHERE +aa ISNULL;
|
||||||
|
SELECT 13, * FROM t1 LEFT JOIN t0 ON aa ISNULL;
|
||||||
|
SELECT 14, * FROM t1 LEFT JOIN t0 ON +aa ISNULL;
|
||||||
|
CREATE INDEX i0 ON t0(aa) WHERE aa ISNULL;
|
||||||
|
SELECT 21, * FROM t1 LEFT JOIN t0 WHERE aa ISNULL;
|
||||||
|
SELECT 22, * FROM t1 LEFT JOIN t0 WHERE +aa ISNULL;
|
||||||
|
SELECT 23, * FROM t1 LEFT JOIN t0 ON aa ISNULL;
|
||||||
|
SELECT 24, * FROM t1 LEFT JOIN t0 ON +aa ISNULL;
|
||||||
|
} {13 1 {} 14 1 {} 23 1 {} 24 1 {}}
|
||||||
|
|
||||||
finish_test
|
finish_test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user