diff options
author | drh <drh@noemail.net> | 2010-04-06 22:33:55 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2010-04-06 22:33:55 +0000 |
commit | a21a64dd0c2ac013afb692e8edf6472f0b87f80f (patch) | |
tree | 8947d114da3c8090daafdc9c77a018ff3ec2a625 /src | |
parent | 75bb9f5a5b91fb8c2715dd15e242ea34bfe4df05 (diff) | |
download | sqlite-a21a64dd0c2ac013afb692e8edf6472f0b87f80f.tar.gz sqlite-a21a64dd0c2ac013afb692e8edf6472f0b87f80f.zip |
Veryquick.test is now working. The SQLITE_STMTSTATUS_AUTOINDEX counter
added.
FossilOrigin-Name: abbf16e5e7895971710fb3a8fd9c782fc1218a77
Diffstat (limited to 'src')
-rw-r--r-- | src/sqlite.h.in | 8 | ||||
-rw-r--r-- | src/test1.c | 1 | ||||
-rw-r--r-- | src/vdbe.c | 8 | ||||
-rw-r--r-- | src/vdbeInt.h | 2 | ||||
-rw-r--r-- | src/where.c | 14 |
5 files changed, 28 insertions, 5 deletions
diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 4777a87ec..24d4e8fbc 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -5199,10 +5199,18 @@ int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); ** A non-zero value in this counter may indicate an opportunity to ** improvement performance through careful use of indices.</dd> ** +** <dt>SQLITE_STMTSTATUS_AUTOINDEX</dt> +** <dd>^This is the number of rows inserted into transient indices that +** were created automatically in order to help joins run faster. +** A non-zero value in this counter may indicate an opportunity to +** improvement performance by adding permanent indices that do not +** need to be reinitialized each time the statement is run.</dd> +** ** </dl> */ #define SQLITE_STMTSTATUS_FULLSCAN_STEP 1 #define SQLITE_STMTSTATUS_SORT 2 +#define SQLITE_STMTSTATUS_AUTOINDEX 3 /* ** CAPI3REF: Custom Page Cache Object diff --git a/src/test1.c b/src/test1.c index 7c5d49715..b5fda952c 100644 --- a/src/test1.c +++ b/src/test1.c @@ -2025,6 +2025,7 @@ static int test_stmt_status( } aOp[] = { { "SQLITE_STMTSTATUS_FULLSCAN_STEP", SQLITE_STMTSTATUS_FULLSCAN_STEP }, { "SQLITE_STMTSTATUS_SORT", SQLITE_STMTSTATUS_SORT }, + { "SQLITE_STMTSTATUS_AUTOINDEX", SQLITE_STMTSTATUS_AUTOINDEX }, }; if( objc!=4 ){ Tcl_WrongNumArgs(interp, 1, objv, "STMT PARAMETER RESETFLAG"); diff --git a/src/vdbe.c b/src/vdbe.c index d5e4b4d19..7989880a7 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -3082,6 +3082,14 @@ case OP_OpenWrite: { ** this opcode. Then this opcode was call OpenVirtual. But ** that created confusion with the whole virtual-table idea. */ +/* Opcode: OpenAutoindex P1 P2 * P4 * +** +** This opcode works the same as OP_OpenEphemeral. It has a +** different name to distinguish its use. Tables created using +** by this opcode will be used for automatically created transient +** indices in joins. +*/ +case OP_OpenAutoindex: case OP_OpenEphemeral: { VdbeCursor *pCx; static const int openFlags = diff --git a/src/vdbeInt.h b/src/vdbeInt.h index 489e8da6a..e8e158544 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -311,7 +311,7 @@ struct Vdbe { int btreeMask; /* Bitmask of db->aDb[] entries referenced */ i64 startTime; /* Time when query started - used for profiling */ BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */ - int aCounter[2]; /* Counters used by sqlite3_stmt_status() */ + int aCounter[3]; /* Counters used by sqlite3_stmt_status() */ char *zSql; /* Text of the SQL statement that generated this */ void *pFree; /* Free this when deleting the vdbe */ i64 nFkConstraint; /* Number of imm. FK constraints this VM */ diff --git a/src/where.c b/src/where.c index 2d476cfbb..dc317dc06 100644 --- a/src/where.c +++ b/src/where.c @@ -1749,7 +1749,7 @@ static void constructTransientIndex( } assert( nColumn>0 ); pLevel->plan.nEq = nColumn; - pLevel->plan.wsFlags = WHERE_COLUMN_EQ | WO_EQ; + pLevel->plan.wsFlags |= WHERE_COLUMN_EQ | WO_EQ; /* Construct the Index object to describe this index */ nByte = sizeof(Index); @@ -1787,9 +1787,9 @@ static void constructTransientIndex( /* Create the transient index */ pKeyinfo = sqlite3IndexKeyinfo(pParse, pIdx); assert( pLevel->iIdxCur>=0 ); - sqlite3VdbeAddOp4(v, OP_OpenEphemeral, pLevel->iIdxCur, nColumn+1, 0, + sqlite3VdbeAddOp4(v, OP_OpenAutoindex, pLevel->iIdxCur, nColumn+1, 0, (char*)pKeyinfo, P4_KEYINFO_HANDOFF); - VdbeComment((v, "auto-idx for %s", pTable->zName)); + VdbeComment((v, "for %s", pTable->zName)); /* Fill the transient index with content */ addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); @@ -1798,6 +1798,7 @@ static void constructTransientIndex( sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord); sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); + sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX); sqlite3VdbeJumpHere(v, addrTop); sqlite3ReleaseTempReg(pParse, regRecord); @@ -3643,7 +3644,11 @@ static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){ sqlite3DbFree(db, pInfo); } if( pWInfo->a[i].plan.wsFlags & WHERE_TEMP_INDEX ){ - sqlite3DbFree(db, pWInfo->a[i].plan.u.pIdx); + Index *pIdx = pWInfo->a[i].plan.u.pIdx; + if( pIdx ){ + sqlite3DbFree(db, pIdx->zColAff); + sqlite3DbFree(db, pIdx); + } } } whereClauseClear(pWInfo->pWC); @@ -4118,6 +4123,7 @@ WhereInfo *sqlite3WhereBegin( notReady &= ~getMask(pWC->pMaskSet, pTabItem->iCursor); } pWInfo->iTop = sqlite3VdbeCurrentAddr(v); + if( db->mallocFailed ) goto whereBeginError; /* Generate the code to do the search. Each iteration of the for ** loop below generates code for a single nested loop of the VM |