From: drh Date: Sat, 11 May 2019 19:36:03 +0000 (+0000) Subject: A new implementation for the sqlite3ExprImpliesExpr() theorem prover that X-Git-Tag: version-3.29.0~105 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c51cf8642f867050c8cb9e330582605dabeff76c;p=thirdparty%2Fsqlite.git A new implementation for the sqlite3ExprImpliesExpr() theorem prover that does a better job of answering TRUE to "(NOT A) OR B" when B is a NOT NULL expression. FossilOrigin-Name: b3413197f57711f04102d8cc6ff1e8ddbe0f5f2bcb6e1989cf314fa97f0ff7f1 --- diff --git a/manifest b/manifest index 2f69eeca87..2b05533af9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sconsidering\spartial\sindexes,\sdo\snot\sassume\sthat\sa\s"CASE\sx\s..."\sexpression\simplies\s"x\sIS\sNOT\sNULL". -D 2019-05-11T16:14:42.493 +C A\snew\simplementation\sfor\sthe\ssqlite3ExprImpliesExpr()\stheorem\sprover\sthat\ndoes\sa\sbetter\sjob\sof\sanswering\sTRUE\sto\s"(NOT\sA)\sOR\sB"\swhen\sB\sis\sa\sNOT\sNULL\nexpression. +D 2019-05-11T19:36:03.376 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -473,7 +473,7 @@ F src/date.c ebe1dc7c8a347117bb02570f1a931c62dd78f4a2b1b516f4837d45b7d6426957 F src/dbpage.c 135eb3b5e74f9ef74bde5cec2571192c90c86984fa534c88bf4a055076fa19b7 F src/dbstat.c c12833de69cb655751487d2c5a59607e36be1c58ba1f4bd536609909ad47b319 F src/delete.c d08c9e01a2664afd12edcfa3a9c6578517e8ff8735f35509582693adbe0edeaf -F src/expr.c de746e2fc5ee48441b1210fba9a39160981718430e6a75b3a2ba29a99957cb71 +F src/expr.c a41e5a03d60e2d99a8eac1535f21258e3833b29a3f52789e76284d97b54bed5f F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 0e14d4bef8eac2d87bbd517e492d9084c65008d117823f8922c5e7b2b599bd33 F src/func.c 08d6d07d138735dd79f12a2b0c623d1dc9270d0eea61b8be584625391ef84475 @@ -1825,7 +1825,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 0ba6d709b50d92db1542f2ff30535a80184b00dadf759d51e5cae7a6e37b1764 -R eed45e78e88ca93286620dd3277355ae -U dan -Z 697971a2288076e83fc4830e959d8147 +P 1b24303220b7b4f59520176a0150fc619c668865450b4fdaa9ce4113a56e9687 +R a0d6bf1f0575775c4809b4d1861fc898 +U drh +Z 5104434a3315d7327fcd08f55bb43328 diff --git a/manifest.uuid b/manifest.uuid index a33bef3c01..dad98559cb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1b24303220b7b4f59520176a0150fc619c668865450b4fdaa9ce4113a56e9687 \ No newline at end of file +b3413197f57711f04102d8cc6ff1e8ddbe0f5f2bcb6e1989cf314fa97f0ff7f1 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 05b50c1e62..a905c28c9b 100644 --- a/src/expr.c +++ b/src/expr.c @@ -4908,6 +4908,76 @@ int sqlite3ExprCompareSkip(Expr *pA, Expr *pB, int iTab){ iTab); } +/* +** Return non-zero if Expr p can only be true if pNN is not NULL. +*/ +static int exprImpliesNotNull( + Parse *pParse, /* Parsing context */ + Expr *p, /* The expression to be checked */ + Expr *pNN, /* The expression that is NOT NULL */ + int iTab, /* Table being evaluated */ + int seenNot /* True if p is an operand of NOT */ +){ + assert( p ); + assert( pNN ); + if( sqlite3ExprCompare(pParse, p, pNN, iTab)==0 ) return 1; + switch( p->op ){ + case TK_IN: { + if( seenNot && ExprHasProperty(p, EP_xIsSelect) ) return 0; + assert( ExprHasProperty(p,EP_xIsSelect) + || (p->x.pList!=0 && p->x.pList->nExpr>0) ); + return exprImpliesNotNull(pParse, p->pLeft, pNN, iTab, seenNot); + } + case TK_BETWEEN: { + ExprList *pList = p->x.pList; + assert( pList!=0 ); + assert( pList->nExpr==2 ); + if( seenNot ) return 0; + if( exprImpliesNotNull(pParse, pList->a[0].pExpr, pNN, iTab, seenNot) + || exprImpliesNotNull(pParse, pList->a[1].pExpr, pNN, iTab, seenNot) + ){ + return 1; + } + return exprImpliesNotNull(pParse, p->pLeft, pNN, iTab, seenNot); + } + case TK_EQ: + case TK_NE: + case TK_LT: + case TK_LE: + case TK_GT: + case TK_GE: + case TK_PLUS: + case TK_MINUS: + case TK_STAR: + case TK_REM: + case TK_BITAND: + case TK_BITOR: + case TK_SLASH: + case TK_LSHIFT: + case TK_RSHIFT: + case TK_CONCAT: { + if( exprImpliesNotNull(pParse, p->pRight, pNN, iTab, seenNot) ) return 1; + /* Fall thru into the next case */ + } + case TK_SPAN: + case TK_COLLATE: + case TK_BITNOT: + case TK_UPLUS: + case TK_UMINUS: { + return exprImpliesNotNull(pParse, p->pLeft, pNN, iTab, seenNot); + } + case TK_TRUTH: { + if( seenNot ) return 0; + if( p->op2!=TK_IS ) return 0; + return exprImpliesNotNull(pParse, p->pLeft, pNN, iTab, seenNot); + } + case TK_NOT: { + return exprImpliesNotNull(pParse, p->pLeft, pNN, iTab, 1); + } + } + return 0; +} + /* ** Return true if we can prove the pE2 will always be true if pE1 is ** true. Return false if we cannot complete the proof or if pE2 might @@ -4944,15 +5014,9 @@ int sqlite3ExprImpliesExpr(Parse *pParse, Expr *pE1, Expr *pE2, int iTab){ return 1; } if( pE2->op==TK_NOTNULL - && pE1->op!=TK_ISNULL - && pE1->op!=TK_IS - && pE1->op!=TK_ISNOT - && pE1->op!=TK_OR - && pE1->op!=TK_CASE + && exprImpliesNotNull(pParse, pE1, pE2->pLeft, iTab, 0) ){ - Expr *pX = sqlite3ExprSkipCollate(pE1->pLeft); - testcase( pX!=pE1->pLeft ); - if( sqlite3ExprCompare(pParse, pX, pE2->pLeft, iTab)==0 ) return 1; + return 1; } return 0; }