diff options
author | drh <> | 2022-10-13 21:08:34 +0000 |
---|---|---|
committer | drh <> | 2022-10-13 21:08:34 +0000 |
commit | 4bc1cc18476aaa674f8a24f859e1ed754c365505 (patch) | |
tree | 8615989555bb36f06e4d5e40728c1d865d216c17 /src/expr.c | |
parent | d92c652ac1fe570e27acd83e15903fb695386880 (diff) | |
download | sqlite-4bc1cc18476aaa674f8a24f859e1ed754c365505.tar.gz sqlite-4bc1cc18476aaa674f8a24f859e1ed754c365505.zip |
This experimental branch attempts to use columns for an index-on-expression
in place of the expression that is being indexed. This particular check-in
mostly works, but there are still issues.
FossilOrigin-Name: 2e8d4fd4cfd9e82f33c707ba246fe2bb3ca01762cf5ac5905058fbc7adf0abe7
Diffstat (limited to 'src/expr.c')
-rw-r--r-- | src/expr.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/expr.c b/src/expr.c index bceb5efb0..3630b47aa 100644 --- a/src/expr.c +++ b/src/expr.c @@ -4043,6 +4043,26 @@ static int exprCodeInlineFunction( return target; } +/* +** Check to see if pExpr is one of the indexed expression on pParse->pIdxExpr. +** If it is, then resolve the expression by reading from the index and +** return the register into which the value has been read. If there is +** no match, return negative. +*/ +static SQLITE_NOINLINE int sqlite3ExprIndexLookup( + Parse *pParse, /* The parsing context */ + Expr *pExpr, /* The expression to potentially bypass */ + int target /* Where to store the result of the expression */ +){ + IndexExpr *p; + for(p=pParse->pIdxExpr; p; p=p->pIENext){ + if( sqlite3ExprCompare(0, pExpr, p->pExpr, p->iDataCur)!=0 ) continue; + sqlite3VdbeAddOp3(pParse->pVdbe, OP_Column, p->iIdxCur, p->iIdxCol, target); + return target; + } + return -1; /* Not found */ +} + /* ** Generate code into the current Vdbe to evaluate the given @@ -4068,6 +4088,14 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){ assert( target>0 && target<=pParse->nMem ); assert( v!=0 ); + if( pParse->pIdxExpr!=0 + && pExpr!=0 + && !ExprHasProperty(pExpr, EP_Leaf) + && (r1 = sqlite3ExprIndexLookup(pParse, pExpr, target))>=0 + ){ + return r1; + } + expr_code_doover: if( pExpr==0 ){ op = TK_NULL; |