Always enable the IS NOT NULL optimization, even if STAT4 is not enabled.
FossilOrigin-Name: fc98218cf69e63bdb9e5f154521a341508502cd8cfe04cb870cabee2d99e0cb3
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
C Fix\sa\sproblem\scaused\sby\susing\san\sSQL\svariable\sin\san\sOVER\sclause\swithin\sa\strigger\sprogram.
|
||||
D 2021-01-21T16:02:14.840
|
||||
C Always\senable\sthe\sIS\sNOT\sNULL\soptimization,\seven\sif\sSTAT4\sis\snot\senabled.
|
||||
D 2021-01-21T17:54:41.795
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@@ -629,9 +629,9 @@ F src/wal.c 69e770e96fd56cc21608992bf2c6f1f3dc5cf2572d0495c6a643b06c3a679f14
|
||||
F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a
|
||||
F src/walker.c d9c4e454ebb9499e908aa62d55b8994c375cf5355ac78f60d45af17f7890701c
|
||||
F src/where.c 0e6abb22a2323fec80b450825593c26a2ad8f4815d1ee3af9969d8f6144bf681
|
||||
F src/whereInt.h 9a3f577619f07700d16d89eeb2f3d94d6b7ed7f109c2dacf0ce8844921549506
|
||||
F src/whereInt.h ae03b5e3a4cca9bd9cb1b7d3c63faf8f1f177200fc8cecc87d3d0cab6ca338e6
|
||||
F src/wherecode.c a3a1aff30fe99a818d8e7c607980f033f40c68d890e03ed25838b9dbb7908bee
|
||||
F src/whereexpr.c a022b4f447c0fb0674e172a9a303537ea5055df60d579f99cec7ead18e8c453f
|
||||
F src/whereexpr.c 1f11bdd204ad021f5935df6e7726b4f1dbdd3157a4f31d0dafc9c457e5e545a8
|
||||
F src/window.c edd6f5e25a1e8f2b6f5305b7f5f7da7bb35f07f0d432b255b1d4c2fcab4205aa
|
||||
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
|
||||
F test/affinity2.test ce1aafc86e110685b324e9a763eab4f2a73f737842ec3b687bd965867de90627
|
||||
@@ -1898,8 +1898,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P d1873054d8e1006a370ea7891dbb9a62e7d36ce98cb92b58dcb0daf271265de3 4f676466e60ee2a420b7b2deace76f3a733ce1af278347428285715d9c67f022
|
||||
R 56f323b51c91a7109bc328027a56f7a2
|
||||
T +closed 4f676466e60ee2a420b7b2deace76f3a733ce1af278347428285715d9c67f022
|
||||
U dan
|
||||
Z af485d37bfb17e22d383f2711ee5f268
|
||||
P 02264ab6a02d6cc95cf865920bcbaf4307d034640e6e4f3371b009ae9818540e
|
||||
R 8df6cd517dfa239c965fc40092a79782
|
||||
T *branch * isnotnull-opt
|
||||
T *sym-isnotnull-opt *
|
||||
T -sym-trunk *
|
||||
U drh
|
||||
Z d06e074a8f142c72ee8a673bfd500f4d
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
02264ab6a02d6cc95cf865920bcbaf4307d034640e6e4f3371b009ae9818540e
|
||||
fc98218cf69e63bdb9e5f154521a341508502cd8cfe04cb870cabee2d99e0cb3
|
||||
+1
-5
@@ -270,11 +270,7 @@ struct WhereTerm {
|
||||
#define TERM_ORINFO 0x0010 /* Need to free the WhereTerm.u.pOrInfo object */
|
||||
#define TERM_ANDINFO 0x0020 /* Need to free the WhereTerm.u.pAndInfo obj */
|
||||
#define TERM_OR_OK 0x0040 /* Used during OR-clause processing */
|
||||
#ifdef SQLITE_ENABLE_STAT4
|
||||
# define TERM_VNULL 0x0080 /* Manufactured x>NULL or x<=NULL term */
|
||||
#else
|
||||
# define TERM_VNULL 0x0000 /* Disabled if not using stat4 */
|
||||
#endif
|
||||
#define TERM_VNULL 0x0080 /* Manufactured x>NULL or x<=NULL term */
|
||||
#define TERM_LIKEOPT 0x0100 /* Virtual terms from the LIKE optimization */
|
||||
#define TERM_LIKECOND 0x0200 /* Conditionally this LIKE operator term */
|
||||
#define TERM_LIKE 0x0400 /* The original LIKE operator */
|
||||
|
||||
+38
-40
@@ -1466,6 +1466,41 @@ static void exprAnalyze(
|
||||
}
|
||||
}
|
||||
|
||||
/* The form "x IS NOT NULL" can sometimes be evaluated more efficiently
|
||||
** as "x>NULL" if x is not an INTEGER PRIMARY KEY. So construct a
|
||||
** virtual term of that form.
|
||||
**
|
||||
** The virtual term must be tagged with TERM_VNULL.
|
||||
*/
|
||||
else if( pExpr->op==TK_NOTNULL ){
|
||||
if( pExpr->pLeft->op==TK_COLUMN
|
||||
&& pExpr->pLeft->iColumn>=0
|
||||
&& !ExprHasProperty(pExpr, EP_FromJoin)
|
||||
){
|
||||
Expr *pNewExpr;
|
||||
Expr *pLeft = pExpr->pLeft;
|
||||
int idxNew;
|
||||
WhereTerm *pNewTerm;
|
||||
|
||||
pNewExpr = sqlite3PExpr(pParse, TK_GT,
|
||||
sqlite3ExprDup(db, pLeft, 0),
|
||||
sqlite3ExprAlloc(db, TK_NULL, 0, 0));
|
||||
|
||||
idxNew = whereClauseInsert(pWC, pNewExpr,
|
||||
TERM_VIRTUAL|TERM_DYNAMIC|TERM_VNULL);
|
||||
if( idxNew ){
|
||||
pNewTerm = &pWC->a[idxNew];
|
||||
pNewTerm->prereqRight = 0;
|
||||
pNewTerm->leftCursor = pLeft->iTable;
|
||||
pNewTerm->u.x.leftColumn = pLeft->iColumn;
|
||||
pNewTerm->eOperator = WO_GT;
|
||||
markTermAsChild(pWC, idxNew, idxTerm);
|
||||
pTerm = &pWC->a[idxTerm];
|
||||
pTerm->wtFlags |= TERM_COPIED;
|
||||
pNewTerm->prereqAll = pTerm->prereqAll;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_LIKE_OPTIMIZATION
|
||||
/* Add constraints to reduce the search space on a LIKE or GLOB
|
||||
@@ -1637,7 +1672,9 @@ static void exprAnalyze(
|
||||
** This only works if the RHS is a simple SELECT (not a compound) that does
|
||||
** not use window functions.
|
||||
*/
|
||||
if( pWC->op==TK_AND && pExpr->op==TK_IN && pTerm->u.x.iField==0
|
||||
if( pWC->op==TK_AND
|
||||
&& pExpr->op==TK_IN
|
||||
&& pTerm->u.x.iField==0
|
||||
&& pExpr->pLeft->op==TK_VECTOR
|
||||
&& pExpr->x.pSelect->pPrior==0
|
||||
#ifndef SQLITE_OMIT_WINDOWFUNC
|
||||
@@ -1654,45 +1691,6 @@ static void exprAnalyze(
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SQLITE_ENABLE_STAT4
|
||||
/* When sqlite_stat4 histogram data is available an operator of the
|
||||
** form "x IS NOT NULL" can sometimes be evaluated more efficiently
|
||||
** as "x>NULL" if x is not an INTEGER PRIMARY KEY. So construct a
|
||||
** virtual term of that form.
|
||||
**
|
||||
** Note that the virtual term must be tagged with TERM_VNULL.
|
||||
*/
|
||||
if( pExpr->op==TK_NOTNULL
|
||||
&& pExpr->pLeft->op==TK_COLUMN
|
||||
&& pExpr->pLeft->iColumn>=0
|
||||
&& !ExprHasProperty(pExpr, EP_FromJoin)
|
||||
&& OptimizationEnabled(db, SQLITE_Stat4)
|
||||
){
|
||||
Expr *pNewExpr;
|
||||
Expr *pLeft = pExpr->pLeft;
|
||||
int idxNew;
|
||||
WhereTerm *pNewTerm;
|
||||
|
||||
pNewExpr = sqlite3PExpr(pParse, TK_GT,
|
||||
sqlite3ExprDup(db, pLeft, 0),
|
||||
sqlite3ExprAlloc(db, TK_NULL, 0, 0));
|
||||
|
||||
idxNew = whereClauseInsert(pWC, pNewExpr,
|
||||
TERM_VIRTUAL|TERM_DYNAMIC|TERM_VNULL);
|
||||
if( idxNew ){
|
||||
pNewTerm = &pWC->a[idxNew];
|
||||
pNewTerm->prereqRight = 0;
|
||||
pNewTerm->leftCursor = pLeft->iTable;
|
||||
pNewTerm->u.x.leftColumn = pLeft->iColumn;
|
||||
pNewTerm->eOperator = WO_GT;
|
||||
markTermAsChild(pWC, idxNew, idxTerm);
|
||||
pTerm = &pWC->a[idxTerm];
|
||||
pTerm->wtFlags |= TERM_COPIED;
|
||||
pNewTerm->prereqAll = pTerm->prereqAll;
|
||||
}
|
||||
}
|
||||
#endif /* SQLITE_ENABLE_STAT4 */
|
||||
|
||||
/* Prevent ON clause terms of a LEFT JOIN from being used to drive
|
||||
** an index for tables to the left of the join.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user