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

Further optimization of SQL function dispatch. Improvements to opcode

documentation.

FossilOrigin-Name: eaddbf296aee98ffca82adade1b0d2fbefd09d7b
This commit is contained in:
drh
2015-06-26 18:47:53 +00:00
parent 9c7c913cd6
commit e2d9e7cfd0
4 changed files with 39 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
C Cache\sthe\ssqlite3_context\sstructure\sin\sthe\sP4\soperand\sof\sVDBE\sprograms\nfor\sfaster\sSQL\sfunction\sdispatch.
D 2015-06-26T18:16:52.781
C Further\soptimization\sof\sSQL\sfunction\sdispatch.\s\sImprovements\sto\sopcode\ndocumentation.
D 2015-06-26T18:47:53.814
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 1063c58075b7400d93326b0eb332b48a54f53025
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -313,11 +313,11 @@ F src/update.c 487747b328b7216bb7f6af0695d6937d5c9e605f
F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c
F src/util.c a6431c92803b975b7322724a7b433e538d243539
F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701
F src/vdbe.c 8fde5281f304c31fd635891b3cb138e6b79ce9f5
F src/vdbe.c b425feab69fb29b3cf4d40c5c8ea585bce883307
F src/vdbe.h 7a75045d879118b9d3af7e8b3c108f2f27c51473
F src/vdbeInt.h 8b54e01ad0463590e7cffabce0bc36da9ee4f816
F src/vdbeapi.c 6a0d7757987018ff6b1b81bc5293219cd26bb299
F src/vdbeaux.c 316e6bc773559d164155848f086c4b7d146f483a
F src/vdbeaux.c 13261b7597c7f189232f84a1e175a3268ea2c32b
F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90
F src/vdbemem.c ae38a0d35ae71cf604381a887c170466ba518090
F src/vdbesort.c f5009e7a35e3065635d8918b9a31f498a499976b
@@ -1286,7 +1286,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 7097716caed9d4aef49c7e766e41ea74abf5967f
R 61b5a8d7a0dc65b1ab9c06045c3a6290
P 2abc44eb3b9d489321baa50bc25e17dafbda3687
R a98b4348d07c70a554120b6bb6158a33
U drh
Z 9dd787a20069829fde828ff0d1be6044
Z 2205c193de128862e6e7711ff0d4d13b

View File

@@ -1 +1 @@
2abc44eb3b9d489321baa50bc25e17dafbda3687
eaddbf296aee98ffca82adade1b0d2fbefd09d7b

View File

@@ -1549,7 +1549,7 @@ case OP_CollSeq: {
/* Opcode: Function0 P1 P2 P3 P4 P5
** Synopsis: r[P3]=func(r[P2@P5])
**
** Invoke a user function (P4 is a pointer to a Function structure that
** Invoke a user function (P4 is a pointer to a FuncDef object that
** defines the function) with P5 arguments taken from register P2 and
** successors. The result of the function is stored in register P3.
** Register P3 must not be one of the function inputs.
@@ -1579,7 +1579,7 @@ case OP_CollSeq: {
** invocation of this opcode.
**
** SQL functions are initially coded as OP_Function0 with P4 pointing
** to the function itself. But on first evaluation, the P4 operand is
** to a FuncDef object. But on first evaluation, the P4 operand is
** automatically converted into an sqlite3_context object and the operation
** changed to this OP_Function opcode. In this way, the initialization of
** the sqlite3_context object occurs only once, rather than once for each
@@ -1619,8 +1619,9 @@ case OP_Function: {
** might change from one evaluation to the next. The next block of code
** checks to see if the register array has changed, and if so it
** reinitializes the relavant parts of the sqlite3_context object */
if( pCtx->pOut != &aMem[pOp->p3] ){
pCtx->pOut = &aMem[pOp->p3];
pOut = &aMem[pOp->p3];
if( pCtx->pOut != pOut ){
pCtx->pOut = pOut;
for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i];
}
@@ -1643,13 +1644,13 @@ case OP_Function: {
sqlite3VdbeError(p, "%s", sqlite3_value_text(pCtx->pOut));
rc = pCtx->isError;
}
sqlite3VdbeDeleteAuxData(p, (int)(pOp - aOp), pOp->p1);
sqlite3VdbeDeleteAuxData(p, pCtx->iOp, pOp->p1);
}
/* Copy the result of the function into register P3 */
sqlite3VdbeChangeEncoding(pCtx->pOut, encoding);
if( sqlite3VdbeMemTooBig(pCtx->pOut) ){
goto too_big;
if( pOut->flags & (MEM_Str|MEM_Blob) ){
sqlite3VdbeChangeEncoding(pCtx->pOut, encoding);
if( sqlite3VdbeMemTooBig(pCtx->pOut) ) goto too_big;
}
REGISTER_TRACE(pOp->p3, pCtx->pOut);
@@ -5737,17 +5738,34 @@ case OP_JumpZeroIncr: { /* jump, in1 */
break;
}
/* Opcode: AggStep * P2 P3 P4 P5
/* Opcode: AggStep0 * P2 P3 P4 P5
** Synopsis: accum=r[P3] step(r[P2@P5])
**
** Execute the step function for an aggregate. The
** function has P5 arguments. P4 is a pointer to the FuncDef
** structure that specifies the function. Use register
** P3 as the accumulator.
** structure that specifies the function. Register P3 is the
** accumulator.
**
** The P5 arguments are taken from register P2 and its
** successors.
*/
/* Opcode: AggStep * P2 P3 P4 P5
** Synopsis: accum=r[P3] step(r[P2@P5])
**
** Execute the step function for an aggregate. The
** function has P5 arguments. P4 is a pointer to an sqlite3_context
** object that is used to run the function. Register P3 is
** as the accumulator.
**
** The P5 arguments are taken from register P2 and its
** successors.
**
** This opcode is initially coded as OP_AggStep0. On first evaluation,
** the FuncDef stored in P4 is converted into an sqlite3_context and
** the opcode is changed. In this way, the initialization of the
** sqlite3_context only happens once, instead of on each call to the
** step function.
*/
case OP_AggStep0: {
int n;
sqlite3_context *pCtx;

View File

@@ -1120,11 +1120,13 @@ static char *displayP4(Op *pOp, char *zTemp, int nTemp){
sqlite3_snprintf(nTemp, zTemp, "%s(%d)", pDef->zName, pDef->nArg);
break;
}
#ifdef SQLITE_DEBUG
case P4_FUNCCTX: {
FuncDef *pDef = pOp->p4.pCtx->pFunc;
sqlite3_snprintf(nTemp, zTemp, "%s(%d)", pDef->zName, pDef->nArg);
break;
}
#endif
case P4_INT64: {
sqlite3_snprintf(nTemp, zTemp, "%lld", *pOp->p4.pI64);
break;