Simplified implementation of indexing with the IS operator.

FossilOrigin-Name: 95b1f9bf14e490c6c6bba9ea78aeab712a44aab5
This commit is contained in:
drh 2015-05-13 19:33:41 +00:00
parent e0cc3c296c
commit 9be1870994
5 changed files with 19 additions and 24 deletions

View File

@ -1,5 +1,5 @@
C Add\stestcase()\smacros\sand\scomments\sand\sa\sfew\stest-cases.
D 2015-05-13T17:54:08.892
C Simplified\simplementation\sof\sindexing\swith\sthe\sIS\soperator.
D 2015-05-13T19:33:41.990
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in edfc69769e613a6359c42c06ea1d42c3bece1736
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -307,8 +307,8 @@ F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb
F src/wal.c ce2cb2d06faab54d1bce3e739bec79e063dd9113
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804
F src/where.c 98964edb2a27d6f87976b85a8b00862558a277b2
F src/whereInt.h 6b5a8ac7b4adc055176c3330d755735ed674335d
F src/where.c fa61aca146422a2a056aeb0381a6bb1c37d46c07
F src/whereInt.h 31d30e83621c21358d031510d5c6a3e474cd8bb7
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
F test/aggnested.test b35b4cd69fc913f90d39a575e171e1116c3a4bb7
@ -1177,7 +1177,7 @@ F test/where8m.test da346596e19d54f0aba35ebade032a7c47d79739
F test/where9.test 729c3ba9b47e8f9f1aab96bae7dad2a524f1d1a2
F test/whereA.test 4d253178d135ec46d1671e440cd8f2b916aa6e6b
F test/whereB.test 0def95db3bdec220a731c7e4bec5930327c1d8c5
F test/whereC.test d6f4ecd4fa2d9429681a5b22a25d2bda8e86ab8a
F test/whereC.test cae295158703cb3fc23bf1a108a9ab730efff0f6
F test/whereD.test 9eba1f9b18e5b19a0b0bcaae5e8c037260195f2b
F test/whereE.test b3a055eef928c992b0a33198a7b8dc10eea5ad2f
F test/whereF.test 5b2ba0dbe8074aa13e416b37c753991f0a2492d7
@ -1258,7 +1258,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 6f7f1673d00d216a5aa456acb44793a14f3b3d91
R 3ff0212a0c4cf6ad597a241e62c5ab7c
P 24263d08b11c88416d270013bdaf5ff45125cb4d
R 16be24e7bac77474bad7ab9d3d121f18
U drh
Z fddf4aa627339444877435638e7a9621
Z 3bc6b705447a86373e017a72613abb32

View File

@ -1 +1 @@
24263d08b11c88416d270013bdaf5ff45125cb4d
95b1f9bf14e490c6c6bba9ea78aeab712a44aab5

View File

@ -1259,7 +1259,7 @@ static void exprAnalyze(
pTerm->u.leftColumn = pLeft->iColumn;
pTerm->eOperator = operatorMask(op) & opMask;
}
if( op==TK_IS ) pTerm->wtFlags |= TERM_NULLOK;
if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
if( pRight && pRight->op==TK_COLUMN ){
WhereTerm *pNew;
Expr *pDup;
@ -1284,7 +1284,7 @@ static void exprAnalyze(
pTerm->eOperator |= WO_EQUIV;
eExtraOp = WO_EQUIV;
}
if( op==TK_IS ) pNew->wtFlags |= TERM_NULLOK;
if( op==TK_IS ) pNew->wtFlags |= TERM_IS;
}else{
pDup = pExpr;
pNew = pTerm;
@ -1475,8 +1475,7 @@ static void exprAnalyze(
** 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 both TERM_VNULL
** and TERM_NULLOK.
** Note that the virtual term must be tagged with TERM_VNULL.
*/
if( pExpr->op==TK_NOTNULL
&& pExpr->pLeft->op==TK_COLUMN
@ -1493,7 +1492,7 @@ static void exprAnalyze(
sqlite3PExpr(pParse, TK_NULL, 0, 0, 0), 0);
idxNew = whereClauseInsert(pWC, pNewExpr,
TERM_VIRTUAL|TERM_DYNAMIC|TERM_VNULL|TERM_NULLOK);
TERM_VIRTUAL|TERM_DYNAMIC|TERM_VNULL);
if( idxNew ){
pNewTerm = &pWC->a[idxNew];
pNewTerm->prereqRight = 0;
@ -2983,10 +2982,7 @@ static int codeAllEqualityTerms(
testcase( pTerm->eOperator & WO_IN );
if( (pTerm->eOperator & (WO_ISNULL|WO_IN))==0 ){
Expr *pRight = pTerm->pExpr->pRight;
testcase( pTerm->pExpr->op==TK_IS );
if( (pTerm->wtFlags & TERM_NULLOK)==0
&& sqlite3ExprCanBeNull(pRight)
){
if( (pTerm->wtFlags & TERM_IS)==0 && sqlite3ExprCanBeNull(pRight) ){
sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
VdbeCoverage(v);
}
@ -3635,8 +3631,7 @@ static Bitmask codeOneLoopStart(
Expr *pRight = pRangeStart->pExpr->pRight;
sqlite3ExprCode(pParse, pRight, regBase+nEq);
whereLikeOptimizationStringFixup(v, pLevel, pRangeStart);
testcase( pRangeStart->pExpr->op==TK_IS );
if( (pRangeStart->wtFlags & TERM_NULLOK)==0
if( (pRangeStart->wtFlags & TERM_VNULL)==0
&& sqlite3ExprCanBeNull(pRight)
){
sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
@ -3682,8 +3677,7 @@ static Bitmask codeOneLoopStart(
sqlite3ExprCacheRemove(pParse, regBase+nEq, 1);
sqlite3ExprCode(pParse, pRight, regBase+nEq);
whereLikeOptimizationStringFixup(v, pLevel, pRangeEnd);
testcase( pRangeEnd->pExpr->op==TK_IS );
if( (pRangeEnd->wtFlags & TERM_NULLOK)==0
if( (pRangeEnd->wtFlags & TERM_VNULL)==0
&& sqlite3ExprCanBeNull(pRight)
){
sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);

View File

@ -280,7 +280,7 @@ struct WhereTerm {
#define TERM_LIKEOPT 0x100 /* Virtual terms from the LIKE optimization */
#define TERM_LIKECOND 0x200 /* Conditionally this LIKE operator term */
#define TERM_LIKE 0x400 /* The original LIKE operator */
#define TERM_NULLOK 0x800 /* Comparison operators against NULL work */
#define TERM_IS 0x800 /* Term.pExpr is an IS operator */
/*
** An instance of the WhereScan object is used as an iterator for locating
@ -430,7 +430,7 @@ struct WhereInfo {
** particular WhereTerms within a WhereClause.
*/
#define WO_IN 0x001
#define WO_EQ 0x002
#define WO_EQ 0x002 /* Used for both == and IS */
#define WO_LT (WO_EQ<<(TK_LT-TK_EQ))
#define WO_LE (WO_EQ<<(TK_LE-TK_EQ))
#define WO_GT (WO_EQ<<(TK_GT-TK_EQ))

View File

@ -59,6 +59,7 @@ foreach {tn sql res} {
12 "SELECT i FROM t1 WHERE a=2 AND b=2 AND i<NULL" {}
13 "SELECT i FROM t1 WHERE a=2 AND b=2 AND i>=NULL" {}
14 "SELECT i FROM t1 WHERE a=1 AND b='2' AND i<4.5" {3 4}
15 "SELECT i FROM t1 WHERE rowid IS '12'" {12}
} {
do_execsql_test 1.$tn.1 $sql $res
do_execsql_test 1.$tn.2 "$sql ORDER BY i ASC" [lsort -integer -inc $res]