Attempt to factor out constant functions from the interior of table scans,
since functions can often be expensive to compute. FossilOrigin-Name: 62e9270a8057d758621da33adb27fad14225f95d
This commit is contained in:
parent
a3a40211bd
commit
1e9b53f9bc
18
manifest
18
manifest
@ -1,5 +1,5 @@
|
||||
C Use\scompiler\sintrinsic\sfunctions\sfor\ssigned\sinteger\smath\swhen\soverflow\ndetection\sis\sneeded.
|
||||
D 2017-01-03T21:57:11.355
|
||||
C Attempt\sto\sfactor\sout\sconstant\sfunctions\sfrom\sthe\sinterior\sof\stable\sscans,\nsince\sfunctions\scan\soften\sbe\sexpensive\sto\scompute.
|
||||
D 2017-01-04T01:07:24.603
|
||||
F Makefile.in 41bd4cad981487345c4a84081074bcdb876e4b2e
|
||||
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
|
||||
F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da
|
||||
@ -341,7 +341,7 @@ F src/ctime.c 9f2296a4e5d26ebf0e0d95a0af4628f1ea694e7a
|
||||
F src/date.c dc3f1391d9297f8c748132813aaffcb117090d6e
|
||||
F src/dbstat.c 19ee7a4e89979d4df8e44cfac7a8f905ec89b77d
|
||||
F src/delete.c c8bc10d145c9666a34ae906250326fdaa8d58fa5
|
||||
F src/expr.c 449cbb8b9857ff8eb685b72555086818a178858c
|
||||
F src/expr.c 8ba6e4ee13cab031bab897d871cf51678cbdd57e
|
||||
F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
|
||||
F src/fkey.c 2e9aabe1aee76273aff8a84ee92c464e095400ae
|
||||
F src/func.c c67273e1ec08abbdcc14c189892a3ff6eeece86b
|
||||
@ -393,7 +393,7 @@ F src/shell.c 6095531aa900decdaa765e0f3993fba7153c92c1
|
||||
F src/sqlite.h.in e8e2d108d82647f0a812fdb74accf91c1ec08ddc
|
||||
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
|
||||
F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae
|
||||
F src/sqliteInt.h f3450b70cfd99b434304225cf3b95de9cb4a9536
|
||||
F src/sqliteInt.h ba08d9eb983697be3eb7ee8d41d1121177694f59
|
||||
F src/sqliteLimit.h c0373387c287c8d0932510b5547ecde31b5da247
|
||||
F src/status.c a9e66593dfb28a9e746cba7153f84d49c1ddc4b1
|
||||
F src/table.c 5226df15ab9179b9ed558d89575ea0ce37b03fc9
|
||||
@ -1541,8 +1541,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 bed0eaa5f50112e64fc97a2afdc9d56cf8f5026a 4c2efd4239bf07eb4b92d4af54edd68ee6312670
|
||||
R 4be5114c40ec1b8757eebb3b6a7e4284
|
||||
T +closed 4c2efd4239bf07eb4b92d4af54edd68ee6312670
|
||||
P d3ac32a6e7f1823450feb3d1089802542090d164
|
||||
R c8a0edce7fe1361197ea989faff6405e
|
||||
T *branch * factor-constant-funcs
|
||||
T *sym-factor-constant-funcs *
|
||||
T -sym-trunk *
|
||||
U drh
|
||||
Z 6bd6e679c9840443d9b2f38c8bc4573f
|
||||
Z 75605860ea44512895bed0398cfff7b7
|
||||
|
@ -1 +1 @@
|
||||
d3ac32a6e7f1823450feb3d1089802542090d164
|
||||
62e9270a8057d758621da33adb27fad14225f95d
|
39
src/expr.c
39
src/expr.c
@ -3612,6 +3612,9 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
|
||||
u8 enc = ENC(db); /* The text encoding used by this database */
|
||||
CollSeq *pColl = 0; /* A collating sequence */
|
||||
|
||||
if( ConstFactorOk(pParse) && sqlite3ExprIsConstantNotJoin(pExpr) ){
|
||||
return sqlite3ExprCodeAtInit(pParse, pExpr, -1, 1);
|
||||
}
|
||||
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
|
||||
if( ExprHasProperty(pExpr, EP_TokenOnly) ){
|
||||
pFarg = 0;
|
||||
@ -3992,8 +3995,16 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
|
||||
|
||||
/*
|
||||
** Factor out the code of the given expression to initialization time.
|
||||
**
|
||||
** If regDest>=0 then the result is always stored in that register.
|
||||
** If regDest<0 then this routine is free to store the value whereever
|
||||
** it wants. The register where the expression is stored is returned.
|
||||
**
|
||||
** If regDest<0 and an equivalent expression already exists elsewhere
|
||||
** in the initialization expressions, then routine just returns the
|
||||
** register of the prior occurrance.
|
||||
*/
|
||||
void sqlite3ExprCodeAtInit(
|
||||
int sqlite3ExprCodeAtInit(
|
||||
Parse *pParse, /* Parsing context */
|
||||
Expr *pExpr, /* The expression to code when the VDBE initializes */
|
||||
int regDest, /* Store the value in this register */
|
||||
@ -4002,6 +4013,18 @@ void sqlite3ExprCodeAtInit(
|
||||
ExprList *p;
|
||||
assert( ConstFactorOk(pParse) );
|
||||
p = pParse->pConstExpr;
|
||||
if( regDest<0 ){
|
||||
if( p && reusable ){
|
||||
struct ExprList_item *pItem;
|
||||
int i;
|
||||
for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
|
||||
if( pItem->reusable && sqlite3ExprCompare(pItem->pExpr,pExpr,-1)==0 ){
|
||||
return pItem->u.iConstExprReg;
|
||||
}
|
||||
}
|
||||
}
|
||||
regDest = ++pParse->nMem;
|
||||
}
|
||||
pExpr = sqlite3ExprDup(pParse->db, pExpr, 0);
|
||||
p = sqlite3ExprListAppend(pParse, p, pExpr);
|
||||
if( p ){
|
||||
@ -4010,6 +4033,7 @@ void sqlite3ExprCodeAtInit(
|
||||
pItem->reusable = reusable;
|
||||
}
|
||||
pParse->pConstExpr = p;
|
||||
return regDest;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -4032,19 +4056,8 @@ int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
|
||||
&& pExpr->op!=TK_REGISTER
|
||||
&& sqlite3ExprIsConstantNotJoin(pExpr)
|
||||
){
|
||||
ExprList *p = pParse->pConstExpr;
|
||||
int i;
|
||||
*pReg = 0;
|
||||
if( p ){
|
||||
struct ExprList_item *pItem;
|
||||
for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){
|
||||
if( pItem->reusable && sqlite3ExprCompare(pItem->pExpr,pExpr,-1)==0 ){
|
||||
return pItem->u.iConstExprReg;
|
||||
}
|
||||
}
|
||||
}
|
||||
r2 = ++pParse->nMem;
|
||||
sqlite3ExprCodeAtInit(pParse, pExpr, r2, 1);
|
||||
r2 = sqlite3ExprCodeAtInit(pParse, pExpr, -1, 1);
|
||||
}else{
|
||||
int r1 = sqlite3GetTempReg(pParse);
|
||||
r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
|
||||
|
@ -3716,7 +3716,7 @@ void sqlite3ExprCacheAffinityChange(Parse*, int, int);
|
||||
void sqlite3ExprCode(Parse*, Expr*, int);
|
||||
void sqlite3ExprCodeCopy(Parse*, Expr*, int);
|
||||
void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
|
||||
void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
|
||||
int sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
|
||||
int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
|
||||
int sqlite3ExprCodeTarget(Parse*, Expr*, int);
|
||||
void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
|
||||
|
Loading…
x
Reference in New Issue
Block a user