1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-10 01:02:56 +03:00

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
This commit is contained in:
drh
2022-10-13 21:08:34 +00:00
parent d92c652ac1
commit 4bc1cc1847
10 changed files with 123 additions and 15 deletions

View File

@@ -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;