Compare commits
108 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a161c222a6 | |||
| 6f38a6418c | |||
| 8ab88326cb | |||
| 793eb043ce | |||
| 52f6c916fb | |||
| 6b169bd86d | |||
| e13e9f54b0 | |||
| 0af62b015a | |||
| bf539c4d5c | |||
| 6919b07556 | |||
| 03e1754e31 | |||
| d3037a4123 | |||
| 5988572876 | |||
| 165674d8db | |||
| fdaac671b8 | |||
| d9e3cad2f8 | |||
| 5f33f37580 | |||
| 5db2605a80 | |||
| de07791a9c | |||
| 9211f8a6ce | |||
| c28c4e5009 | |||
| d100f6912d | |||
| f63936e805 | |||
| 46539d7cfa | |||
| 582d47d27a | |||
| 01f75f2d68 | |||
| eb26672d0e | |||
| e75fb06146 | |||
| 1073e26435 | |||
| ff574f4c76 | |||
| be007dc61e | |||
| ba7df1188a | |||
| 4384e98e6e | |||
| 24b7fe9004 | |||
| 3b6cb3ceb9 | |||
| 73632e37c9 | |||
| 1f03e609ff | |||
| 92054fefcd | |||
| 19384380f3 | |||
| 8b8d28dd5a | |||
| 915fe4d7e0 | |||
| 07490d2b8a | |||
| f42747246a | |||
| 2f312ee65f | |||
| 5d1dcff095 | |||
| 56c517aa5f | |||
| 6284d02160 | |||
| 7fa2092571 | |||
| dcf31a14bf | |||
| e62d373031 | |||
| 95a7b3e36d | |||
| b8af6a285c | |||
| 9ac99313b5 | |||
| 02e8689233 | |||
| 77ff23f9c7 | |||
| 55e85ca5f5 | |||
| d49c358e39 | |||
| aecd80215c | |||
| a496fa7c02 | |||
| 6bb64f6a31 | |||
| 9ccd8659ff | |||
| f1d2670d40 | |||
| ebb6a65d16 | |||
| 6e1b167454 | |||
| a4c3c87e3d | |||
| c5cd124900 | |||
| a9cb5be49a | |||
| 36ca5359dc | |||
| 4a1f4ff53b | |||
| 61b7060c4f | |||
| 36c12888b5 | |||
| 7d9e7d8287 | |||
| 89a75397e0 | |||
| 09328c00d6 | |||
| aae0f9e462 | |||
| abfa6d52ed | |||
| 36fabb6297 | |||
| 1d2b3c1f8a | |||
| 0259bc3da2 | |||
| add5ce303f | |||
| fde1e6bc37 | |||
| cca9f3d291 | |||
| d36e104112 | |||
| 0d31dc37ac | |||
| 8ff2d9561a | |||
| 74dade2155 | |||
| af0d8bcf4b | |||
| 55a1b30875 | |||
| 2b1a64a120 | |||
| c2cfb51525 | |||
| 30f07042df | |||
| fbc38de980 | |||
| b13af4c5dd | |||
| 67a5ec7b54 | |||
| 05db3c7743 | |||
| b49d1047c6 | |||
| 84f48296fa | |||
| 575ab2f8f6 | |||
| 1df556e6f2 | |||
| 4a1aa3851a | |||
| 3fa2a82b8b | |||
| 60bdad7f54 | |||
| 4eaa1295c9 | |||
| 6cdc63d4e3 | |||
| da5b1cd446 | |||
| 463f348f2c | |||
| 9894742beb | |||
| 50420545fc |
@@ -470,6 +470,17 @@ LTLIBOPTS = /MACHINE:$(PLATFORM)
|
||||
#
|
||||
!IF $(FOR_WINRT)!=0
|
||||
LTLINKOPTS = $(LTLINKOPTS) /APPCONTAINER
|
||||
!IF "$(VISUALSTUDIOVERSION)"=="12.0"
|
||||
!IF "$(PLATFORM)"=="x86"
|
||||
LTLINKOPTS = $(LTLINKOPTS) "/LIBPATH:$(VCINSTALLDIR)\lib\store"
|
||||
!ELSEIF "$(PLATFORM)"=="x64"
|
||||
LTLINKOPTS = $(LTLINKOPTS) "/LIBPATH:$(VCINSTALLDIR)\lib\store\amd64"
|
||||
!ELSEIF "$(PLATFORM)"=="ARM"
|
||||
LTLINKOPTS = $(LTLINKOPTS) "/LIBPATH:$(VCINSTALLDIR)\lib\store\arm"
|
||||
!ELSE
|
||||
LTLINKOPTS = $(LTLINKOPTS) "/LIBPATH:$(VCINSTALLDIR)\lib\store"
|
||||
!ENDIF
|
||||
!ENDIF
|
||||
!ENDIF
|
||||
|
||||
# If either debugging or symbols are enabled, enable PDBs.
|
||||
|
||||
+422
-103
@@ -1457,7 +1457,11 @@ static int fts3BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
|
||||
Fts3Table *p = (Fts3Table *)pVTab;
|
||||
int i; /* Iterator variable */
|
||||
int iCons = -1; /* Index of constraint to use */
|
||||
|
||||
int iLangidCons = -1; /* Index of langid=x constraint, if present */
|
||||
int iDocidGe = -1; /* Index of docid>=x constraint, if present */
|
||||
int iDocidLe = -1; /* Index of docid<=x constraint, if present */
|
||||
int iIdx;
|
||||
|
||||
/* By default use a full table scan. This is an expensive option,
|
||||
** so search through the constraints to see if a more efficient
|
||||
@@ -1466,14 +1470,14 @@ static int fts3BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
|
||||
pInfo->idxNum = FTS3_FULLSCAN_SEARCH;
|
||||
pInfo->estimatedCost = 5000000;
|
||||
for(i=0; i<pInfo->nConstraint; i++){
|
||||
int bDocid; /* True if this constraint is on docid */
|
||||
struct sqlite3_index_constraint *pCons = &pInfo->aConstraint[i];
|
||||
if( pCons->usable==0 ) continue;
|
||||
|
||||
bDocid = (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1);
|
||||
|
||||
/* A direct lookup on the rowid or docid column. Assign a cost of 1.0. */
|
||||
if( iCons<0
|
||||
&& pCons->op==SQLITE_INDEX_CONSTRAINT_EQ
|
||||
&& (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1 )
|
||||
){
|
||||
if( iCons<0 && pCons->op==SQLITE_INDEX_CONSTRAINT_EQ && bDocid ){
|
||||
pInfo->idxNum = FTS3_DOCID_SEARCH;
|
||||
pInfo->estimatedCost = 1.0;
|
||||
iCons = i;
|
||||
@@ -1502,14 +1506,38 @@ static int fts3BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
|
||||
){
|
||||
iLangidCons = i;
|
||||
}
|
||||
|
||||
if( bDocid ){
|
||||
switch( pCons->op ){
|
||||
case SQLITE_INDEX_CONSTRAINT_GE:
|
||||
case SQLITE_INDEX_CONSTRAINT_GT:
|
||||
iDocidGe = i;
|
||||
break;
|
||||
|
||||
case SQLITE_INDEX_CONSTRAINT_LE:
|
||||
case SQLITE_INDEX_CONSTRAINT_LT:
|
||||
iDocidLe = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
iIdx = 1;
|
||||
if( iCons>=0 ){
|
||||
pInfo->aConstraintUsage[iCons].argvIndex = 1;
|
||||
pInfo->aConstraintUsage[iCons].argvIndex = iIdx++;
|
||||
pInfo->aConstraintUsage[iCons].omit = 1;
|
||||
}
|
||||
if( iLangidCons>=0 ){
|
||||
pInfo->aConstraintUsage[iLangidCons].argvIndex = 2;
|
||||
pInfo->idxNum |= FTS3_HAVE_LANGID;
|
||||
pInfo->aConstraintUsage[iLangidCons].argvIndex = iIdx++;
|
||||
}
|
||||
if( iDocidGe>=0 ){
|
||||
pInfo->idxNum |= FTS3_HAVE_DOCID_GE;
|
||||
pInfo->aConstraintUsage[iDocidGe].argvIndex = iIdx++;
|
||||
}
|
||||
if( iDocidLe>=0 ){
|
||||
pInfo->idxNum |= FTS3_HAVE_DOCID_LE;
|
||||
pInfo->aConstraintUsage[iDocidLe].argvIndex = iIdx++;
|
||||
}
|
||||
|
||||
/* Regardless of the strategy selected, FTS can deliver rows in rowid (or
|
||||
@@ -2956,6 +2984,33 @@ static int fts3NextMethod(sqlite3_vtab_cursor *pCursor){
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** The following are copied from sqliteInt.h.
|
||||
**
|
||||
** Constants for the largest and smallest possible 64-bit signed integers.
|
||||
** These macros are designed to work correctly on both 32-bit and 64-bit
|
||||
** compilers.
|
||||
*/
|
||||
#ifndef SQLITE_AMALGAMATION
|
||||
# define LARGEST_INT64 (0xffffffff|(((sqlite3_int64)0x7fffffff)<<32))
|
||||
# define SMALLEST_INT64 (((sqlite3_int64)-1) - LARGEST_INT64)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** If the numeric type of argument pVal is "integer", then return it
|
||||
** converted to a 64-bit signed integer. Otherwise, return a copy of
|
||||
** the second parameter, iDefault.
|
||||
*/
|
||||
static sqlite3_int64 fts3DocidRange(sqlite3_value *pVal, i64 iDefault){
|
||||
if( pVal ){
|
||||
int eType = sqlite3_value_numeric_type(pVal);
|
||||
if( eType==SQLITE_INTEGER ){
|
||||
return sqlite3_value_int64(pVal);
|
||||
}
|
||||
}
|
||||
return iDefault;
|
||||
}
|
||||
|
||||
/*
|
||||
** This is the xFilter interface for the virtual table. See
|
||||
** the virtual table xFilter method documentation for additional
|
||||
@@ -2981,40 +3036,58 @@ static int fts3FilterMethod(
|
||||
){
|
||||
int rc;
|
||||
char *zSql; /* SQL statement used to access %_content */
|
||||
int eSearch;;
|
||||
Fts3Table *p = (Fts3Table *)pCursor->pVtab;
|
||||
Fts3Cursor *pCsr = (Fts3Cursor *)pCursor;
|
||||
|
||||
sqlite3_value *pCons = 0; /* The MATCH or rowid constraint, if any */
|
||||
sqlite3_value *pLangid = 0; /* The "langid = ?" constraint, if any */
|
||||
sqlite3_value *pDocidGe = 0; /* The "docid >= ?" constraint, if any */
|
||||
sqlite3_value *pDocidLe = 0; /* The "docid <= ?" constraint, if any */
|
||||
int iIdx;
|
||||
|
||||
UNUSED_PARAMETER(idxStr);
|
||||
UNUSED_PARAMETER(nVal);
|
||||
|
||||
assert( idxNum>=0 && idxNum<=(FTS3_FULLTEXT_SEARCH+p->nColumn) );
|
||||
assert( nVal==0 || nVal==1 || nVal==2 );
|
||||
assert( (nVal==0)==(idxNum==FTS3_FULLSCAN_SEARCH) );
|
||||
eSearch = (idxNum & 0x0000FFFF);
|
||||
assert( eSearch>=0 && eSearch<=(FTS3_FULLTEXT_SEARCH+p->nColumn) );
|
||||
assert( p->pSegments==0 );
|
||||
|
||||
/* Collect arguments into local variables */
|
||||
iIdx = 0;
|
||||
if( eSearch!=FTS3_FULLSCAN_SEARCH ) pCons = apVal[iIdx++];
|
||||
if( idxNum & FTS3_HAVE_LANGID ) pLangid = apVal[iIdx++];
|
||||
if( idxNum & FTS3_HAVE_DOCID_GE ) pDocidGe = apVal[iIdx++];
|
||||
if( idxNum & FTS3_HAVE_DOCID_LE ) pDocidLe = apVal[iIdx++];
|
||||
assert( iIdx==nVal );
|
||||
|
||||
/* In case the cursor has been used before, clear it now. */
|
||||
sqlite3_finalize(pCsr->pStmt);
|
||||
sqlite3_free(pCsr->aDoclist);
|
||||
sqlite3Fts3ExprFree(pCsr->pExpr);
|
||||
memset(&pCursor[1], 0, sizeof(Fts3Cursor)-sizeof(sqlite3_vtab_cursor));
|
||||
|
||||
/* Set the lower and upper bounds on docids to return */
|
||||
pCsr->iMinDocid = fts3DocidRange(pDocidGe, SMALLEST_INT64);
|
||||
pCsr->iMaxDocid = fts3DocidRange(pDocidLe, LARGEST_INT64);
|
||||
|
||||
if( idxStr ){
|
||||
pCsr->bDesc = (idxStr[0]=='D');
|
||||
}else{
|
||||
pCsr->bDesc = p->bDescIdx;
|
||||
}
|
||||
pCsr->eSearch = (i16)idxNum;
|
||||
pCsr->eSearch = (i16)eSearch;
|
||||
|
||||
if( idxNum!=FTS3_DOCID_SEARCH && idxNum!=FTS3_FULLSCAN_SEARCH ){
|
||||
int iCol = idxNum-FTS3_FULLTEXT_SEARCH;
|
||||
const char *zQuery = (const char *)sqlite3_value_text(apVal[0]);
|
||||
if( eSearch!=FTS3_DOCID_SEARCH && eSearch!=FTS3_FULLSCAN_SEARCH ){
|
||||
int iCol = eSearch-FTS3_FULLTEXT_SEARCH;
|
||||
const char *zQuery = (const char *)sqlite3_value_text(pCons);
|
||||
|
||||
if( zQuery==0 && sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
|
||||
if( zQuery==0 && sqlite3_value_type(pCons)!=SQLITE_NULL ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
|
||||
pCsr->iLangid = 0;
|
||||
if( nVal==2 ) pCsr->iLangid = sqlite3_value_int(apVal[1]);
|
||||
if( pLangid ) pCsr->iLangid = sqlite3_value_int(pLangid);
|
||||
|
||||
assert( p->base.zErrMsg==0 );
|
||||
rc = sqlite3Fts3ExprParse(p->pTokenizer, pCsr->iLangid,
|
||||
@@ -3037,7 +3110,7 @@ static int fts3FilterMethod(
|
||||
** full-text query or docid lookup, the statement retrieves a single
|
||||
** row by docid.
|
||||
*/
|
||||
if( idxNum==FTS3_FULLSCAN_SEARCH ){
|
||||
if( eSearch==FTS3_FULLSCAN_SEARCH ){
|
||||
zSql = sqlite3_mprintf(
|
||||
"SELECT %s ORDER BY rowid %s",
|
||||
p->zReadExprlist, (pCsr->bDesc ? "DESC" : "ASC")
|
||||
@@ -3048,10 +3121,10 @@ static int fts3FilterMethod(
|
||||
}else{
|
||||
rc = SQLITE_NOMEM;
|
||||
}
|
||||
}else if( idxNum==FTS3_DOCID_SEARCH ){
|
||||
}else if( eSearch==FTS3_DOCID_SEARCH ){
|
||||
rc = fts3CursorSeekStmt(pCsr, &pCsr->pStmt);
|
||||
if( rc==SQLITE_OK ){
|
||||
rc = sqlite3_bind_value(pCsr->pStmt, 1, apVal[0]);
|
||||
rc = sqlite3_bind_value(pCsr->pStmt, 1, pCons);
|
||||
}
|
||||
}
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
@@ -3942,6 +4015,12 @@ static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Maximum number of tokens a phrase may have to be considered for the
|
||||
** incremental doclists strategy.
|
||||
*/
|
||||
#define MAX_INCR_PHRASE_TOKENS 4
|
||||
|
||||
/*
|
||||
** This function is called for each Fts3Phrase in a full-text query
|
||||
** expression to initialize the mechanism for returning rows. Once this
|
||||
@@ -3955,23 +4034,43 @@ static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
|
||||
** SQLITE_OK is returned if no error occurs, otherwise an SQLite error code.
|
||||
*/
|
||||
static int fts3EvalPhraseStart(Fts3Cursor *pCsr, int bOptOk, Fts3Phrase *p){
|
||||
int rc; /* Error code */
|
||||
Fts3PhraseToken *pFirst = &p->aToken[0];
|
||||
Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab;
|
||||
int rc = SQLITE_OK; /* Error code */
|
||||
int i;
|
||||
|
||||
if( pCsr->bDesc==pTab->bDescIdx
|
||||
&& bOptOk==1
|
||||
&& p->nToken==1
|
||||
&& pFirst->pSegcsr
|
||||
&& pFirst->pSegcsr->bLookup
|
||||
&& pFirst->bFirst==0
|
||||
){
|
||||
/* Determine if doclists may be loaded from disk incrementally. This is
|
||||
** possible if the bOptOk argument is true, the FTS doclists will be
|
||||
** scanned in forward order, and the phrase consists of
|
||||
** MAX_INCR_PHRASE_TOKENS or fewer tokens, none of which are are "^first"
|
||||
** tokens or prefix tokens that cannot use a prefix-index. */
|
||||
int bHaveIncr = 0;
|
||||
int bIncrOk = (bOptOk
|
||||
&& pCsr->bDesc==pTab->bDescIdx
|
||||
&& p->nToken<=MAX_INCR_PHRASE_TOKENS && p->nToken>0
|
||||
&& p->nToken<=MAX_INCR_PHRASE_TOKENS && p->nToken>0
|
||||
#ifdef SQLITE_TEST
|
||||
&& pTab->bNoIncrDoclist==0
|
||||
#endif
|
||||
);
|
||||
for(i=0; bIncrOk==1 && i<p->nToken; i++){
|
||||
Fts3PhraseToken *pToken = &p->aToken[i];
|
||||
if( pToken->bFirst || (pToken->pSegcsr!=0 && !pToken->pSegcsr->bLookup) ){
|
||||
bIncrOk = 0;
|
||||
}
|
||||
if( pToken->pSegcsr ) bHaveIncr = 1;
|
||||
}
|
||||
|
||||
if( bIncrOk && bHaveIncr ){
|
||||
/* Use the incremental approach. */
|
||||
int iCol = (p->iColumn >= pTab->nColumn ? -1 : p->iColumn);
|
||||
rc = sqlite3Fts3MsrIncrStart(
|
||||
pTab, pFirst->pSegcsr, iCol, pFirst->z, pFirst->n);
|
||||
for(i=0; rc==SQLITE_OK && i<p->nToken; i++){
|
||||
Fts3PhraseToken *pToken = &p->aToken[i];
|
||||
Fts3MultiSegReader *pSegcsr = pToken->pSegcsr;
|
||||
if( pSegcsr ){
|
||||
rc = sqlite3Fts3MsrIncrStart(pTab, pSegcsr, iCol, pToken->z, pToken->n);
|
||||
}
|
||||
}
|
||||
p->bIncr = 1;
|
||||
|
||||
}else{
|
||||
/* Load the full doclist for the phrase into memory. */
|
||||
rc = fts3EvalPhraseLoad(pCsr, p);
|
||||
@@ -4080,6 +4179,216 @@ void sqlite3Fts3DoclistNext(
|
||||
*ppIter = p;
|
||||
}
|
||||
|
||||
/*
|
||||
** Advance the iterator pDL to the next entry in pDL->aAll/nAll. Set *pbEof
|
||||
** to true if EOF is reached.
|
||||
*/
|
||||
static void fts3EvalDlPhraseNext(
|
||||
Fts3Table *pTab,
|
||||
Fts3Doclist *pDL,
|
||||
u8 *pbEof
|
||||
){
|
||||
char *pIter; /* Used to iterate through aAll */
|
||||
char *pEnd = &pDL->aAll[pDL->nAll]; /* 1 byte past end of aAll */
|
||||
|
||||
if( pDL->pNextDocid ){
|
||||
pIter = pDL->pNextDocid;
|
||||
}else{
|
||||
pIter = pDL->aAll;
|
||||
}
|
||||
|
||||
if( pIter>=pEnd ){
|
||||
/* We have already reached the end of this doclist. EOF. */
|
||||
*pbEof = 1;
|
||||
}else{
|
||||
sqlite3_int64 iDelta;
|
||||
pIter += sqlite3Fts3GetVarint(pIter, &iDelta);
|
||||
if( pTab->bDescIdx==0 || pDL->pNextDocid==0 ){
|
||||
pDL->iDocid += iDelta;
|
||||
}else{
|
||||
pDL->iDocid -= iDelta;
|
||||
}
|
||||
pDL->pList = pIter;
|
||||
fts3PoslistCopy(0, &pIter);
|
||||
pDL->nList = (int)(pIter - pDL->pList);
|
||||
|
||||
/* pIter now points just past the 0x00 that terminates the position-
|
||||
** list for document pDL->iDocid. However, if this position-list was
|
||||
** edited in place by fts3EvalNearTrim(), then pIter may not actually
|
||||
** point to the start of the next docid value. The following line deals
|
||||
** with this case by advancing pIter past the zero-padding added by
|
||||
** fts3EvalNearTrim(). */
|
||||
while( pIter<pEnd && *pIter==0 ) pIter++;
|
||||
|
||||
pDL->pNextDocid = pIter;
|
||||
assert( pIter>=&pDL->aAll[pDL->nAll] || *pIter );
|
||||
*pbEof = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Helper type used by fts3EvalIncrPhraseNext() and incrPhraseTokenNext().
|
||||
*/
|
||||
typedef struct TokenDoclist TokenDoclist;
|
||||
struct TokenDoclist {
|
||||
int bIgnore;
|
||||
sqlite3_int64 iDocid;
|
||||
char *pList;
|
||||
int nList;
|
||||
};
|
||||
|
||||
/*
|
||||
** Token pToken is an incrementally loaded token that is part of a
|
||||
** multi-token phrase. Advance it to the next matching document in the
|
||||
** database and populate output variable *p with the details of the new
|
||||
** entry. Or, if the iterator has reached EOF, set *pbEof to true.
|
||||
**
|
||||
** If an error occurs, return an SQLite error code. Otherwise, return
|
||||
** SQLITE_OK.
|
||||
*/
|
||||
static int incrPhraseTokenNext(
|
||||
Fts3Table *pTab, /* Virtual table handle */
|
||||
Fts3Phrase *pPhrase, /* Phrase to advance token of */
|
||||
int iToken, /* Specific token to advance */
|
||||
TokenDoclist *p, /* OUT: Docid and doclist for new entry */
|
||||
u8 *pbEof /* OUT: True if iterator is at EOF */
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
|
||||
if( pPhrase->iDoclistToken==iToken ){
|
||||
assert( p->bIgnore==0 );
|
||||
assert( pPhrase->aToken[iToken].pSegcsr==0 );
|
||||
fts3EvalDlPhraseNext(pTab, &pPhrase->doclist, pbEof);
|
||||
p->pList = pPhrase->doclist.pList;
|
||||
p->nList = pPhrase->doclist.nList;
|
||||
p->iDocid = pPhrase->doclist.iDocid;
|
||||
}else{
|
||||
Fts3PhraseToken *pToken = &pPhrase->aToken[iToken];
|
||||
assert( pToken->pDeferred==0 );
|
||||
assert( pToken->pSegcsr || pPhrase->iDoclistToken>=0 );
|
||||
if( pToken->pSegcsr ){
|
||||
assert( p->bIgnore==0 );
|
||||
rc = sqlite3Fts3MsrIncrNext(
|
||||
pTab, pToken->pSegcsr, &p->iDocid, &p->pList, &p->nList
|
||||
);
|
||||
if( p->pList==0 ) *pbEof = 1;
|
||||
}else{
|
||||
p->bIgnore = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** The phrase iterator passed as the second argument:
|
||||
**
|
||||
** * features at least one token that uses an incremental doclist, and
|
||||
**
|
||||
** * does not contain any deferred tokens.
|
||||
**
|
||||
** Advance it to the next matching documnent in the database and populate
|
||||
** the Fts3Doclist.pList and nList fields.
|
||||
**
|
||||
** If there is no "next" entry and no error occurs, then *pbEof is set to
|
||||
** 1 before returning. Otherwise, if no error occurs and the iterator is
|
||||
** successfully advanced, *pbEof is set to 0.
|
||||
**
|
||||
** If an error occurs, return an SQLite error code. Otherwise, return
|
||||
** SQLITE_OK.
|
||||
*/
|
||||
static int fts3EvalIncrPhraseNext(
|
||||
Fts3Cursor *pCsr, /* FTS Cursor handle */
|
||||
Fts3Phrase *p, /* Phrase object to advance to next docid */
|
||||
u8 *pbEof /* OUT: Set to 1 if EOF */
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
Fts3Doclist *pDL = &p->doclist;
|
||||
Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab;
|
||||
u8 bEof = 0;
|
||||
|
||||
/* This is only called if it is guaranteed that the phrase has at least
|
||||
** one incremental token. In which case the bIncr flag is set. */
|
||||
assert( p->bIncr==1 );
|
||||
|
||||
if( p->nToken==1 && p->bIncr ){
|
||||
rc = sqlite3Fts3MsrIncrNext(pTab, p->aToken[0].pSegcsr,
|
||||
&pDL->iDocid, &pDL->pList, &pDL->nList
|
||||
);
|
||||
if( pDL->pList==0 ) bEof = 1;
|
||||
}else{
|
||||
int bDescDoclist = pCsr->bDesc;
|
||||
struct TokenDoclist a[MAX_INCR_PHRASE_TOKENS];
|
||||
|
||||
memset(a, 0, sizeof(a));
|
||||
assert( p->nToken<=MAX_INCR_PHRASE_TOKENS );
|
||||
assert( p->iDoclistToken<MAX_INCR_PHRASE_TOKENS );
|
||||
|
||||
while( bEof==0 ){
|
||||
int bMaxSet = 0;
|
||||
sqlite3_int64 iMax; /* Largest docid for all iterators */
|
||||
int i; /* Used to iterate through tokens */
|
||||
|
||||
/* Advance the iterator for each token in the phrase once. */
|
||||
for(i=0; rc==SQLITE_OK && i<p->nToken; i++){
|
||||
rc = incrPhraseTokenNext(pTab, p, i, &a[i], &bEof);
|
||||
if( a[i].bIgnore==0 && (bMaxSet==0 || DOCID_CMP(iMax, a[i].iDocid)<0) ){
|
||||
iMax = a[i].iDocid;
|
||||
bMaxSet = 1;
|
||||
}
|
||||
}
|
||||
assert( rc!=SQLITE_OK || a[p->nToken-1].bIgnore==0 );
|
||||
assert( rc!=SQLITE_OK || bMaxSet );
|
||||
|
||||
/* Keep advancing iterators until they all point to the same document */
|
||||
for(i=0; i<p->nToken; i++){
|
||||
while( rc==SQLITE_OK && bEof==0
|
||||
&& a[i].bIgnore==0 && DOCID_CMP(a[i].iDocid, iMax)<0
|
||||
){
|
||||
rc = incrPhraseTokenNext(pTab, p, i, &a[i], &bEof);
|
||||
if( DOCID_CMP(a[i].iDocid, iMax)>0 ){
|
||||
iMax = a[i].iDocid;
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the current entries really are a phrase match */
|
||||
if( bEof==0 ){
|
||||
int nList = 0;
|
||||
int nByte = a[p->nToken-1].nList;
|
||||
char *aDoclist = sqlite3_malloc(nByte+1);
|
||||
if( !aDoclist ) return SQLITE_NOMEM;
|
||||
memcpy(aDoclist, a[p->nToken-1].pList, nByte+1);
|
||||
|
||||
for(i=0; i<(p->nToken-1); i++){
|
||||
if( a[i].bIgnore==0 ){
|
||||
char *pL = a[i].pList;
|
||||
char *pR = aDoclist;
|
||||
char *pOut = aDoclist;
|
||||
int nDist = p->nToken-1-i;
|
||||
int res = fts3PoslistPhraseMerge(&pOut, nDist, 0, 1, &pL, &pR);
|
||||
if( res==0 ) break;
|
||||
nList = (pOut - aDoclist);
|
||||
}
|
||||
}
|
||||
if( i==(p->nToken-1) ){
|
||||
pDL->iDocid = iMax;
|
||||
pDL->pList = aDoclist;
|
||||
pDL->nList = nList;
|
||||
pDL->bFreeList = 1;
|
||||
break;
|
||||
}
|
||||
sqlite3_free(aDoclist);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*pbEof = bEof;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Attempt to move the phrase iterator to point to the next matching docid.
|
||||
** If an error occurs, return an SQLite error code. Otherwise, return
|
||||
@@ -4099,55 +4408,14 @@ static int fts3EvalPhraseNext(
|
||||
Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab;
|
||||
|
||||
if( p->bIncr ){
|
||||
assert( p->nToken==1 );
|
||||
assert( pDL->pNextDocid==0 );
|
||||
rc = sqlite3Fts3MsrIncrNext(pTab, p->aToken[0].pSegcsr,
|
||||
&pDL->iDocid, &pDL->pList, &pDL->nList
|
||||
);
|
||||
if( rc==SQLITE_OK && !pDL->pList ){
|
||||
*pbEof = 1;
|
||||
}
|
||||
rc = fts3EvalIncrPhraseNext(pCsr, p, pbEof);
|
||||
}else if( pCsr->bDesc!=pTab->bDescIdx && pDL->nAll ){
|
||||
sqlite3Fts3DoclistPrev(pTab->bDescIdx, pDL->aAll, pDL->nAll,
|
||||
&pDL->pNextDocid, &pDL->iDocid, &pDL->nList, pbEof
|
||||
);
|
||||
pDL->pList = pDL->pNextDocid;
|
||||
}else{
|
||||
char *pIter; /* Used to iterate through aAll */
|
||||
char *pEnd = &pDL->aAll[pDL->nAll]; /* 1 byte past end of aAll */
|
||||
if( pDL->pNextDocid ){
|
||||
pIter = pDL->pNextDocid;
|
||||
}else{
|
||||
pIter = pDL->aAll;
|
||||
}
|
||||
|
||||
if( pIter>=pEnd ){
|
||||
/* We have already reached the end of this doclist. EOF. */
|
||||
*pbEof = 1;
|
||||
}else{
|
||||
sqlite3_int64 iDelta;
|
||||
pIter += sqlite3Fts3GetVarint(pIter, &iDelta);
|
||||
if( pTab->bDescIdx==0 || pDL->pNextDocid==0 ){
|
||||
pDL->iDocid += iDelta;
|
||||
}else{
|
||||
pDL->iDocid -= iDelta;
|
||||
}
|
||||
pDL->pList = pIter;
|
||||
fts3PoslistCopy(0, &pIter);
|
||||
pDL->nList = (int)(pIter - pDL->pList);
|
||||
|
||||
/* pIter now points just past the 0x00 that terminates the position-
|
||||
** list for document pDL->iDocid. However, if this position-list was
|
||||
** edited in place by fts3EvalNearTrim(), then pIter may not actually
|
||||
** point to the start of the next docid value. The following line deals
|
||||
** with this case by advancing pIter past the zero-padding added by
|
||||
** fts3EvalNearTrim(). */
|
||||
while( pIter<pEnd && *pIter==0 ) pIter++;
|
||||
|
||||
pDL->pNextDocid = pIter;
|
||||
assert( pIter>=&pDL->aAll[pDL->nAll] || *pIter );
|
||||
*pbEof = 0;
|
||||
}
|
||||
fts3EvalDlPhraseNext(pTab, pDL, pbEof);
|
||||
}
|
||||
|
||||
return rc;
|
||||
@@ -4172,7 +4440,6 @@ static int fts3EvalPhraseNext(
|
||||
static void fts3EvalStartReaders(
|
||||
Fts3Cursor *pCsr, /* FTS Cursor handle */
|
||||
Fts3Expr *pExpr, /* Expression to initialize phrases in */
|
||||
int bOptOk, /* True to enable incremental loading */
|
||||
int *pRc /* IN/OUT: Error code */
|
||||
){
|
||||
if( pExpr && SQLITE_OK==*pRc ){
|
||||
@@ -4183,10 +4450,10 @@ static void fts3EvalStartReaders(
|
||||
if( pExpr->pPhrase->aToken[i].pDeferred==0 ) break;
|
||||
}
|
||||
pExpr->bDeferred = (i==nToken);
|
||||
*pRc = fts3EvalPhraseStart(pCsr, bOptOk, pExpr->pPhrase);
|
||||
*pRc = fts3EvalPhraseStart(pCsr, 1, pExpr->pPhrase);
|
||||
}else{
|
||||
fts3EvalStartReaders(pCsr, pExpr->pLeft, bOptOk, pRc);
|
||||
fts3EvalStartReaders(pCsr, pExpr->pRight, bOptOk, pRc);
|
||||
fts3EvalStartReaders(pCsr, pExpr->pLeft, pRc);
|
||||
fts3EvalStartReaders(pCsr, pExpr->pRight, pRc);
|
||||
pExpr->bDeferred = (pExpr->pLeft->bDeferred && pExpr->pRight->bDeferred);
|
||||
}
|
||||
}
|
||||
@@ -4428,7 +4695,7 @@ static int fts3EvalSelectDeferred(
|
||||
** overflowing the 32-bit integer it is stored in. */
|
||||
if( ii<12 ) nLoad4 = nLoad4*4;
|
||||
|
||||
if( ii==0 || pTC->pPhrase->nToken>1 ){
|
||||
if( ii==0 || (pTC->pPhrase->nToken>1 && ii!=nToken-1) ){
|
||||
/* Either this is the cheapest token in the entire query, or it is
|
||||
** part of a multi-token phrase. Either way, the entire doclist will
|
||||
** (eventually) be loaded into memory. It may as well be now. */
|
||||
@@ -4508,7 +4775,7 @@ static int fts3EvalStart(Fts3Cursor *pCsr){
|
||||
}
|
||||
#endif
|
||||
|
||||
fts3EvalStartReaders(pCsr, pCsr->pExpr, 1, &rc);
|
||||
fts3EvalStartReaders(pCsr, pCsr->pExpr, &rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -4991,6 +5258,16 @@ static int fts3EvalNext(Fts3Cursor *pCsr){
|
||||
pCsr->iPrevId = pExpr->iDocid;
|
||||
}while( pCsr->isEof==0 && fts3EvalTestDeferredAndNear(pCsr, &rc) );
|
||||
}
|
||||
|
||||
/* Check if the cursor is past the end of the docid range specified
|
||||
** by Fts3Cursor.iMinDocid/iMaxDocid. If so, set the EOF flag. */
|
||||
if( rc==SQLITE_OK && (
|
||||
(pCsr->bDesc==0 && pCsr->iPrevId>pCsr->iMaxDocid)
|
||||
|| (pCsr->bDesc!=0 && pCsr->iPrevId<pCsr->iMinDocid)
|
||||
)){
|
||||
pCsr->isEof = 1;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -5014,12 +5291,16 @@ static void fts3EvalRestart(
|
||||
if( pPhrase ){
|
||||
fts3EvalInvalidatePoslist(pPhrase);
|
||||
if( pPhrase->bIncr ){
|
||||
assert( pPhrase->nToken==1 );
|
||||
assert( pPhrase->aToken[0].pSegcsr );
|
||||
sqlite3Fts3MsrIncrRestart(pPhrase->aToken[0].pSegcsr);
|
||||
int i;
|
||||
for(i=0; i<pPhrase->nToken; i++){
|
||||
Fts3PhraseToken *pToken = &pPhrase->aToken[i];
|
||||
assert( pToken->pDeferred==0 );
|
||||
if( pToken->pSegcsr ){
|
||||
sqlite3Fts3MsrIncrRestart(pToken->pSegcsr);
|
||||
}
|
||||
}
|
||||
*pRc = fts3EvalPhraseStart(pCsr, 0, pPhrase);
|
||||
}
|
||||
|
||||
pPhrase->doclist.pNextDocid = 0;
|
||||
pPhrase->doclist.iDocid = 0;
|
||||
}
|
||||
@@ -5268,15 +5549,23 @@ int sqlite3Fts3EvalPhrasePoslist(
|
||||
pIter = pPhrase->doclist.pList;
|
||||
if( iDocid!=pCsr->iPrevId || pExpr->bEof ){
|
||||
int bDescDoclist = pTab->bDescIdx; /* For DOCID_CMP macro */
|
||||
int iMul; /* +1 if csr dir matches index dir, else -1 */
|
||||
int bOr = 0;
|
||||
u8 bEof = 0;
|
||||
Fts3Expr *p;
|
||||
u8 bTreeEof = 0;
|
||||
Fts3Expr *p; /* Used to iterate from pExpr to root */
|
||||
Fts3Expr *pNear; /* Most senior NEAR ancestor (or pExpr) */
|
||||
|
||||
/* Check if this phrase descends from an OR expression node. If not,
|
||||
** return NULL. Otherwise, the entry that corresponds to docid
|
||||
** pCsr->iPrevId may lie earlier in the doclist buffer. */
|
||||
** pCsr->iPrevId may lie earlier in the doclist buffer. Or, if the
|
||||
** tree that the node is part of has been marked as EOF, but the node
|
||||
** itself is not EOF, then it may point to an earlier entry. */
|
||||
pNear = pExpr;
|
||||
for(p=pExpr->pParent; p; p=p->pParent){
|
||||
if( p->eType==FTSQUERY_OR ) bOr = 1;
|
||||
if( p->eType==FTSQUERY_NEAR ) pNear = p;
|
||||
if( p->bEof ) bTreeEof = 1;
|
||||
}
|
||||
if( bOr==0 ) return SQLITE_OK;
|
||||
|
||||
@@ -5295,29 +5584,59 @@ int sqlite3Fts3EvalPhrasePoslist(
|
||||
assert( rc!=SQLITE_OK || pPhrase->bIncr==0 );
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
}
|
||||
|
||||
if( pExpr->bEof ){
|
||||
pIter = 0;
|
||||
iDocid = 0;
|
||||
|
||||
iMul = ((pCsr->bDesc==bDescDoclist) ? 1 : -1);
|
||||
while( bTreeEof==1
|
||||
&& pNear->bEof==0
|
||||
&& (DOCID_CMP(pNear->iDocid, pCsr->iPrevId) * iMul)<0
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
fts3EvalNextRow(pCsr, pExpr, &rc);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
iDocid = pExpr->iDocid;
|
||||
pIter = pPhrase->doclist.pList;
|
||||
}
|
||||
|
||||
bEof = (pPhrase->doclist.nAll==0);
|
||||
assert( bDescDoclist==0 || bDescDoclist==1 );
|
||||
assert( pCsr->bDesc==0 || pCsr->bDesc==1 );
|
||||
|
||||
if( pCsr->bDesc==bDescDoclist ){
|
||||
int dummy;
|
||||
while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)>0 ) && bEof==0 ){
|
||||
sqlite3Fts3DoclistPrev(
|
||||
bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll,
|
||||
&pIter, &iDocid, &dummy, &bEof
|
||||
);
|
||||
}
|
||||
}else{
|
||||
while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){
|
||||
sqlite3Fts3DoclistNext(
|
||||
bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll,
|
||||
&pIter, &iDocid, &bEof
|
||||
);
|
||||
if( bEof==0 ){
|
||||
if( pCsr->bDesc==bDescDoclist ){
|
||||
int dummy;
|
||||
if( pNear->bEof ){
|
||||
/* This expression is already at EOF. So position it to point to the
|
||||
** last entry in the doclist at pPhrase->doclist.aAll[]. Variable
|
||||
** iDocid is already set for this entry, so all that is required is
|
||||
** to set pIter to point to the first byte of the last position-list
|
||||
** in the doclist.
|
||||
**
|
||||
** It would also be correct to set pIter and iDocid to zero. In
|
||||
** this case, the first call to sqltie3Fts4DoclistPrev() below
|
||||
** would also move the iterator to point to the last entry in the
|
||||
** doclist. However, this is expensive, as to do so it has to
|
||||
** iterate through the entire doclist from start to finish (since
|
||||
** it does not know the docid for the last entry). */
|
||||
pIter = &pPhrase->doclist.aAll[pPhrase->doclist.nAll-1];
|
||||
fts3ReversePoslist(pPhrase->doclist.aAll, &pIter);
|
||||
}
|
||||
while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)>0 ) && bEof==0 ){
|
||||
sqlite3Fts3DoclistPrev(
|
||||
bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll,
|
||||
&pIter, &iDocid, &dummy, &bEof
|
||||
);
|
||||
}
|
||||
}else{
|
||||
if( pNear->bEof ){
|
||||
pIter = 0;
|
||||
iDocid = 0;
|
||||
}
|
||||
while( (pIter==0 || DOCID_CMP(iDocid, pCsr->iPrevId)<0 ) && bEof==0 ){
|
||||
sqlite3Fts3DoclistNext(
|
||||
bDescDoclist, pPhrase->doclist.aAll, pPhrase->doclist.nAll,
|
||||
&pIter, &iDocid, &bEof
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+17
-1
@@ -267,6 +267,12 @@ struct Fts3Table {
|
||||
int inTransaction; /* True after xBegin but before xCommit/xRollback */
|
||||
int mxSavepoint; /* Largest valid xSavepoint integer */
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
/* True to disable the incremental doclist optimization. This is controled
|
||||
** by special insert command 'test-no-incr-doclist'. */
|
||||
int bNoIncrDoclist;
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -292,7 +298,8 @@ struct Fts3Cursor {
|
||||
int eEvalmode; /* An FTS3_EVAL_XX constant */
|
||||
int nRowAvg; /* Average size of database rows, in pages */
|
||||
sqlite3_int64 nDoc; /* Documents in table */
|
||||
|
||||
i64 iMinDocid; /* Minimum docid to return */
|
||||
i64 iMaxDocid; /* Maximum docid to return */
|
||||
int isMatchinfoNeeded; /* True when aMatchinfo[] needs filling in */
|
||||
u32 *aMatchinfo; /* Information about most recent match */
|
||||
int nMatchinfo; /* Number of elements in aMatchinfo[] */
|
||||
@@ -322,6 +329,15 @@ struct Fts3Cursor {
|
||||
#define FTS3_DOCID_SEARCH 1 /* Lookup by rowid on %_content table */
|
||||
#define FTS3_FULLTEXT_SEARCH 2 /* Full-text index search */
|
||||
|
||||
/*
|
||||
** The lower 16-bits of the sqlite3_index_info.idxNum value set by
|
||||
** the xBestIndex() method contains the Fts3Cursor.eSearch value described
|
||||
** above. The upper 16-bits contain a combination of the following
|
||||
** bits, used to describe extra constraints on full-text searches.
|
||||
*/
|
||||
#define FTS3_HAVE_LANGID 0x00010000 /* languageid=? */
|
||||
#define FTS3_HAVE_DOCID_GE 0x00020000 /* docid>=? */
|
||||
#define FTS3_HAVE_DOCID_LE 0x00040000 /* docid<=? */
|
||||
|
||||
struct Fts3Doclist {
|
||||
char *aAll; /* Array containing doclist (or NULL) */
|
||||
|
||||
@@ -5050,6 +5050,9 @@ static int fts3SpecialInsert(Fts3Table *p, sqlite3_value *pVal){
|
||||
}else if( nVal>11 && 0==sqlite3_strnicmp(zVal, "maxpending=", 9) ){
|
||||
p->nMaxPendingData = atoi(&zVal[11]);
|
||||
rc = SQLITE_OK;
|
||||
}else if( nVal>21 && 0==sqlite3_strnicmp(zVal, "test-no-incr-doclist=", 21) ){
|
||||
p->bNoIncrDoclist = atoi(&zVal[21]);
|
||||
rc = SQLITE_OK;
|
||||
#endif
|
||||
}else{
|
||||
rc = SQLITE_ERROR;
|
||||
|
||||
+6
-2
@@ -786,6 +786,7 @@ static void amatchFree(amatch_vtab *p){
|
||||
sqlite3_free(p->zVocabTab);
|
||||
sqlite3_free(p->zVocabWord);
|
||||
sqlite3_free(p->zVocabLang);
|
||||
sqlite3_free(p->zSelf);
|
||||
memset(p, 0, sizeof(*p));
|
||||
sqlite3_free(p);
|
||||
}
|
||||
@@ -948,6 +949,9 @@ static void amatchClearCursor(amatch_cursor *pCur){
|
||||
pCur->pAllWords = 0;
|
||||
sqlite3_free(pCur->zInput);
|
||||
pCur->zInput = 0;
|
||||
sqlite3_free(pCur->zBuf);
|
||||
pCur->zBuf = 0;
|
||||
pCur->nBuf = 0;
|
||||
pCur->pCost = 0;
|
||||
pCur->pWord = 0;
|
||||
pCur->pCurrent = 0;
|
||||
@@ -1103,7 +1107,7 @@ static int amatchNext(sqlite3_vtab_cursor *cur){
|
||||
char *zSql;
|
||||
if( p->zVocabLang && p->zVocabLang[0] ){
|
||||
zSql = sqlite3_mprintf(
|
||||
"SELECT \"%s\" FROM \"%s\"",
|
||||
"SELECT \"%w\" FROM \"%w\"",
|
||||
" WHERE \"%w\">=?1 AND \"%w\"=?2"
|
||||
" ORDER BY 1",
|
||||
p->zVocabWord, p->zVocabTab,
|
||||
@@ -1111,7 +1115,7 @@ static int amatchNext(sqlite3_vtab_cursor *cur){
|
||||
);
|
||||
}else{
|
||||
zSql = sqlite3_mprintf(
|
||||
"SELECT \"%s\" FROM \"%s\""
|
||||
"SELECT \"%w\" FROM \"%w\""
|
||||
" WHERE \"%w\">=?1"
|
||||
" ORDER BY 1",
|
||||
p->zVocabWord, p->zVocabTab,
|
||||
|
||||
+16
-3
@@ -38,6 +38,19 @@
|
||||
** out) run the following query:
|
||||
**
|
||||
** SELECT next_char('cha','dictionary','word');
|
||||
**
|
||||
** IMPLEMENTATION NOTES:
|
||||
**
|
||||
** The next_char function is implemented using recursive SQL that makes
|
||||
** use of the table name and column name as part of a query. If either
|
||||
** the table name or column name are keywords or contain special characters,
|
||||
** then they should be escaped. For example:
|
||||
**
|
||||
** SELECT next_char('cha','[dictionary]','[word]');
|
||||
**
|
||||
** This also means that the table name can be a subquery:
|
||||
**
|
||||
** SELECT next_char('cha','(SELECT word AS w FROM dictionary)','w');
|
||||
*/
|
||||
#include "sqlite3ext.h"
|
||||
SQLITE_EXTENSION_INIT1
|
||||
@@ -231,9 +244,9 @@ static void nextCharFunc(
|
||||
zColl = "";
|
||||
}
|
||||
zSql = sqlite3_mprintf(
|
||||
"SELECT \"%w\" FROM \"%w\""
|
||||
" WHERE \"%w\">=(?1 || ?2) %s"
|
||||
" AND \"%w\"<=(?1 || char(1114111)) %s" /* 1114111 == 0x10ffff */
|
||||
"SELECT %s FROM %s"
|
||||
" WHERE %s>=(?1 || ?2) %s"
|
||||
" AND %s<=(?1 || char(1114111)) %s" /* 1114111 == 0x10ffff */
|
||||
" %s"
|
||||
" ORDER BY 1 %s ASC LIMIT 1",
|
||||
zField, zTable, zField, zColl, zField, zColl, zWhereClause, zColl
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
C Revise\sthe\samalgamation\stool\sto\sallow\s'duplicate'\sinclude\sfiles\sto\sbe\sretained\smanually\swhile\sstill\spreserving\sthe\sexisting\sline\snumbers.
|
||||
D 2013-08-31T18:06:52.923
|
||||
C Try\sto\sremember\sstatistics\sfrom\sANALYZE\susing\sLogEst\sinstead\sof\su64.
|
||||
D 2013-10-07T16:53:50.515
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
F Makefile.msc a97163524522cd829cb91bcf900d07608e025502
|
||||
F Makefile.msc 9af063716f726a73b5d5c98c69ea97eca6a9369b
|
||||
F Makefile.vxworks db21ed42a01d5740e656b16f92cb5d8d5e5dd315
|
||||
F README cd04a36fbc7ea56932a4052d7d0b7f09f27c33d6
|
||||
F VERSION a8d1f6839521130dc73c5408cdd24bcfd791df34
|
||||
@@ -78,9 +78,9 @@ F ext/fts3/README.content fdc666a70d5257a64fee209f97cf89e0e6e32b51
|
||||
F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a
|
||||
F ext/fts3/README.tokenizers e0a8b81383ea60d0334d274fadf305ea14a8c314
|
||||
F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d
|
||||
F ext/fts3/fts3.c 0d6311cd433ea30c9e941b93bfeac2f9e6937980
|
||||
F ext/fts3/fts3.c 6d277a3ff6b20ff815184395407c5a4bd7787f9c
|
||||
F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe
|
||||
F ext/fts3/fts3Int.h c7a451661c2d9b2440b2008c3f63ce06f13181d6
|
||||
F ext/fts3/fts3Int.h 8689f7cf85020e7f88d1e761eeac480c3b0ea7ad
|
||||
F ext/fts3/fts3_aux.c b02632f6dd0e375ce97870206d914ea6d8df5ccd
|
||||
F ext/fts3/fts3_expr.c f8eb1046063ba342c7114eba175cabb31c4a64e7
|
||||
F ext/fts3/fts3_hash.c 8dd2d06b66c72c628c2732555a32bc0943114914
|
||||
@@ -96,7 +96,7 @@ F ext/fts3/fts3_tokenizer.h 64c6ef6c5272c51ebe60fc607a896e84288fcbc3
|
||||
F ext/fts3/fts3_tokenizer1.c 5c98225a53705e5ee34824087478cf477bdb7004
|
||||
F ext/fts3/fts3_unicode.c 92391b4b4fb043564c6539ea9b8661e3bcba47b9
|
||||
F ext/fts3/fts3_unicode2.c 0113d3acf13429e6dc38e0647d1bc71211c31a4d
|
||||
F ext/fts3/fts3_write.c ce45c3ea578464f26b0293ea8e54a39694f18b64
|
||||
F ext/fts3/fts3_write.c 851e65f413576055f2e86a63d45b7d67c829db56
|
||||
F ext/fts3/fts3speed.tcl b54caf6a18d38174f1a6e84219950d85e98bb1e9
|
||||
F ext/fts3/mkfts3amal.tcl 252ecb7fe6467854f2aa237bf2c390b74e71f100
|
||||
F ext/fts3/tool/fts3view.c 6cfc5b67a5f0e09c0d698f9fd012c784bfaa9197
|
||||
@@ -106,11 +106,11 @@ F ext/fts3/unicode/mkunicode.tcl dc6f268eb526710e2c6e496c372471d773d0c368
|
||||
F ext/icu/README.txt d9fbbad0c2f647c3fdf715fc9fd64af53aedfc43
|
||||
F ext/icu/icu.c d415ccf984defeb9df2c0e1afcfaa2f6dc05eacb
|
||||
F ext/icu/sqliteicu.h 728867a802baa5a96de7495e9689a8e01715ef37
|
||||
F ext/misc/amatch.c eae8454cd9dcb287b2a3ec2e65a865a4ac5f0d06
|
||||
F ext/misc/amatch.c 678056a4bfcd83c4e82dea81d37543cd1d6dbee1
|
||||
F ext/misc/closure.c 636024302cde41b2bf0c542f81c40c624cfb7012
|
||||
F ext/misc/fuzzer.c 136533c53cfce0957f0b48fa11dba27e21c5c01d
|
||||
F ext/misc/ieee754.c b0362167289170627659e84173f5d2e8fee8566e
|
||||
F ext/misc/nextchar.c 80ba262d23238efcfcb3d72d71aa4513098e26a6
|
||||
F ext/misc/nextchar.c 35c8b8baacb96d92abbb34a83a997b797075b342
|
||||
F ext/misc/percentile.c bcbee3c061b884eccb80e21651daaae8e1e43c63
|
||||
F ext/misc/regexp.c af92cdaa5058fcec1451e49becc7ba44dba023dc
|
||||
F ext/misc/rot13.c 1ac6f95f99b575907b9b09c81a349114cf9be45a
|
||||
@@ -157,36 +157,36 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
|
||||
F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
|
||||
F sqlite3.pc.in 48fed132e7cb71ab676105d2a4dc77127d8c1f3a
|
||||
F src/alter.c 2af0330bb1b601af7a7789bf7229675fd772a083
|
||||
F src/analyze.c 128f85d9bd7e79e93b8b27aa2bb54a43ad0c00f3
|
||||
F src/attach.c fea00cab11c854646a27641a263f5876569a51f9
|
||||
F src/analyze.c 3994309c21b7324217cd32225b7abb5cb1bd1946
|
||||
F src/attach.c 0a17c9364895316ca4f52d06a97a72c0af1ae8b3
|
||||
F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
|
||||
F src/backup.c 2f1987981139bd2f6d8c728d64bf09fb387443c3
|
||||
F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb
|
||||
F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7
|
||||
F src/btree.c b9b57df546df2636294bfb21a986f5707b417df2
|
||||
F src/btree.c d5720cbb21ae56e7e5b07847e05e5b203818acac
|
||||
F src/btree.h bfe0e8c5759b4ec77b0d18390064a6ef3cdffaaf
|
||||
F src/btreeInt.h 51cf220a9b9223354770883e93a859dc377aa27f
|
||||
F src/build.c f63e8929c7f89c0074fbc74929bc946ea117b2f8
|
||||
F src/callback.c d7e46f40c3cf53c43550b7da7a1d0479910b62cc
|
||||
F src/btreeInt.h f038e818bfadf75afbd09819ed93c26a333d39e0
|
||||
F src/build.c 46bb89df0a204eb7154874f966f11d16a7fbced7
|
||||
F src/callback.c f99a8957ba2adf369645fac0db09ad8adcf1caa2
|
||||
F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
|
||||
F src/ctime.c ea4b7f3623a0fcb1146e7f245d7410033e86859c
|
||||
F src/date.c 067a81c9942c497aafd2c260e13add8a7d0c7dd4
|
||||
F src/delete.c 2317c814866d9aa71fea16b3faf4fdd4d6a49b94
|
||||
F src/expr.c 4d89bd03a04fcdb5ff71d86b4e0cc7d3230797b8
|
||||
F src/date.c 65196e95e69f36993659bd7781abe7c2f1994739
|
||||
F src/delete.c 45788c5e48734f2af4acd75a876466e5b9838e34
|
||||
F src/expr.c e7338ccffdc391c53ba2d51c5eb6a2f5299e040e
|
||||
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
|
||||
F src/fkey.c 914a6bbd987d857c41ac9d244efa6641f36faadb
|
||||
F src/func.c 5b064acd303b3e74f019ab551d423ff6cace4023
|
||||
F src/fkey.c be866cd8c4fa6cae98ba33109578fd1a3311ee5b
|
||||
F src/func.c 2c47b65e6e00e3e9374942f28254faf8adafe398
|
||||
F src/global.c 5caf4deab621abb45b4c607aad1bd21c20aac759
|
||||
F src/hash.c ac3470bbf1ca4ae4e306a8ecb0fdf1731810ffe4
|
||||
F src/hash.h 8890a25af81fb85a9ad7790d32eedab4b994da22
|
||||
F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08
|
||||
F src/insert.c a66bcdc956145369c1a876709f47f69476973e15
|
||||
F src/insert.c 9a3f578ffe37f18ef695a06764320db5dc1f0011
|
||||
F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d
|
||||
F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12
|
||||
F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b
|
||||
F src/loadext.c 867c7b330b740c6c917af9956b13b81d0a048303
|
||||
F src/main.c c4c781b06faa2ce4040c32a75fd931a07ba7054e
|
||||
F src/malloc.c fe085aa851b666b7c375c1ff957643dc20a04bf6
|
||||
F src/main.c 35931467ec026b05babb279cb8a573e62f6fe1a3
|
||||
F src/malloc.c 543a8eb5508eaf4cadf55a9b503379eba2088128
|
||||
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
|
||||
F src/mem1.c 437c7c4af964895d4650f29881df63535caaa1fa
|
||||
F src/mem2.c dce31758da87ec2cfa52ba4c5df1aed6e07d8e8f
|
||||
@@ -203,29 +203,29 @@ F src/os.c b4ad71336fd96f97776f75587cd9e8218288f5be
|
||||
F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f
|
||||
F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
|
||||
F src/os_unix.c 243fb37f47dc072fc59839ea241ff0a17c8d76e6
|
||||
F src/os_win.c bb592dfb850e4ee3e4caecce461dca74dc40936d
|
||||
F src/os_win.c b8f54f42d9c232c48cb694b7dbe94e601c816b5c
|
||||
F src/pager.c 2aa4444ffe86e9282d03bc349a4a5e49bd77c0e8
|
||||
F src/pager.h f094af9f6ececfaa8a1e93876905a4f34233fb0c
|
||||
F src/parse.y 27c6b4138497d6f8360ba7847da6ed48033f957f
|
||||
F src/parse.y a97566d6da75075589a7c716d1bda14b586cf8da
|
||||
F src/pcache.c f8043b433a57aba85384a531e3937a804432a346
|
||||
F src/pcache.h a5e4f5d9f5d592051d91212c5949517971ae6222
|
||||
F src/pcache1.c a467393909a4ed7ca9de066d85ba5c5b04a5be63
|
||||
F src/pragma.c 3aa3d8c8623b7b71c5b1bfb72dcc31fb0c25665f
|
||||
F src/pragma.c f4ff6e29c316d06bf7dffca0c8cee7c229cae42e
|
||||
F src/prepare.c fa6988589f39af8504a61731614cd4f6ae71554f
|
||||
F src/printf.c da9119eb31a187a4b99f60aa4a225141c0ebb74b
|
||||
F src/random.c 0b2dbc37fdfbfa6bd455b091dfcef5bdb32dba68
|
||||
F src/resolve.c 9d53899cc6e1f4ec0b4632d07e97d57827bf63b9
|
||||
F src/resolve.c 7459801d02997b07e8b8da85ef255392ba1d022b
|
||||
F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0
|
||||
F src/select.c 8b148eb851f384412aea57091659d14b369918ca
|
||||
F src/shell.c dbe064d404bb497acd8a44c066cd6b8460a71236
|
||||
F src/select.c 19611e6da6646a1090164b29d6b23b7c8e7364ea
|
||||
F src/shell.c 5ee50ca3e35453bbd6ccdf1bdd0f6bbe9738e9fb
|
||||
F src/sqlite.h.in ec40aa958a270416fb04b4f72210357bf163d2c5
|
||||
F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0
|
||||
F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e
|
||||
F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc
|
||||
F src/sqliteInt.h 600086a5082e2291b0aeeefcfbb546f2bbda67b2
|
||||
F src/sqliteInt.h a5fa87b540662fb552ba81c0d4eeb368aebb5af7
|
||||
F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
|
||||
F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158
|
||||
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
|
||||
F src/tclsqlite.c 659dad8ef30b54831306a244b43e37af4725a444
|
||||
F src/tclsqlite.c 3b5f3716e320480659239abe887164521c575d83
|
||||
F src/test1.c 26226cfd2b6dc3f77d2eb27f07ffcf236b4e728b
|
||||
F src/test2.c 7355101c085304b90024f2261e056cdff13c6c35
|
||||
F src/test3.c 1c0e5d6f080b8e33c1ce8b3078e7013fdbcd560c
|
||||
@@ -233,7 +233,7 @@ F src/test4.c 9b32d22f5f150abe23c1830e2057c4037c45b3df
|
||||
F src/test5.c a6d1ac55ac054d0b2b8f37b5e655b6c92645a013
|
||||
F src/test6.c a437f76f9874d2563352a7e6cd0d43217663c220
|
||||
F src/test7.c 126b886b53f0358b92aba9b81d3fcbfbe9a93cd6
|
||||
F src/test8.c 7ee77ea522ae34aa691dfe407139dec80d4fc039
|
||||
F src/test8.c c7aab1d9fbbf54fc33d43b73aa24aa55f9eaf534
|
||||
F src/test9.c bea1e8cf52aa93695487badedd6e1886c321ea60
|
||||
F src/test_async.c 21e11293a2f72080eda70e1124e9102044531cd8
|
||||
F src/test_autoext.c dea8a01a7153b9adc97bd26161e4226329546e12
|
||||
@@ -245,7 +245,7 @@ F src/test_devsym.c e7498904e72ba7491d142d5c83b476c4e76993bc
|
||||
F src/test_fs.c ced436e3d4b8e4681328409b8081051ce614e28f
|
||||
F src/test_func.c f8235719dff4bf9ffee04c55a190af8782ce9ab5
|
||||
F src/test_hexio.c abfdecb6fa58c354623978efceb088ca18e379cd
|
||||
F src/test_init.c 3cbad7ce525aec925f8fda2192d576d47f0d478a
|
||||
F src/test_init.c 66b33120ffe9cd853b5a905ec850d51151337b32
|
||||
F src/test_intarray.c 87847c71c3c36889c0bcc9c4baf9d31881665d61
|
||||
F src/test_intarray.h 2ece66438cfd177b78d1bfda7a4180cd3a10844d
|
||||
F src/test_journal.c f5c0a05b7b3d5930db769b5ee6c3766dc2221a64
|
||||
@@ -272,44 +272,46 @@ F src/test_vfs.c e72f555ef7a59080f898fcf1a233deb9eb704ea9
|
||||
F src/test_vfstrace.c 34b544e80ba7fb77be15395a609c669df2e660a2
|
||||
F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
|
||||
F src/tokenize.c 70061085a51f2f4fc15ece94f32c03bcb78e63b2
|
||||
F src/trigger.c 5c0ea9b8755e7c5e1a700f3e27ac4f8d92dd221e
|
||||
F src/update.c 7d9d38e4f341ada7d79035ea969cdefb8b9014d1
|
||||
F src/trigger.c ba0a883cd536b7dfdd4df3733001f5372a4299da
|
||||
F src/update.c f5182157f5d0d0a97bc5f5e3c9bdba0dfbe08f08
|
||||
F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269
|
||||
F src/util.c f566b5138099a2df8533b190d0dcc74b7dfbe0c9
|
||||
F src/vacuum.c d9c5759f4c5a438bb43c2086f72c5d2edabc36c8
|
||||
F src/vdbe.c 2b1cd2c7e3d74e6aa99ce2f538bfdd07a00dc2f1
|
||||
F src/util.c 2f0c9b1f884d038eb90f48cf17042a88dc1629d3
|
||||
F src/vacuum.c f313bc97123a4dd4bfd3f50a00c4d44c08a5b1b7
|
||||
F src/vdbe.c 56e648f5ba9a91810caf216857adfed9039cd174
|
||||
F src/vdbe.h 4f554b5627f26710c4c36d919110a3fc611ca5c4
|
||||
F src/vdbeInt.h cbe71b8b36d8b3bba5709cc3f436c7e3b47b7b08
|
||||
F src/vdbeapi.c 96b24b946cf21894f63d9393e821baa2f0a80979
|
||||
F src/vdbeaux.c c7fe2695e256dbf254113c4fe90d3ec9aabe3bbe
|
||||
F src/vdbeInt.h ff57f67aee1ba26a3a47e786533dab155ab6dad6
|
||||
F src/vdbeapi.c 93a22a9ba2abe292d5c2cf304d7eb2e894dde0ed
|
||||
F src/vdbeaux.c 55f4858fe6abd84bd7311acbf30a75a28903ec25
|
||||
F src/vdbeblob.c 5dc79627775bd9a9b494dd956e26297946417d69
|
||||
F src/vdbemem.c 4511e1d2304a7d7916d14be20080036331740fcf
|
||||
F src/vdbemem.c 817ce21ab4ca57f902619bb8fef3f8a51bbd0ed8
|
||||
F src/vdbesort.c 3937e06b2a0e354500e17dc206ef4c35770a5017
|
||||
F src/vdbetrace.c e7ec40e1999ff3c6414424365d5941178966dcbc
|
||||
F src/vtab.c 165ce0e797c2cd23badb104c9f2ae9042d6d942c
|
||||
F src/vtab.c 5a423b042eb1402ef77697d03d6a67378d97bc8d
|
||||
F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4
|
||||
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
|
||||
F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73
|
||||
F src/where.c 83f6106e0edfa23d1258c617cd58e3125277a363
|
||||
F src/walker.c e9e593d5bb798c3e67fc3893dfe7055c9e7d8d74
|
||||
F src/where.c 7916e32a4d7f8cc891a08de09380ef519415d275
|
||||
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
|
||||
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
|
||||
F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6
|
||||
F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87
|
||||
F test/all.test 6ff7b43c2b4b905c74dc4a813d201d0fa64c5783
|
||||
F test/alter.test 7e771c3c3f401198557dbbcf4a2c21950ba934f3
|
||||
F test/alter.test 775a1dded3f8247983c9a3e767b011d9a5114442
|
||||
F test/alter2.test 7ea05c7d92ac99349a802ef7ada17294dd647060
|
||||
F test/alter3.test 49c9d9fba2b8fcdce2dedeca97bbf1f369cc548d
|
||||
F test/alter4.test 8e93bf7a7e6919b14b0c9a6c1e4908bcf21b0165
|
||||
F test/altermalloc.test e81ac9657ed25c6c5bb09bebfa5a047cd8e4acfc
|
||||
F test/amatch1.test b5ae7065f042b7f4c1c922933f4700add50cdb9f
|
||||
F test/analyze.test 1772936d66471c65221e437b6d1999c3a03166c4
|
||||
F test/analyze3.test 412f690dfe95b337475e3e78a84a85d25f6f125d
|
||||
F test/analyze4.test eff2df19b8dd84529966420f29ea52edc6b56213
|
||||
F test/analyze5.test 765c4e284aa69ca172772aa940946f55629bc8c4
|
||||
F test/analyze6.test 19151da2c4e918905d2081b74ac5c4d47fc850ab
|
||||
F test/analyze6.test d31defa011a561b938b4608d3538c1b4e0b5e92c
|
||||
F test/analyze7.test bb1409afc9e8629e414387ef048b8e0e3e0bdc4f
|
||||
F test/analyze8.test 093d15c1c888eed5034304a98c992f7360130b88
|
||||
F test/analyze9.test 3095a9ebfea4a2b1f9db60375320ae7f219595ba
|
||||
F test/analyze9.test 1b9b7e9a096d1536f03d9ad7b72f638ef5669347
|
||||
F test/analyzeA.test 1a5c40079894847976d983ca39c707aaa44b6944
|
||||
F test/analyzeB.test 8bf35ee0a548aea831bf56762cb8e7fdb1db083d
|
||||
F test/async.test 1d0e056ba1bb9729283a0f22718d3a25e82c277b
|
||||
F test/async2.test c0a9bd20816d7d6a2ceca7b8c03d3d69c28ffb8b
|
||||
F test/async3.test d73a062002376d7edc1fe3edff493edbec1fc2f7
|
||||
@@ -340,7 +342,7 @@ F test/badutf2.test f5bc7f2d280670ecd79b9cf4f0f1760c607fe51f
|
||||
F test/bc_common.tcl 5c8689cc6d2fb44b7c0968ae4f85eb26d50022fa
|
||||
F test/between.test 34d375fb5ce1ae283ffe82b6b233e9f38e84fc6c
|
||||
F test/bigfile.test aa74f4e5db51c8e54a1d9de9fa65d01d1eb20b59
|
||||
F test/bigfile2.test 7c79f1ef0c6c2c2bc1e7bd895596fab32bfb4796
|
||||
F test/bigfile2.test 1b489a3a39ae90c7f027b79110d6b4e1dbc71bfc
|
||||
F test/bigrow.test f0aeb7573dcb8caaafea76454be3ade29b7fc747
|
||||
F test/bind.test 3c7b320969000c441a70952b0b15938fbb66237c
|
||||
F test/bindxfer.test efecd12c580c14df5f4ad3b3e83c667744a4f7e0
|
||||
@@ -412,7 +414,7 @@ F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
|
||||
F test/createtab.test b5de160630b209c4b8925bdcbbaf48cc90b67fe8
|
||||
F test/cse.test 277350a26264495e86b1785f34d2d0c8600e021c
|
||||
F test/ctime.test 7bd009071e242aac4f18521581536b652b789a47
|
||||
F test/date.test f3228180c87bbe5d39c9397bf001c0095c3821b9
|
||||
F test/date.test 502ddcbaaac9ce103bcd76d8e9d9bc8aa04e61b0
|
||||
F test/dbstatus.test aee30c3f337e6c217ff06df59fb8fe6e6448dce2
|
||||
F test/dbstatus2.test 10418e62b3db5dca070f0c3eef3ea13946f339c2
|
||||
F test/default.test 6faf23ccb300114924353007795aa9a8ec0aa9dc
|
||||
@@ -444,7 +446,7 @@ F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea
|
||||
F test/enc2.test 83437a79ba1545a55fb549309175c683fb334473
|
||||
F test/enc3.test 90683ad0e6ea587b9d5542ca93568af9a9858c40
|
||||
F test/enc4.test c8f1ce3618508fd0909945beb8b8831feef2c020
|
||||
F test/eqp.test d9e7ad4e7bd36d976f1b631f76e6e6ea090c41a0
|
||||
F test/eqp.test 57c6c604c2807fb5531731c5323133453c24afac
|
||||
F test/errmsg.test 050717f1c6a5685de9c79f5f9f6b83d7c592f73a
|
||||
F test/eval.test bc269c365ba877554948441e91ad5373f9f91be3
|
||||
F test/exclusive.test c7ebbc756eacf544c108b15eed64d7d4e5f86b75
|
||||
@@ -461,6 +463,7 @@ F test/fkey3.test 5ec899d12b13bcf1e9ef40eff7fb692fdb91392e
|
||||
F test/fkey4.test 86446017011273aad8f9a99c1a65019e7bd9ca9d
|
||||
F test/fkey5.test 0bf64f2d19ad80433ca0b24edbf604a18b353d5f
|
||||
F test/fkey6.test c555f7fc45d842cc84b0d3ff93951ce2b8c25fc8
|
||||
F test/fkey7.test e31d0e71a41c1d29349a16448d6c420e2c53a8fc
|
||||
F test/fkey_malloc.test bb74c9cb8f8fceed03b58f8a7ef2df98520bbd51
|
||||
F test/format4.test 1f0cac8ff3895e9359ed87e41aaabee982a812eb
|
||||
F test/fts-9fd058691.test 78b887e30ae6816df0e1fed6259de4b5a64ad33c
|
||||
@@ -528,6 +531,7 @@ F test/fts3cov.test e0fb00d8b715ddae4a94c305992dfc3ef70353d7
|
||||
F test/fts3d.test bf640d79722b720fa1c81834c48cdaa45d531b1a
|
||||
F test/fts3defer.test 0be4440b73a2e651fc1e472066686d6ada4b9963
|
||||
F test/fts3defer2.test a3b6cbeabaf28c9398652a4d101ea224d9358479
|
||||
F test/fts3defer3.test dd53fc13223c6d8264a98244e9b19abd35ed71cd
|
||||
F test/fts3drop.test 1b906e293d6773812587b3dc458cb9e8f3f0c297
|
||||
F test/fts3e.test 1f6c6ac9cc8b772ca256e6b22aaeed50c9350851
|
||||
F test/fts3expr.test 5e745b2b6348499d9ef8d59015de3182072c564c
|
||||
@@ -544,20 +548,22 @@ F test/fts3prefix2.test e1f0a822ca661dced7f12ce392e14eaf65609dce
|
||||
F test/fts3query.test 4fefd43ff24993bc2c9b2778f2bec0cc7629e7ed
|
||||
F test/fts3rnd.test 1320d8826a845e38a96e769562bf83d7a92a15d0
|
||||
F test/fts3shared.test 57e26a801f21027b7530da77db54286a6fe4997e
|
||||
F test/fts3snippet.test 24d6ff1920a70fd970c401a8525834b4ad12cece
|
||||
F test/fts3snippet.test d524af6bcef4714e059ef559113dbdc924cd33d1
|
||||
F test/fts3sort.test ed34c716a11cc2009a35210e84ad5f9c102362ca
|
||||
F test/fts3tok1.test b10d0a12a0ab5f905cea1200b745de233f37443f
|
||||
F test/fts3tok_err.test 52273cd193b9036282f7bacb43da78c6be87418d
|
||||
F test/fts4aa.test 95f448fb02c4a976968b08d1b4ce134e720946ae
|
||||
F test/fts4aa.test 0c3152322c7f0b548cc942ad763eaba0da87ccca
|
||||
F test/fts4check.test 66fa274cab2b615f2fb338b257713aba8fad88a8
|
||||
F test/fts4content.test 2e7252557d6d24afa101d9ba1de710d6140e6d06
|
||||
F test/fts4docid.test e33c383cfbdff0284685604d256f347a18fdbf01
|
||||
F test/fts4incr.test 2fae04582c2329a038b2b1f985e702478fb94888
|
||||
F test/fts4langid.test 24a6e41063b416bbdf371ff6b4476fa41c194aa7
|
||||
F test/fts4merge.test c424309743fdd203f8e56a1f1cd7872cd66cc0ee
|
||||
F test/fts4merge2.test 5faa558d1b672f82b847d2a337465fa745e46891
|
||||
F test/fts4merge3.test aab02a09f50fe6baaddc2e159c3eabc116d45fc7
|
||||
F test/fts4merge4.test c19c85ca1faa7b6d536832b49c12e1867235f584
|
||||
F test/fts4noti.test aed33ba44808852dcb24bf70fa132e7bf530f057
|
||||
F test/fts4unicode.test 5fa8e0a7899d906d114345c605250ebfa9d8ed28
|
||||
F test/fts4unicode.test ebd937061e1ce096240d2352feb424587f2187b9
|
||||
F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d
|
||||
F test/func.test cd25cf605c5a345d038dc7b84232204c6a901c84
|
||||
F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f
|
||||
@@ -570,6 +576,7 @@ F test/fuzz_common.tcl a87dfbb88c2a6b08a38e9a070dabd129e617b45b
|
||||
F test/fuzz_malloc.test 328f70aaca63adf29b4c6f06505ed0cf57ca7c26
|
||||
F test/fuzzer1.test d4c52aaf3ef923da293a2653cfab33d02f718a36
|
||||
F test/fuzzerfault.test 8792cd77fd5bce765b05d0c8e01b9edcf8af8536
|
||||
F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98
|
||||
F test/hook.test 45cb22b940c3cc0af616ba7430f666e245711a48
|
||||
F test/icu.test 70df4faca133254c042d02ae342c0a141f2663f4
|
||||
F test/in.test 5941096407d8c133b9eff15bd3e666624b6cbde3
|
||||
@@ -592,7 +599,7 @@ F test/index2.test ee83c6b5e3173a3d7137140d945d9a5d4fdfb9d6
|
||||
F test/index3.test 423a25c789fc8cc51aaf2a4370bbdde2d9e9eed7
|
||||
F test/index4.test 2983216eb8c86ee62d9ed7cb206b5cc3331c0026
|
||||
F test/index5.test fc07c14193c0430814e7a08b5da46888ee795c33
|
||||
F test/index6.test e96324d8c1ade4b30a4c6cee14b1fc2e5a367cda
|
||||
F test/index6.test 9996f064672c03e768e256e4bf7cff4b63e8b109
|
||||
F test/indexedby.test b2f22f3e693a53813aa3f50b812eb609ba6df1ec
|
||||
F test/indexfault.test 31d4ab9a7d2f6e9616933eb079722362a883eb1d
|
||||
F test/init.test 15c823093fdabbf7b531fe22cf037134d09587a7
|
||||
@@ -651,7 +658,7 @@ F test/malloc6.test 2f039d9821927eacae43e1831f815e157659a151
|
||||
F test/malloc7.test 7c68a32942858bc715284856c5507446bba88c3a
|
||||
F test/malloc8.test 9b7a3f8cb9cf0b12fff566e80a980b1767bd961d
|
||||
F test/malloc9.test 2307c6ee3703b0a21391f3ea92388b4b73f9105e
|
||||
F test/mallocA.test 71e4b57e640c017cf2833e51fe6e8e43e8575b73
|
||||
F test/mallocA.test 1ba0367fb5434e7bc2fa4afcb30b14174d91b160
|
||||
F test/mallocAll.test 98f1be74bc9f49a858bc4f361fc58e26486798be
|
||||
F test/mallocB.test bc475ab850cda896142ab935bbfbc74c24e51ed6
|
||||
F test/mallocC.test 3dffe16532f109293ce1ccecd0c31dca55ef08c4
|
||||
@@ -716,8 +723,8 @@ F test/pagesize.test 1dd51367e752e742f58e861e65ed7390603827a0
|
||||
F test/pcache.test b09104b03160aca0d968d99e8cd2c5b1921a993d
|
||||
F test/pcache2.test a83efe2dec0d392f814bfc998def1d1833942025
|
||||
F test/percentile.test b98fc868d71eb5619d42a1702e9ab91718cbed54
|
||||
F test/permutations.test c5e7ae8a18cb8a0ced38dbbc9e2463536c1de45b
|
||||
F test/pragma.test 5e7de6c32a5d764f09437d2025f07e4917b9e178
|
||||
F test/permutations.test 72f4f8881d388163ddbbeec0a6ed812e863ea2e6
|
||||
F test/pragma.test de128f0253ee42a1edf6c80f21813babfb19bd3b
|
||||
F test/pragma2.test 224f0381f9411a78ae685cac24c13656a62021b7
|
||||
F test/printf.test ec9870c4dce8686a37818e0bf1aba6e6a1863552
|
||||
F test/progress.test a282973d1d17f08071bc58a77d6b80f2a81c354d
|
||||
@@ -725,8 +732,8 @@ F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc
|
||||
F test/queryonly.test 5f653159e0f552f0552d43259890c1089391dcca
|
||||
F test/quick.test 1681febc928d686362d50057c642f77a02c62e57
|
||||
F test/quota-glob.test 32901e9eed6705d68ca3faee2a06b73b57cb3c26
|
||||
F test/quota.test b5b3eec55a059e0fe493c66c6e27bd2c07676cfd
|
||||
F test/quota2.test 6d2bd57e8a4da28817f46db9da18551211cd325f
|
||||
F test/quota.test 2379902c25e291eac5c12b4cf96946a3447e3744
|
||||
F test/quota2.test 7dc12e08b11cbc4c16c9ba2aa2e040ea8d8ab4b8
|
||||
F test/quote.test 215897dbe8de1a6f701265836d6601cc6ed103e6
|
||||
F test/randexpr1.tcl 40dec52119ed3a2b8b2a773bce24b63a3a746459
|
||||
F test/randexpr1.test eda062a97e60f9c38ae8d806b03b0ddf23d796df
|
||||
@@ -771,7 +778,7 @@ F test/selectE.test fc02a1eb04c8eb537091482644b7d778ae8759b7
|
||||
F test/server1.test 46803bd3fe8b99b30dbc5ff38ffc756f5c13a118
|
||||
F test/shared.test 1da9dbad400cee0d93f252ccf76e1ae007a63746
|
||||
F test/shared2.test 03eb4a8d372e290107d34b6ce1809919a698e879
|
||||
F test/shared3.test ebf77f023f4bdaa8f74f65822b559e86ce5c6257
|
||||
F test/shared3.test fcd65cb11d189eff5f5c85cc4fad246fb0933108
|
||||
F test/shared4.test 72d90821e8d2fc918a08f16d32880868d8ee8e9d
|
||||
F test/shared6.test 866bb4982c45ce216c61ded5e8fde4e7e2f3ffa9
|
||||
F test/shared7.test 960760bc8d03e1419e70dea69cf41db62853616e
|
||||
@@ -779,17 +786,17 @@ F test/shared8.test 00a07bf5e1337ecf72e94542bdefdc330d7a2538
|
||||
F test/shared9.test 5f2a8f79b4d6c7d107a01ffa1ed05ae7e6333e21
|
||||
F test/sharedA.test 0cdf1a76dfa00e6beee66af5b534b1e8df2720f5
|
||||
F test/shared_err.test 0079c05c97d88cfa03989b7c20a8b266983087aa
|
||||
F test/sharedlock.test 927a4b6da11978c82b857dbdb20a932aad732123
|
||||
F test/shell1.test 928547277d385038c696428e9d791cbbad098974
|
||||
F test/shell2.test 037d6ad16e873354195d30bb2dc4b5321788154a
|
||||
F test/shell3.test 9196c42772d575685e722c92b4b39053c6ebba59
|
||||
F test/sharedlock.test 5ede3c37439067c43b0198f580fd374ebf15d304
|
||||
F test/shell1.test e7c0b9ebda25d5e78f0a3ea0dc4e31bb6d8098c0
|
||||
F test/shell2.test e1d3790f064e50b2f973502f45750012667486df
|
||||
F test/shell3.test 5e8545ec72c4413a0e8d4c6be56496e3c257ca29
|
||||
F test/shell4.test aa4eef8118b412d1a01477a53426ece169ea86a9
|
||||
F test/shell5.test bfa21ecc173adcbc15db2c075baa468778f67f88
|
||||
F test/shell5.test 46c8c18d62732415c4fe084816c13d559831705e
|
||||
F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3
|
||||
F test/shrink.test 8c70f62b6e8eb4d54533de6d65bd06b1b9a17868
|
||||
F test/sidedelete.test f0ad71abe6233e3b153100f3b8d679b19a488329
|
||||
F test/soak.test 0b5b6375c9f4110c828070b826b3b4b0bb65cd5f
|
||||
F test/softheap1.test c16709a16ad79fa43b32929b2e623d1d117ccf53
|
||||
F test/softheap1.test 40562fe6cac6d9827b7b42b86d45aedf12c15e24
|
||||
F test/sort.test 0e4456e729e5a92a625907c63dcdedfbe72c5dc5
|
||||
F test/speed1.test f2974a91d79f58507ada01864c0e323093065452
|
||||
F test/speed1p.explain d841e650a04728b39e6740296b852dccdca9b2cb
|
||||
@@ -799,11 +806,11 @@ F test/speed3.test d32043614c08c53eafdc80f33191d5bd9b920523
|
||||
F test/speed4.test abc0ad3399dcf9703abed2fff8705e4f8e416715
|
||||
F test/speed4p.explain 6b5f104ebeb34a038b2f714150f51d01143e59aa
|
||||
F test/speed4p.test 0e51908951677de5a969b723e03a27a1c45db38b
|
||||
F test/spellfix.test 38246facf7d9d7eeb8a57d7497cf7ce73ce5785d
|
||||
F test/spellfix.test 8c40b169b104086d8795781f670ba3c786d6d8be
|
||||
F test/sqllimits1.test b1aae27cc98eceb845e7f7adf918561256e31298
|
||||
F test/stat.test be8d477306006ec696bc86757cfb34bec79447ce
|
||||
F test/stmt.test 25d64e3dbf9a3ce89558667d7f39d966fe2a71b9
|
||||
F test/subquery.test 3b97763ada8b3a4092d2c80db3ebc0e7870e7eaf
|
||||
F test/subquery.test 666fdecceac258f5fd84bed09a64e49d9f37edd9
|
||||
F test/subquery2.test 91e1e364072aeff431d1f9689b15147e421d88c7
|
||||
F test/subselect.test d24fd8757daf97dafd2e889c73ea4c4272dcf4e4
|
||||
F test/substr.test 18f57c4ca8a598805c4d64e304c418734d843c1a
|
||||
@@ -849,7 +856,7 @@ F test/tkt-5e10420e8d.test 904d1687b3c06d43e5b3555bbcf6802e7c0ffd84
|
||||
F test/tkt-5ee23731f.test 9db6e1d7209dc0794948b260d6f82b2b1de83a9f
|
||||
F test/tkt-6bfb98dfc0.test 24780633627b5cfc0635a5500c2389ebfb563336
|
||||
F test/tkt-752e1646fc.test ea78d88d14fe9866bdd991c634483334639e13bf
|
||||
F test/tkt-78e04e52ea.test 787b70cfb0488c356266bb8d5ad8a657f9efceb8
|
||||
F test/tkt-78e04e52ea.test b0190d3375cf88b97d32188149cc99ccf22f556b
|
||||
F test/tkt-7a31705a7e6.test e75a2bba4eec801b92c8040eb22096ac6d35e844
|
||||
F test/tkt-7bbfb7d442.test 7b2cd79c7a17ae6750e75ec1a7846712a69c9d18
|
||||
F test/tkt-80ba201079.test 105a721e6aad0ae3c5946d7615d1e4d03f6145b8
|
||||
@@ -962,6 +969,7 @@ F test/tkt3992.test f3e7d548ac26f763b47bc0f750da3d03c81071da
|
||||
F test/tkt3997.test a335fa41ca3985660a139df7b734a26ef53284bd
|
||||
F test/tkt4018.test 7c2c9ba4df489c676a0a7a0e809a1fb9b2185bd1
|
||||
F test/tokenize.test ce430a7aed48fc98301611429595883fdfcab5d7
|
||||
F test/tpch01.test 8f4ac52f62f3e9f6bce0889105aecdf0275e331b
|
||||
F test/trace.test 4b36a41a3e9c7842151af6da5998f5080cdad9e5
|
||||
F test/trace2.test e7a988fdd982cdec62f1f1f34b0360e6476d01a0
|
||||
F test/trans.test 6e1b4c6a42dba31bd65f8fa5e61a2708e08ddde6
|
||||
@@ -981,6 +989,7 @@ F test/triggerA.test fe5597f47ee21bacb4936dc827994ed94161e332
|
||||
F test/triggerB.test 56780c031b454abac2340dbb3b71ac5c56c3d7fe
|
||||
F test/triggerC.test a7b4367392c755bc5fd5fff88011753e6b6afe90
|
||||
F test/triggerD.test 8e7f3921a92a5797d472732108109e44575fa650
|
||||
F test/triggerE.test 355e9c5cbaed5cd039a60baad1fb2197caeb8e52
|
||||
F test/tt3_checkpoint.c 415eccce672d681b297485fc20f44cdf0eac93af
|
||||
F test/types.test bf816ce73c7dfcfe26b700c19f97ef4050d194ff
|
||||
F test/types2.test 3555aacf8ed8dc883356e59efc314707e6247a84
|
||||
@@ -1041,8 +1050,8 @@ F test/walro.test 6cc247a0cc9b36aeea2057dd28a922a1cdfbd630
|
||||
F test/walshared.test 0befc811dcf0b287efae21612304d15576e35417
|
||||
F test/walslow.test e7be6d9888f83aa5d3d3c7c08aa9b5c28b93609a
|
||||
F test/walthread.test de8dbaf6d9e41481c460ba31ca61e163d7348f8e
|
||||
F test/where.test da54153a4c1571ea1b95659e5bec8119edf786aa
|
||||
F test/where2.test 76d5346f7edb2a6a0442dcf3e9d088ac6903e0b5
|
||||
F test/where.test 701a633ed16c661cd597b9d504b485197a0f49d7
|
||||
F test/where2.test ed6baa9420a109d8be683dbef5d153d186f3690b
|
||||
F test/where3.test d28c51f257e60be30f74308fa385ceeddfb54a6e
|
||||
F test/where4.test e9b9e2f2f98f00379e6031db6a6fca29bae782a2
|
||||
F test/where5.test fdf66f96d29a064b63eb543e28da4dfdccd81ad2
|
||||
@@ -1057,32 +1066,36 @@ F test/whereC.test d6f4ecd4fa2d9429681a5b22a25d2bda8e86ab8a
|
||||
F test/whereD.test 6c2feb79ef1f68381b07f39017fe5f9b96da8d62
|
||||
F test/whereE.test b3a055eef928c992b0a33198a7b8dc10eea5ad2f
|
||||
F test/whereF.test 5b2ba0dbe8074aa13e416b37c753991f0a2492d7
|
||||
F test/whereG.test 2a3d5181decc801b36600fa1c40b0dad2ccc267f
|
||||
F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31
|
||||
F test/wild001.test bca33f499866f04c24510d74baf1e578d4e44b1c
|
||||
F test/win32lock.test 7a6bd73a5dcdee39b5bb93e92395e1773a194361
|
||||
F test/win32longpath.test e2aafc07e6990fe86c69be22a3d1a0e210cd329b
|
||||
F test/zeroblob.test caaecfb4f908f7bc086ed238668049f96774d688
|
||||
F test/zerodamage.test 209d7ed441f44cc5299e4ebffbef06fd5aabfefd
|
||||
F tool/build-all-msvc.bat c55f64ca200308fb5fa5c1ee751ea95a13977b5a x
|
||||
F tool/build-all-msvc.bat 38623a30fd58288fda5cc7f7df2682aaab75c9d5 x
|
||||
F tool/build-shell.sh 950f47c6174f1eea171319438b93ba67ff5bf367
|
||||
F tool/checkSpacing.c 810e51703529a204fc4e1eb060e9ab663e3c06d2
|
||||
F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b
|
||||
F tool/extract.c 054069d81b095fbdc189a6f5d4466e40380505e2
|
||||
F tool/fast_vacuum.c 5ba0d6f5963a0a63bdc42840f678bad75b2ebce1
|
||||
F tool/fragck.tcl 5265a95126abcf6ab357f7efa544787e5963f439
|
||||
F tool/genfkey.README cf68fddd4643bbe3ff8e31b8b6d8b0a1b85e20f4
|
||||
F tool/genfkey.test 4196a8928b78f51d54ef58e99e99401ab2f0a7e5
|
||||
F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce
|
||||
F tool/lemon.c 680980c7935bfa1edec20c804c9e5ba4b1dd96f5
|
||||
F tool/lemon.c 323e54ac86fb2393f9950219224e304620d2fb12
|
||||
F tool/lempar.c 01ca97f87610d1dac6d8cd96ab109ab1130e76dc
|
||||
F tool/logest.c 7ad625cac3d54012b27d468b7af6612f78b9ba75
|
||||
F tool/mkautoconfamal.sh f8d8dbf7d62f409ebed5134998bf5b51d7266383
|
||||
F tool/mkkeywordhash.c bb52064aa614e1426445e4b2b9b00eeecd23cc79
|
||||
F tool/mkopts.tcl 66ac10d240cc6e86abd37dc908d50382f84ff46e
|
||||
F tool/mkpragmatab.tcl ceaaeebcd882864caefe4176592ca6fa4648fab1
|
||||
F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97
|
||||
F tool/mksqlite3c-noext.tcl 8bce31074e4cbe631bb7676526a048335f4c9f02
|
||||
F tool/mksqlite3c.tcl d344cc3144a0271cd853c5e3df36e9f31d78d619
|
||||
F tool/mksqlite3h.tcl ba24038056f51fde07c0079c41885ab85e2cff12
|
||||
F tool/mksqlite3internalh.tcl 3dca7bb5374cee003379b8cbac73714f610ef795
|
||||
F tool/mkvsix.tcl 0be7f7a591f1e83f9199cb82911b66668ca484c9
|
||||
F tool/mkvsix.tcl f3312df26fd9938a27fa0a845ec96bea84b0c16b
|
||||
F tool/offsets.c fe4262fdfa378e8f5499a42136d17bf3b98f6091
|
||||
F tool/omittest.tcl 4665982e95a6e5c1bd806cf7bc3dea95be422d77
|
||||
F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
|
||||
@@ -1093,7 +1106,7 @@ F tool/showjournal.c b62cecaab86a4053d944c276bb5232e4d17ece02
|
||||
F tool/showwal.c 3f7f7da5ec0cba51b1449a75f700493377da57b5
|
||||
F tool/soak1.tcl 8d407956e1a45b485a8e072470a3e629a27037fe
|
||||
F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b
|
||||
F tool/spaceanal.tcl f87fc8e459e3e42255b52987fe0dda3f8a8c513d
|
||||
F tool/spaceanal.tcl d8c11da184b1a13d0456d786e70b3867e141b74a
|
||||
F tool/speedtest.tcl 06c76698485ccf597b9e7dbb1ac70706eb873355
|
||||
F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
|
||||
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
@@ -1107,9 +1120,11 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06
|
||||
F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
|
||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
|
||||
F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae
|
||||
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
|
||||
P b1811baab6e35ecb1ba920a7ed3302997758d309
|
||||
R c09e9aaa82ece462d9ada3bc7aee07de
|
||||
U mistachkin
|
||||
Z 9761d739f96263a417653d62e6565ea2
|
||||
F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
|
||||
P 1d7b2dc0eae70c0c0e523b715acf758bb4cfa9ac
|
||||
R faf619696f929769ec0cefbeba9e27c2
|
||||
T *branch * log-stats
|
||||
T *sym-log-stats *
|
||||
T -sym-row-size-est *
|
||||
U drh
|
||||
Z 72baf94bdfc7ce8839761e1732e0e2d4
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
aa48284637b954d63bcf77e19b25e75c7ad1a6d3
|
||||
8e78557a40a6b97009852f5b72e68d6483fb00fc
|
||||
+104
-68
@@ -347,7 +347,7 @@ static void statInit(
|
||||
p->mxSample = mxSample;
|
||||
p->nPSample = (tRowcnt)(sqlite3_value_int64(argv[1])/(mxSample/3+1) + 1);
|
||||
p->current.anLt = &p->current.anEq[nColUp];
|
||||
sqlite3_randomness(sizeof(p->iPrn), &p->iPrn);
|
||||
p->iPrn = nCol*0x689e962d ^ sqlite3_value_int(argv[1])*0xd0944565;
|
||||
|
||||
/* Set up the Stat4Accum.a[] and aBest[] arrays */
|
||||
p->a = (struct Stat4Sample*)&p->current.anLt[nColUp];
|
||||
@@ -371,8 +371,7 @@ static void statInit(
|
||||
}
|
||||
static const FuncDef statInitFuncdef = {
|
||||
1+IsStat34, /* nArg */
|
||||
SQLITE_UTF8, /* iPrefEnc */
|
||||
0, /* flags */
|
||||
SQLITE_UTF8, /* funcFlags */
|
||||
0, /* pUserData */
|
||||
0, /* pNext */
|
||||
statInit, /* xFunc */
|
||||
@@ -383,24 +382,63 @@ static const FuncDef statInitFuncdef = {
|
||||
0 /* pDestructor */
|
||||
};
|
||||
|
||||
#ifdef SQLITE_ENABLE_STAT4
|
||||
/*
|
||||
** pNew and pOld are both candidate non-periodic samples selected for
|
||||
** the same column (pNew->iCol==pOld->iCol). Ignoring this column and
|
||||
** considering only any trailing columns and the sample hash value, this
|
||||
** function returns true if sample pNew is to be preferred over pOld.
|
||||
** In other words, if we assume that the cardinalities of the selected
|
||||
** column for pNew and pOld are equal, is pNew to be preferred over pOld.
|
||||
**
|
||||
** This function assumes that for each argument sample, the contents of
|
||||
** the anEq[] array from pSample->anEq[pSample->iCol+1] onwards are valid.
|
||||
*/
|
||||
static int sampleIsBetterPost(
|
||||
Stat4Accum *pAccum,
|
||||
Stat4Sample *pNew,
|
||||
Stat4Sample *pOld
|
||||
){
|
||||
int nCol = pAccum->nCol;
|
||||
int i;
|
||||
assert( pNew->iCol==pOld->iCol );
|
||||
for(i=pNew->iCol+1; i<nCol; i++){
|
||||
if( pNew->anEq[i]>pOld->anEq[i] ) return 1;
|
||||
if( pNew->anEq[i]<pOld->anEq[i] ) return 0;
|
||||
}
|
||||
if( pNew->iHash>pOld->iHash ) return 1;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
|
||||
/*
|
||||
** Return true if pNew is to be preferred over pOld.
|
||||
**
|
||||
** This function assumes that for each argument sample, the contents of
|
||||
** the anEq[] array from pSample->anEq[pSample->iCol] onwards are valid.
|
||||
*/
|
||||
static int sampleIsBetter(Stat4Sample *pNew, Stat4Sample *pOld){
|
||||
static int sampleIsBetter(
|
||||
Stat4Accum *pAccum,
|
||||
Stat4Sample *pNew,
|
||||
Stat4Sample *pOld
|
||||
){
|
||||
tRowcnt nEqNew = pNew->anEq[pNew->iCol];
|
||||
tRowcnt nEqOld = pOld->anEq[pOld->iCol];
|
||||
|
||||
assert( pOld->isPSample==0 && pNew->isPSample==0 );
|
||||
assert( IsStat4 || (pNew->iCol==0 && pOld->iCol==0) );
|
||||
|
||||
if( (nEqNew>nEqOld)
|
||||
|| (nEqNew==nEqOld && pNew->iCol<pOld->iCol)
|
||||
|| (nEqNew==nEqOld && pNew->iCol==pOld->iCol && pNew->iHash>pOld->iHash)
|
||||
){
|
||||
return 1;
|
||||
if( (nEqNew>nEqOld) ) return 1;
|
||||
#ifdef SQLITE_ENABLE_STAT4
|
||||
if( nEqNew==nEqOld ){
|
||||
if( pNew->iCol<pOld->iCol ) return 1;
|
||||
return (pNew->iCol==pOld->iCol && sampleIsBetterPost(pAccum, pNew, pOld));
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
return (nEqNew==nEqOld && pNew->iHash>pOld->iHash);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -423,11 +461,10 @@ void sampleCopy(Stat4Accum *p, Stat4Sample *pTo, Stat4Sample *pFrom){
|
||||
static void sampleInsert(Stat4Accum *p, Stat4Sample *pNew, int nEqZero){
|
||||
Stat4Sample *pSample;
|
||||
int i;
|
||||
i64 iSeq;
|
||||
int iPos;
|
||||
|
||||
assert( IsStat4 || nEqZero==0 );
|
||||
|
||||
#ifdef SQLITE_ENABLE_STAT4
|
||||
if( pNew->isPSample==0 ){
|
||||
Stat4Sample *pUpgrade = 0;
|
||||
assert( pNew->anEq[pNew->iCol]>0 );
|
||||
@@ -441,8 +478,9 @@ static void sampleInsert(Stat4Accum *p, Stat4Sample *pNew, int nEqZero){
|
||||
Stat4Sample *pOld = &p->a[i];
|
||||
if( pOld->anEq[pNew->iCol]==0 ){
|
||||
if( pOld->isPSample ) return;
|
||||
assert( sampleIsBetter(pNew, pOld) );
|
||||
if( pUpgrade==0 || sampleIsBetter(pOld, pUpgrade) ){
|
||||
assert( pOld->iCol>pNew->iCol );
|
||||
assert( sampleIsBetter(p, pNew, pOld) );
|
||||
if( pUpgrade==0 || sampleIsBetter(p, pOld, pUpgrade) ){
|
||||
pUpgrade = pOld;
|
||||
}
|
||||
}
|
||||
@@ -453,6 +491,7 @@ static void sampleInsert(Stat4Accum *p, Stat4Sample *pNew, int nEqZero){
|
||||
goto find_new_min;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If necessary, remove sample iMin to make room for the new sample. */
|
||||
if( p->nSample>=p->mxSample ){
|
||||
@@ -468,36 +507,30 @@ static void sampleInsert(Stat4Accum *p, Stat4Sample *pNew, int nEqZero){
|
||||
p->nSample = p->mxSample-1;
|
||||
}
|
||||
|
||||
/* Figure out where in the a[] array the new sample should be inserted. */
|
||||
iSeq = pNew->anLt[p->nCol-1];
|
||||
for(iPos=p->nSample; iPos>0; iPos--){
|
||||
if( iSeq>p->a[iPos-1].anLt[p->nCol-1] ) break;
|
||||
}
|
||||
/* The "rows less-than" for the rowid column must be greater than that
|
||||
** for the last sample in the p->a[] array. Otherwise, the samples would
|
||||
** be out of order. */
|
||||
#ifdef SQLITE_ENABLE_STAT4
|
||||
assert( p->nSample==0
|
||||
|| pNew->anLt[p->nCol-1] > p->a[p->nSample-1].anLt[p->nCol-1] );
|
||||
#endif
|
||||
|
||||
/* Insert the new sample */
|
||||
pSample = &p->a[iPos];
|
||||
if( iPos!=p->nSample ){
|
||||
Stat4Sample *pEnd = &p->a[p->nSample];
|
||||
tRowcnt *anEq = pEnd->anEq;
|
||||
tRowcnt *anLt = pEnd->anLt;
|
||||
tRowcnt *anDLt = pEnd->anDLt;
|
||||
memmove(&p->a[iPos], &p->a[iPos+1], (p->nSample-iPos)*sizeof(p->a[0]));
|
||||
pSample->anEq = anEq;
|
||||
pSample->anDLt = anDLt;
|
||||
pSample->anLt = anLt;
|
||||
}
|
||||
p->nSample++;
|
||||
pSample = &p->a[p->nSample];
|
||||
sampleCopy(p, pSample, pNew);
|
||||
p->nSample++;
|
||||
|
||||
/* Zero the first nEqZero entries in the anEq[] array. */
|
||||
memset(pSample->anEq, 0, sizeof(tRowcnt)*nEqZero);
|
||||
|
||||
#ifdef SQLITE_ENABLE_STAT4
|
||||
find_new_min:
|
||||
#endif
|
||||
if( p->nSample>=p->mxSample ){
|
||||
int iMin = -1;
|
||||
for(i=0; i<p->mxSample; i++){
|
||||
if( p->a[i].isPSample ) continue;
|
||||
if( iMin<0 || sampleIsBetter(&p->a[iMin], &p->a[i]) ){
|
||||
if( iMin<0 || sampleIsBetter(p, &p->a[iMin], &p->a[i]) ){
|
||||
iMin = i;
|
||||
}
|
||||
}
|
||||
@@ -521,9 +554,8 @@ static void samplePushPrevious(Stat4Accum *p, int iChng){
|
||||
** into IndexSample.a[] at this point. */
|
||||
for(i=(p->nCol-2); i>=iChng; i--){
|
||||
Stat4Sample *pBest = &p->aBest[i];
|
||||
if( p->nSample<p->mxSample
|
||||
|| sampleIsBetter(pBest, &p->a[p->iMin])
|
||||
){
|
||||
pBest->anEq[i] = p->current.anEq[i];
|
||||
if( p->nSample<p->mxSample || sampleIsBetter(p, pBest, &p->a[p->iMin]) ){
|
||||
sampleInsert(p, pBest, i);
|
||||
}
|
||||
}
|
||||
@@ -550,7 +582,9 @@ static void samplePushPrevious(Stat4Accum *p, int iChng){
|
||||
}else
|
||||
|
||||
/* Or if it is a non-periodic sample. Add it in this case too. */
|
||||
if( p->nSample<p->mxSample || sampleIsBetter(&p->current, &p->a[p->iMin]) ){
|
||||
if( p->nSample<p->mxSample
|
||||
|| sampleIsBetter(p, &p->current, &p->a[p->iMin])
|
||||
){
|
||||
sampleInsert(p, &p->current, 0);
|
||||
}
|
||||
}
|
||||
@@ -584,8 +618,7 @@ static void statPush(
|
||||
assert( iChng<p->nCol );
|
||||
|
||||
if( p->nRow==0 ){
|
||||
/* anEq[0] is only zero for the very first call to this function. Do
|
||||
** appropriate initialization */
|
||||
/* This is the first call to this function. Do initialization. */
|
||||
for(i=0; i<p->nCol; i++) p->current.anEq[i] = 1;
|
||||
}else{
|
||||
/* Second and subsequent calls get processed here */
|
||||
@@ -625,7 +658,7 @@ static void statPush(
|
||||
/* Update the aBest[] array. */
|
||||
for(i=0; i<(p->nCol-1); i++){
|
||||
p->current.iCol = i;
|
||||
if( i>=iChng || sampleIsBetter(&p->current, &p->aBest[i]) ){
|
||||
if( i>=iChng || sampleIsBetterPost(p, &p->current, &p->aBest[i]) ){
|
||||
sampleCopy(p, &p->aBest[i], &p->current);
|
||||
}
|
||||
}
|
||||
@@ -634,8 +667,7 @@ static void statPush(
|
||||
}
|
||||
static const FuncDef statPushFuncdef = {
|
||||
2+IsStat34, /* nArg */
|
||||
SQLITE_UTF8, /* iPrefEnc */
|
||||
0, /* flags */
|
||||
SQLITE_UTF8, /* funcFlags */
|
||||
0, /* pUserData */
|
||||
0, /* pNext */
|
||||
statPush, /* xFunc */
|
||||
@@ -770,8 +802,7 @@ static void statGet(
|
||||
}
|
||||
static const FuncDef statGetFuncdef = {
|
||||
1+IsStat34, /* nArg */
|
||||
SQLITE_UTF8, /* iPrefEnc */
|
||||
0, /* flags */
|
||||
SQLITE_UTF8, /* funcFlags */
|
||||
0, /* pUserData */
|
||||
0, /* pNext */
|
||||
statGet, /* xFunc */
|
||||
@@ -1219,17 +1250,15 @@ struct analysisInfo {
|
||||
** the array aOut[].
|
||||
*/
|
||||
static void decodeIntArray(
|
||||
char *zIntArray,
|
||||
int nOut,
|
||||
tRowcnt *aOut,
|
||||
int *pbUnordered
|
||||
char *zIntArray, /* String containing int array to decode */
|
||||
int nOut, /* Number of slots in aOut[] */
|
||||
LogEst *aOut, /* Convert values to 10*log2() and store here */
|
||||
Index *pIndex /* Handle extra flags for this index, if not NULL */
|
||||
){
|
||||
char *z = zIntArray;
|
||||
int c;
|
||||
int i;
|
||||
tRowcnt v;
|
||||
|
||||
assert( pbUnordered==0 || *pbUnordered==0 );
|
||||
u64 v;
|
||||
|
||||
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
|
||||
if( z==0 ) z = "";
|
||||
@@ -1242,11 +1271,17 @@ static void decodeIntArray(
|
||||
v = v*10 + c - '0';
|
||||
z++;
|
||||
}
|
||||
aOut[i] = v;
|
||||
aOut[i] = sqlite3LogEst(v);
|
||||
if( *z==' ' ) z++;
|
||||
}
|
||||
if( pbUnordered && strcmp(z, "unordered")==0 ){
|
||||
*pbUnordered = 1;
|
||||
if( pIndex ){
|
||||
if( strcmp(z, "unordered")==0 ){
|
||||
pIndex->bUnordered = 1;
|
||||
}else if( sqlite3_strglob("sz=[0-9]*", z)==0 ){
|
||||
int v32 = 0;
|
||||
sqlite3GetInt32(z+3, &v32);
|
||||
pIndex->szIdxRow = sqlite3LogEst(v32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1285,12 +1320,13 @@ static int analysisLoader(void *pData, int argc, char **argv, char **NotUsed){
|
||||
z = argv[2];
|
||||
|
||||
if( pIndex ){
|
||||
int bUnordered = 0;
|
||||
decodeIntArray((char*)z, pIndex->nColumn+1, pIndex->aiRowEst,&bUnordered);
|
||||
decodeIntArray((char*)z, pIndex->nColumn+1, pIndex->aiRowEst, pIndex);
|
||||
if( pIndex->pPartIdxWhere==0 ) pTable->nRowEst = pIndex->aiRowEst[0];
|
||||
pIndex->bUnordered = bUnordered;
|
||||
}else{
|
||||
decodeIntArray((char*)z, 1, &pTable->nRowEst, 0);
|
||||
Index fakeIdx;
|
||||
fakeIdx.szIdxRow = pTable->szTabRow;
|
||||
decodeIntArray((char*)z, 1, &pTable->nRowEst, &fakeIdx);
|
||||
pTable->szTabRow = fakeIdx.szIdxRow;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -1332,10 +1368,10 @@ static void initAvgEq(Index *pIdx){
|
||||
int iCol;
|
||||
for(iCol=0; iCol<pIdx->nColumn; iCol++){
|
||||
int i; /* Used to iterate through samples */
|
||||
tRowcnt sumEq = 0; /* Sum of the nEq values */
|
||||
tRowcnt nSum = 0; /* Number of terms contributing to sumEq */
|
||||
tRowcnt avgEq = 0;
|
||||
tRowcnt nDLt = pFinal->anDLt[iCol];
|
||||
u64 sumEq = 0; /* Sum of the nEq values */
|
||||
u64 nSum = 0; /* Number of terms contributing to sumEq */
|
||||
u64 avgEq = 0;
|
||||
u64 nDLt = sqlite3LogEstToInt(pFinal->anDLt[iCol]);
|
||||
|
||||
/* Set nSum to the number of distinct (iCol+1) field prefixes that
|
||||
** occur in the stat4 table for this index before pFinal. Set
|
||||
@@ -1344,15 +1380,15 @@ static void initAvgEq(Index *pIdx){
|
||||
** prefixes). */
|
||||
for(i=0; i<(pIdx->nSample-1); i++){
|
||||
if( aSample[i].anDLt[iCol]!=aSample[i+1].anDLt[iCol] ){
|
||||
sumEq += aSample[i].anEq[iCol];
|
||||
sumEq += sqlite3LogEstToInt(aSample[i].anEq[iCol]);
|
||||
nSum++;
|
||||
}
|
||||
}
|
||||
if( nDLt>nSum ){
|
||||
avgEq = (pFinal->anLt[iCol] - sumEq)/(nDLt - nSum);
|
||||
avgEq = (sqlite3LogEstToInt(pFinal->anLt[iCol]) - sumEq)/(nDLt - nSum);
|
||||
}
|
||||
if( avgEq==0 ) avgEq = 1;
|
||||
pIdx->aAvgEq[iCol] = avgEq;
|
||||
if( avgEq<=0 ) avgEq = 1;
|
||||
pIdx->aAvgEq[iCol] = sqlite3LogEst(avgEq);
|
||||
if( pIdx->nSampleCol==1 ) break;
|
||||
}
|
||||
}
|
||||
@@ -1402,7 +1438,7 @@ static int loadStatTbl(
|
||||
int nSample; /* Number of samples */
|
||||
int nByte; /* Bytes of space required */
|
||||
int i; /* Bytes of space required */
|
||||
tRowcnt *pSpace;
|
||||
LogEst *pSpace;
|
||||
|
||||
zIndex = (char *)sqlite3_column_text(pStmt, 0);
|
||||
if( zIndex==0 ) continue;
|
||||
@@ -1418,15 +1454,15 @@ static int loadStatTbl(
|
||||
}
|
||||
pIdx->nSampleCol = nIdxCol;
|
||||
nByte = sizeof(IndexSample) * nSample;
|
||||
nByte += sizeof(tRowcnt) * nIdxCol * 3 * nSample;
|
||||
nByte += nAvgCol * sizeof(tRowcnt); /* Space for Index.aAvgEq[] */
|
||||
nByte += sizeof(LogEst) * nIdxCol * 3 * nSample;
|
||||
nByte += nAvgCol * sizeof(LogEst); /* Space for Index.aAvgEq[] */
|
||||
|
||||
pIdx->aSample = sqlite3DbMallocZero(db, nByte);
|
||||
if( pIdx->aSample==0 ){
|
||||
sqlite3_finalize(pStmt);
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
pSpace = (tRowcnt*)&pIdx->aSample[nSample];
|
||||
pSpace = (LogEst*)&pIdx->aSample[nSample];
|
||||
pIdx->aAvgEq = pSpace; pSpace += nAvgCol;
|
||||
for(i=0; i<nSample; i++){
|
||||
pIdx->aSample[i].anEq = pSpace; pSpace += nIdxCol;
|
||||
|
||||
+35
-19
@@ -379,8 +379,7 @@ attach_end:
|
||||
void sqlite3Detach(Parse *pParse, Expr *pDbname){
|
||||
static const FuncDef detach_func = {
|
||||
1, /* nArg */
|
||||
SQLITE_UTF8, /* iPrefEnc */
|
||||
0, /* flags */
|
||||
SQLITE_UTF8, /* funcFlags */
|
||||
0, /* pUserData */
|
||||
0, /* pNext */
|
||||
detachFunc, /* xFunc */
|
||||
@@ -401,8 +400,7 @@ void sqlite3Detach(Parse *pParse, Expr *pDbname){
|
||||
void sqlite3Attach(Parse *pParse, Expr *p, Expr *pDbname, Expr *pKey){
|
||||
static const FuncDef attach_func = {
|
||||
3, /* nArg */
|
||||
SQLITE_UTF8, /* iPrefEnc */
|
||||
0, /* flags */
|
||||
SQLITE_UTF8, /* funcFlags */
|
||||
0, /* pUserData */
|
||||
0, /* pNext */
|
||||
attachFunc, /* xFunc */
|
||||
@@ -419,11 +417,8 @@ void sqlite3Attach(Parse *pParse, Expr *p, Expr *pDbname, Expr *pKey){
|
||||
/*
|
||||
** Initialize a DbFixer structure. This routine must be called prior
|
||||
** to passing the structure to one of the sqliteFixAAAA() routines below.
|
||||
**
|
||||
** The return value indicates whether or not fixation is required. TRUE
|
||||
** means we do need to fix the database references, FALSE means we do not.
|
||||
*/
|
||||
int sqlite3FixInit(
|
||||
void sqlite3FixInit(
|
||||
DbFixer *pFix, /* The fixer to be initialized */
|
||||
Parse *pParse, /* Error messages will be written here */
|
||||
int iDb, /* This is the database that must be used */
|
||||
@@ -432,7 +427,6 @@ int sqlite3FixInit(
|
||||
){
|
||||
sqlite3 *db;
|
||||
|
||||
if( NEVER(iDb<0) || iDb==1 ) return 0;
|
||||
db = pParse->db;
|
||||
assert( db->nDb>iDb );
|
||||
pFix->pParse = pParse;
|
||||
@@ -440,7 +434,7 @@ int sqlite3FixInit(
|
||||
pFix->pSchema = db->aDb[iDb].pSchema;
|
||||
pFix->zType = zType;
|
||||
pFix->pName = pName;
|
||||
return 1;
|
||||
pFix->bVarOnly = (iDb==1);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -468,15 +462,17 @@ int sqlite3FixSrcList(
|
||||
if( NEVER(pList==0) ) return 0;
|
||||
zDb = pFix->zDb;
|
||||
for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
|
||||
if( pItem->zDatabase && sqlite3StrICmp(pItem->zDatabase, zDb) ){
|
||||
sqlite3ErrorMsg(pFix->pParse,
|
||||
"%s %T cannot reference objects in database %s",
|
||||
pFix->zType, pFix->pName, pItem->zDatabase);
|
||||
return 1;
|
||||
if( pFix->bVarOnly==0 ){
|
||||
if( pItem->zDatabase && sqlite3StrICmp(pItem->zDatabase, zDb) ){
|
||||
sqlite3ErrorMsg(pFix->pParse,
|
||||
"%s %T cannot reference objects in database %s",
|
||||
pFix->zType, pFix->pName, pItem->zDatabase);
|
||||
return 1;
|
||||
}
|
||||
sqlite3DbFree(pFix->pParse->db, pItem->zDatabase);
|
||||
pItem->zDatabase = 0;
|
||||
pItem->pSchema = pFix->pSchema;
|
||||
}
|
||||
sqlite3DbFree(pFix->pParse->db, pItem->zDatabase);
|
||||
pItem->zDatabase = 0;
|
||||
pItem->pSchema = pFix->pSchema;
|
||||
#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER)
|
||||
if( sqlite3FixSelect(pFix, pItem->pSelect) ) return 1;
|
||||
if( sqlite3FixExpr(pFix, pItem->pOn) ) return 1;
|
||||
@@ -499,9 +495,21 @@ int sqlite3FixSelect(
|
||||
if( sqlite3FixExpr(pFix, pSelect->pWhere) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqlite3FixExprList(pFix, pSelect->pGroupBy) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqlite3FixExpr(pFix, pSelect->pHaving) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqlite3FixExprList(pFix, pSelect->pOrderBy) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqlite3FixExpr(pFix, pSelect->pLimit) ){
|
||||
return 1;
|
||||
}
|
||||
if( sqlite3FixExpr(pFix, pSelect->pOffset) ){
|
||||
return 1;
|
||||
}
|
||||
pSelect = pSelect->pPrior;
|
||||
}
|
||||
return 0;
|
||||
@@ -511,7 +519,15 @@ int sqlite3FixExpr(
|
||||
Expr *pExpr /* The expression to be fixed to one database */
|
||||
){
|
||||
while( pExpr ){
|
||||
if( ExprHasAnyProperty(pExpr, EP_TokenOnly) ) break;
|
||||
if( pExpr->op==TK_VARIABLE ){
|
||||
if( pFix->pParse->db->init.busy ){
|
||||
pExpr->op = TK_NULL;
|
||||
}else{
|
||||
sqlite3ErrorMsg(pFix->pParse, "%s cannot use variables", pFix->zType);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if( ExprHasProperty(pExpr, EP_TokenOnly) ) break;
|
||||
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
|
||||
if( sqlite3FixSelect(pFix, pExpr->x.pSelect) ) return 1;
|
||||
}else{
|
||||
|
||||
+1
-2
@@ -2508,7 +2508,6 @@ static int lockBtree(BtShared *pBt){
|
||||
assert( pBt->maxLeaf + 23 <= MX_CELL_SIZE(pBt) );
|
||||
pBt->pPage1 = pPage1;
|
||||
pBt->nPage = nPage;
|
||||
assert( pPage1->leaf==0 || pPage1->leaf==1 );
|
||||
return SQLITE_OK;
|
||||
|
||||
page1_init_failed:
|
||||
@@ -2668,7 +2667,7 @@ int sqlite3BtreeBeginTrans(Btree *p, int wrflag){
|
||||
if( p->inTrans==TRANS_WRITE || (p->inTrans==TRANS_READ && !wrflag) ){
|
||||
goto trans_begun;
|
||||
}
|
||||
assert( IfNotOmitAV(pBt->bDoTruncate)==0 );
|
||||
assert( pBt->inTransaction==TRANS_WRITE || IfNotOmitAV(pBt->bDoTruncate)==0 );
|
||||
|
||||
/* Write transactions are not possible on a read-only database */
|
||||
if( (pBt->btsFlags & BTS_READ_ONLY)!=0 && wrflag ){
|
||||
|
||||
+8
-7
@@ -56,13 +56,13 @@
|
||||
**
|
||||
** OFFSET SIZE DESCRIPTION
|
||||
** 0 16 Header string: "SQLite format 3\000"
|
||||
** 16 2 Page size in bytes.
|
||||
** 16 2 Page size in bytes. (1 means 65536)
|
||||
** 18 1 File format write version
|
||||
** 19 1 File format read version
|
||||
** 20 1 Bytes of unused space at the end of each page
|
||||
** 21 1 Max embedded payload fraction
|
||||
** 22 1 Min embedded payload fraction
|
||||
** 23 1 Min leaf payload fraction
|
||||
** 21 1 Max embedded payload fraction (must be 64)
|
||||
** 22 1 Min embedded payload fraction (must be 32)
|
||||
** 23 1 Min leaf payload fraction (must be 32)
|
||||
** 24 4 File change counter
|
||||
** 28 4 Reserved for future use
|
||||
** 32 4 First freelist page
|
||||
@@ -76,9 +76,10 @@
|
||||
** 56 4 1=UTF-8 2=UTF16le 3=UTF16be
|
||||
** 60 4 User version
|
||||
** 64 4 Incremental vacuum mode
|
||||
** 68 4 unused
|
||||
** 72 4 unused
|
||||
** 76 4 unused
|
||||
** 68 4 Application-ID
|
||||
** 72 20 unused
|
||||
** 92 4 The version-valid-for number
|
||||
** 96 4 SQLITE_VERSION_NUMBER
|
||||
**
|
||||
** All of the integer values are big-endian (most significant byte first).
|
||||
**
|
||||
|
||||
+90
-28
@@ -879,7 +879,7 @@ void sqlite3StartTable(
|
||||
pTable->iPKey = -1;
|
||||
pTable->pSchema = db->aDb[iDb].pSchema;
|
||||
pTable->nRef = 1;
|
||||
pTable->nRowEst = 1000000;
|
||||
pTable->nRowEst = 200;
|
||||
assert( pParse->pNewTable==0 );
|
||||
pParse->pNewTable = pTable;
|
||||
|
||||
@@ -1026,6 +1026,7 @@ void sqlite3AddColumn(Parse *pParse, Token *pName){
|
||||
** be called next to set pCol->affinity correctly.
|
||||
*/
|
||||
pCol->affinity = SQLITE_AFF_NONE;
|
||||
pCol->szEst = 1;
|
||||
p->nCol++;
|
||||
}
|
||||
|
||||
@@ -1067,15 +1068,18 @@ void sqlite3AddNotNull(Parse *pParse, int onError){
|
||||
** If none of the substrings in the above table are found,
|
||||
** SQLITE_AFF_NUMERIC is returned.
|
||||
*/
|
||||
char sqlite3AffinityType(const char *zIn){
|
||||
char sqlite3AffinityType(const char *zIn, u8 *pszEst){
|
||||
u32 h = 0;
|
||||
char aff = SQLITE_AFF_NUMERIC;
|
||||
const char *zChar = 0;
|
||||
|
||||
if( zIn ) while( zIn[0] ){
|
||||
if( zIn==0 ) return aff;
|
||||
while( zIn[0] ){
|
||||
h = (h<<8) + sqlite3UpperToLower[(*zIn)&0xff];
|
||||
zIn++;
|
||||
if( h==(('c'<<24)+('h'<<16)+('a'<<8)+'r') ){ /* CHAR */
|
||||
aff = SQLITE_AFF_TEXT;
|
||||
aff = SQLITE_AFF_TEXT;
|
||||
zChar = zIn;
|
||||
}else if( h==(('c'<<24)+('l'<<16)+('o'<<8)+'b') ){ /* CLOB */
|
||||
aff = SQLITE_AFF_TEXT;
|
||||
}else if( h==(('t'<<24)+('e'<<16)+('x'<<8)+'t') ){ /* TEXT */
|
||||
@@ -1083,6 +1087,7 @@ char sqlite3AffinityType(const char *zIn){
|
||||
}else if( h==(('b'<<24)+('l'<<16)+('o'<<8)+'b') /* BLOB */
|
||||
&& (aff==SQLITE_AFF_NUMERIC || aff==SQLITE_AFF_REAL) ){
|
||||
aff = SQLITE_AFF_NONE;
|
||||
if( zIn[0]=='(' ) zChar = zIn;
|
||||
#ifndef SQLITE_OMIT_FLOATING_POINT
|
||||
}else if( h==(('r'<<24)+('e'<<16)+('a'<<8)+'l') /* REAL */
|
||||
&& aff==SQLITE_AFF_NUMERIC ){
|
||||
@@ -1100,6 +1105,28 @@ char sqlite3AffinityType(const char *zIn){
|
||||
}
|
||||
}
|
||||
|
||||
/* If pszEst is not NULL, store an estimate of the field size. The
|
||||
** estimate is scaled so that the size of an integer is 1. */
|
||||
if( pszEst ){
|
||||
*pszEst = 1; /* default size is approx 4 bytes */
|
||||
if( aff<=SQLITE_AFF_NONE ){
|
||||
if( zChar ){
|
||||
while( zChar[0] ){
|
||||
if( sqlite3Isdigit(zChar[0]) ){
|
||||
int v;
|
||||
sqlite3GetInt32(zChar, &v);
|
||||
v = v/4 + 1;
|
||||
if( v>255 ) v = 255;
|
||||
*pszEst = v; /* BLOB(k), VARCHAR(k), CHAR(k) -> r=(k/4+1) */
|
||||
break;
|
||||
}
|
||||
zChar++;
|
||||
}
|
||||
}else{
|
||||
*pszEst = 5; /* BLOB, TEXT, CLOB -> r=5 (approx 20 bytes)*/
|
||||
}
|
||||
}
|
||||
}
|
||||
return aff;
|
||||
}
|
||||
|
||||
@@ -1121,7 +1148,7 @@ void sqlite3AddColumnType(Parse *pParse, Token *pType){
|
||||
pCol = &p->aCol[p->nCol-1];
|
||||
assert( pCol->zType==0 );
|
||||
pCol->zType = sqlite3NameFromToken(pParse->db, pType);
|
||||
pCol->affinity = sqlite3AffinityType(pCol->zType);
|
||||
pCol->affinity = sqlite3AffinityType(pCol->zType, &pCol->szEst);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1469,7 +1496,7 @@ static char *createTableStmt(sqlite3 *db, Table *p){
|
||||
zType = azType[pCol->affinity - SQLITE_AFF_TEXT];
|
||||
len = sqlite3Strlen30(zType);
|
||||
assert( pCol->affinity==SQLITE_AFF_NONE
|
||||
|| pCol->affinity==sqlite3AffinityType(zType) );
|
||||
|| pCol->affinity==sqlite3AffinityType(zType, 0) );
|
||||
memcpy(&zStmt[k], zType, len);
|
||||
k += len;
|
||||
assert( k<=n );
|
||||
@@ -1478,6 +1505,34 @@ static char *createTableStmt(sqlite3 *db, Table *p){
|
||||
return zStmt;
|
||||
}
|
||||
|
||||
/*
|
||||
** Estimate the total row width for a table.
|
||||
*/
|
||||
static void estimateTableWidth(Table *pTab){
|
||||
unsigned wTable = 0;
|
||||
const Column *pTabCol;
|
||||
int i;
|
||||
for(i=pTab->nCol, pTabCol=pTab->aCol; i>0; i--, pTabCol++){
|
||||
wTable += pTabCol->szEst;
|
||||
}
|
||||
if( pTab->iPKey<0 ) wTable++;
|
||||
pTab->szTabRow = sqlite3LogEst(wTable*4);
|
||||
}
|
||||
|
||||
/*
|
||||
** Estimate the average size of a row for an index.
|
||||
*/
|
||||
static void estimateIndexWidth(Index *pIdx){
|
||||
unsigned wIndex = 1;
|
||||
int i;
|
||||
const Column *aCol = pIdx->pTable->aCol;
|
||||
for(i=0; i<pIdx->nColumn; i++){
|
||||
assert( pIdx->aiColumn[i]>=0 && pIdx->aiColumn[i]<pIdx->pTable->nCol );
|
||||
wIndex += aCol[pIdx->aiColumn[i]].szEst;
|
||||
}
|
||||
pIdx->szIdxRow = sqlite3LogEst(wIndex*4);
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is called to report the final ")" that terminates
|
||||
** a CREATE TABLE statement.
|
||||
@@ -1504,9 +1559,10 @@ void sqlite3EndTable(
|
||||
Token *pEnd, /* The final ')' token in the CREATE TABLE */
|
||||
Select *pSelect /* Select from a "CREATE ... AS SELECT" */
|
||||
){
|
||||
Table *p;
|
||||
sqlite3 *db = pParse->db;
|
||||
int iDb;
|
||||
Table *p; /* The new table */
|
||||
sqlite3 *db = pParse->db; /* The database connection */
|
||||
int iDb; /* Database in which the table lives */
|
||||
Index *pIdx; /* An implied index of the table */
|
||||
|
||||
if( (pEnd==0 && pSelect==0) || db->mallocFailed ){
|
||||
return;
|
||||
@@ -1526,6 +1582,12 @@ void sqlite3EndTable(
|
||||
}
|
||||
#endif /* !defined(SQLITE_OMIT_CHECK) */
|
||||
|
||||
/* Estimate the average row size for the table and for all implied indices */
|
||||
estimateTableWidth(p);
|
||||
for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
estimateIndexWidth(pIdx);
|
||||
}
|
||||
|
||||
/* If the db->init.busy is 1 it means we are reading the SQL off the
|
||||
** "sqlite_master" or "sqlite_temp_master" table on the disk.
|
||||
** So do not write to the disk again. Extract the root page number
|
||||
@@ -1722,9 +1784,8 @@ void sqlite3CreateView(
|
||||
}
|
||||
sqlite3TwoPartName(pParse, pName1, pName2, &pName);
|
||||
iDb = sqlite3SchemaToIndex(db, p->pSchema);
|
||||
if( sqlite3FixInit(&sFix, pParse, iDb, "view", pName)
|
||||
&& sqlite3FixSelect(&sFix, pSelect)
|
||||
){
|
||||
sqlite3FixInit(&sFix, pParse, iDb, "view", pName);
|
||||
if( sqlite3FixSelect(&sFix, pSelect) ){
|
||||
sqlite3SelectDelete(db, pSelect);
|
||||
return;
|
||||
}
|
||||
@@ -2485,9 +2546,10 @@ Index *sqlite3CreateIndex(
|
||||
int iDb; /* Index of the database that is being written */
|
||||
Token *pName = 0; /* Unqualified name of the index to create */
|
||||
struct ExprList_item *pListItem; /* For looping over pList */
|
||||
int nCol;
|
||||
int nExtra = 0;
|
||||
char *zExtra;
|
||||
const Column *pTabCol; /* A column in the table */
|
||||
int nCol; /* Number of columns */
|
||||
int nExtra = 0; /* Space allocated for zExtra[] */
|
||||
char *zExtra; /* Extra space after the Index object */
|
||||
|
||||
assert( pParse->nErr==0 ); /* Never called with prior errors */
|
||||
if( db->mallocFailed || IN_DECLARE_VTAB ){
|
||||
@@ -2524,9 +2586,8 @@ Index *sqlite3CreateIndex(
|
||||
}
|
||||
#endif
|
||||
|
||||
if( sqlite3FixInit(&sFix, pParse, iDb, "index", pName) &&
|
||||
sqlite3FixSrcList(&sFix, pTblName)
|
||||
){
|
||||
sqlite3FixInit(&sFix, pParse, iDb, "index", pName);
|
||||
if( sqlite3FixSrcList(&sFix, pTblName) ){
|
||||
/* Because the parser constructs pTblName from a single identifier,
|
||||
** sqlite3FixSrcList can never fail. */
|
||||
assert(0);
|
||||
@@ -2661,7 +2722,7 @@ Index *sqlite3CreateIndex(
|
||||
nCol = pList->nExpr;
|
||||
pIndex = sqlite3DbMallocZero(db,
|
||||
ROUND8(sizeof(Index)) + /* Index structure */
|
||||
ROUND8(sizeof(tRowcnt)*(nCol+1)) + /* Index.aiRowEst */
|
||||
ROUND8(sizeof(LogEst)*(nCol+1)) + /* Index.aiRowEst */
|
||||
sizeof(char *)*nCol + /* Index.azColl */
|
||||
sizeof(int)*nCol + /* Index.aiColumn */
|
||||
sizeof(u8)*nCol + /* Index.aSortOrder */
|
||||
@@ -2672,9 +2733,9 @@ Index *sqlite3CreateIndex(
|
||||
goto exit_create_index;
|
||||
}
|
||||
zExtra = (char*)pIndex;
|
||||
pIndex->aiRowEst = (tRowcnt*)&zExtra[ROUND8(sizeof(Index))];
|
||||
pIndex->aiRowEst = (LogEst*)&zExtra[ROUND8(sizeof(Index))];
|
||||
pIndex->azColl = (char**)
|
||||
((char*)pIndex->aiRowEst + ROUND8(sizeof(tRowcnt)*nCol+1));
|
||||
((char*)pIndex->aiRowEst + ROUND8(sizeof(LogEst)*nCol+1));
|
||||
assert( EIGHT_BYTE_ALIGNMENT(pIndex->aiRowEst) );
|
||||
assert( EIGHT_BYTE_ALIGNMENT(pIndex->azColl) );
|
||||
pIndex->aiColumn = (int *)(&pIndex->azColl[nCol]);
|
||||
@@ -2715,7 +2776,6 @@ Index *sqlite3CreateIndex(
|
||||
*/
|
||||
for(i=0, pListItem=pList->a; i<pList->nExpr; i++, pListItem++){
|
||||
const char *zColName = pListItem->zName;
|
||||
Column *pTabCol;
|
||||
int requestedSortOrder;
|
||||
char *zColl; /* Collation sequence name */
|
||||
|
||||
@@ -2752,6 +2812,7 @@ Index *sqlite3CreateIndex(
|
||||
if( pTab->aCol[j].notNull==0 ) pIndex->uniqNotNull = 0;
|
||||
}
|
||||
sqlite3DefaultRowEst(pIndex);
|
||||
if( pParse->pNewTable==0 ) estimateIndexWidth(pIndex);
|
||||
|
||||
if( pTab==pParse->pNewTable ){
|
||||
/* This routine has been called to create an automatic index as a
|
||||
@@ -2953,19 +3014,20 @@ exit_create_index:
|
||||
** are based on typical values found in actual indices.
|
||||
*/
|
||||
void sqlite3DefaultRowEst(Index *pIdx){
|
||||
tRowcnt *a = pIdx->aiRowEst;
|
||||
LogEst *a = pIdx->aiRowEst;
|
||||
int i;
|
||||
tRowcnt n;
|
||||
LogEst n;
|
||||
assert( a!=0 );
|
||||
a[0] = pIdx->pTable->nRowEst;
|
||||
if( a[0]<10 ) a[0] = 10;
|
||||
n = 10;
|
||||
assert( 33==sqlite3LogEst(10) );
|
||||
if( a[0]<34 ){ a[0] = 34; }
|
||||
n = 34;
|
||||
for(i=1; i<=pIdx->nColumn; i++){
|
||||
a[i] = n;
|
||||
if( n>5 ) n--;
|
||||
if( n>24 ) n -= 2;
|
||||
}
|
||||
if( pIdx->onError!=OE_None ){
|
||||
a[pIdx->nColumn] = 1;
|
||||
a[pIdx->nColumn] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -270,9 +270,9 @@ static int matchQuality(
|
||||
}
|
||||
|
||||
/* Bonus points if the text encoding matches */
|
||||
if( enc==p->iPrefEnc ){
|
||||
if( enc==(p->funcFlags & SQLITE_FUNC_ENCMASK) ){
|
||||
match += 2; /* Exact encoding match */
|
||||
}else if( (enc & p->iPrefEnc & 2)!=0 ){
|
||||
}else if( (enc & p->funcFlags & 2)!=0 ){
|
||||
match += 1; /* Both are UTF16, but with different byte orders */
|
||||
}
|
||||
|
||||
@@ -406,7 +406,7 @@ FuncDef *sqlite3FindFunction(
|
||||
(pBest = sqlite3DbMallocZero(db, sizeof(*pBest)+nName+1))!=0 ){
|
||||
pBest->zName = (char *)&pBest[1];
|
||||
pBest->nArg = (u16)nArg;
|
||||
pBest->iPrefEnc = enc;
|
||||
pBest->funcFlags = enc;
|
||||
memcpy(pBest->zName, zName, nName);
|
||||
pBest->zName[nName] = 0;
|
||||
sqlite3FuncDefInsert(&db->aFunc, pBest);
|
||||
|
||||
+4
-4
@@ -294,8 +294,8 @@ static int parseYyyyMmDd(const char *zDate, DateTime *p){
|
||||
** Return the number of errors.
|
||||
*/
|
||||
static int setDateTimeToCurrent(sqlite3_context *context, DateTime *p){
|
||||
sqlite3 *db = sqlite3_context_db_handle(context);
|
||||
if( sqlite3OsCurrentTimeInt64(db->pVfs, &p->iJD)==SQLITE_OK ){
|
||||
p->iJD = sqlite3StmtCurrentTime(context);
|
||||
if( p->iJD>0 ){
|
||||
p->validJD = 1;
|
||||
return 0;
|
||||
}else{
|
||||
@@ -1078,8 +1078,8 @@ static void currentTimeFunc(
|
||||
UNUSED_PARAMETER(argc);
|
||||
UNUSED_PARAMETER(argv);
|
||||
|
||||
db = sqlite3_context_db_handle(context);
|
||||
if( sqlite3OsCurrentTimeInt64(db->pVfs, &iT) ) return;
|
||||
iT = sqlite3StmtCurrentTime(context);
|
||||
if( iT<=0 ) return;
|
||||
t = iT/1000 - 10000*(sqlite3_int64)21086676;
|
||||
#ifdef HAVE_GMTIME_R
|
||||
pTm = gmtime_r(&t, &sNow);
|
||||
|
||||
+3
-2
@@ -350,6 +350,7 @@ void sqlite3DeleteFrom(
|
||||
&& 0==sqlite3FkRequired(pParse, pTab, 0, 0)
|
||||
){
|
||||
assert( !isView );
|
||||
sqlite3TableLock(pParse, iDb, pTab->tnum, 1, pTab->zName);
|
||||
sqlite3VdbeAddOp4(v, OP_Clear, pTab->tnum, iDb, memCnt,
|
||||
pTab->zName, P4_STATIC);
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
@@ -536,7 +537,7 @@ void sqlite3GenerateRowDelete(
|
||||
/* Do FK processing. This call checks that any FK constraints that
|
||||
** refer to this table (i.e. constraints attached to other tables)
|
||||
** are not violated by deleting this row. */
|
||||
sqlite3FkCheck(pParse, pTab, iOld, 0);
|
||||
sqlite3FkCheck(pParse, pTab, iOld, 0, 0, 0);
|
||||
}
|
||||
|
||||
/* Delete the index and table entries. Skip this step if pTab is really
|
||||
@@ -553,7 +554,7 @@ void sqlite3GenerateRowDelete(
|
||||
/* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to
|
||||
** handle rows (possibly in other tables) that refer via a foreign key
|
||||
** to the row just deleted. */
|
||||
sqlite3FkActions(pParse, pTab, 0, iOld);
|
||||
sqlite3FkActions(pParse, pTab, 0, iOld, 0, 0);
|
||||
|
||||
/* Invoke AFTER DELETE trigger programs. */
|
||||
sqlite3CodeRowTrigger(pParse, pTrigger,
|
||||
|
||||
+79
-58
@@ -41,7 +41,7 @@ char sqlite3ExprAffinity(Expr *pExpr){
|
||||
#ifndef SQLITE_OMIT_CAST
|
||||
if( op==TK_CAST ){
|
||||
assert( !ExprHasProperty(pExpr, EP_IntValue) );
|
||||
return sqlite3AffinityType(pExpr->u.zToken);
|
||||
return sqlite3AffinityType(pExpr->u.zToken, 0);
|
||||
}
|
||||
#endif
|
||||
if( (op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_REGISTER)
|
||||
@@ -70,7 +70,7 @@ Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr *pExpr, Token *pCollName){
|
||||
Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, 1);
|
||||
if( pNew ){
|
||||
pNew->pLeft = pExpr;
|
||||
pNew->flags |= EP_Collate;
|
||||
pNew->flags |= EP_Collate|EP_Skip;
|
||||
pExpr = pNew;
|
||||
}
|
||||
}
|
||||
@@ -85,13 +85,21 @@ Expr *sqlite3ExprAddCollateString(Parse *pParse, Expr *pExpr, const char *zC){
|
||||
}
|
||||
|
||||
/*
|
||||
** Skip over any TK_COLLATE and/or TK_AS operators at the root of
|
||||
** an expression.
|
||||
** Skip over any TK_COLLATE or TK_AS operators and any unlikely()
|
||||
** or likelihood() function at the root of an expression.
|
||||
*/
|
||||
Expr *sqlite3ExprSkipCollate(Expr *pExpr){
|
||||
while( pExpr && (pExpr->op==TK_COLLATE || pExpr->op==TK_AS) ){
|
||||
pExpr = pExpr->pLeft;
|
||||
}
|
||||
while( pExpr && ExprHasProperty(pExpr, EP_Skip) ){
|
||||
if( ExprHasProperty(pExpr, EP_Unlikely) ){
|
||||
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
|
||||
assert( pExpr->x.pList->nExpr>0 );
|
||||
assert( pExpr->op==TK_FUNCTION );
|
||||
pExpr = pExpr->x.pList->a[0].pExpr;
|
||||
}else{
|
||||
assert( pExpr->op==TK_COLLATE || pExpr->op==TK_AS );
|
||||
pExpr = pExpr->pLeft;
|
||||
}
|
||||
}
|
||||
return pExpr;
|
||||
}
|
||||
|
||||
@@ -596,7 +604,7 @@ void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){
|
||||
const char *z;
|
||||
|
||||
if( pExpr==0 ) return;
|
||||
assert( !ExprHasAnyProperty(pExpr, EP_IntValue|EP_Reduced|EP_TokenOnly) );
|
||||
assert( !ExprHasProperty(pExpr, EP_IntValue|EP_Reduced|EP_TokenOnly) );
|
||||
z = pExpr->u.zToken;
|
||||
assert( z!=0 );
|
||||
assert( z[0]!=0 );
|
||||
@@ -666,12 +674,12 @@ void sqlite3ExprDelete(sqlite3 *db, Expr *p){
|
||||
if( p==0 ) return;
|
||||
/* Sanity check: Assert that the IntValue is non-negative if it exists */
|
||||
assert( !ExprHasProperty(p, EP_IntValue) || p->u.iValue>=0 );
|
||||
if( !ExprHasAnyProperty(p, EP_TokenOnly) ){
|
||||
if( !ExprHasProperty(p, EP_TokenOnly) ){
|
||||
/* The Expr.x union is never used at the same time as Expr.pRight */
|
||||
assert( p->x.pList==0 || p->pRight==0 );
|
||||
sqlite3ExprDelete(db, p->pLeft);
|
||||
sqlite3ExprDelete(db, p->pRight);
|
||||
if( !ExprHasProperty(p, EP_Reduced) && (p->flags2 & EP2_MallocedToken)!=0 ){
|
||||
sqlite3DbFree(db, p->u.zToken);
|
||||
}
|
||||
if( ExprHasProperty(p, EP_MemToken) ) sqlite3DbFree(db, p->u.zToken);
|
||||
if( ExprHasProperty(p, EP_xIsSelect) ){
|
||||
sqlite3SelectDelete(db, p->x.pSelect);
|
||||
}else{
|
||||
@@ -731,16 +739,19 @@ static int exprStructSize(Expr *p){
|
||||
static int dupedExprStructSize(Expr *p, int flags){
|
||||
int nSize;
|
||||
assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */
|
||||
assert( EXPR_FULLSIZE<=0xfff );
|
||||
assert( (0xfff & (EP_Reduced|EP_TokenOnly))==0 );
|
||||
if( 0==(flags&EXPRDUP_REDUCE) ){
|
||||
nSize = EXPR_FULLSIZE;
|
||||
}else{
|
||||
assert( !ExprHasAnyProperty(p, EP_TokenOnly|EP_Reduced) );
|
||||
assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
|
||||
assert( !ExprHasProperty(p, EP_FromJoin) );
|
||||
assert( (p->flags2 & EP2_MallocedToken)==0 );
|
||||
assert( (p->flags2 & EP2_Irreducible)==0 );
|
||||
if( p->pLeft || p->pRight || p->x.pList ){
|
||||
assert( !ExprHasProperty(p, EP_MemToken) );
|
||||
assert( !ExprHasProperty(p, EP_NoReduce) );
|
||||
if( p->pLeft || p->x.pList ){
|
||||
nSize = EXPR_REDUCEDSIZE | EP_Reduced;
|
||||
}else{
|
||||
assert( p->pRight==0 );
|
||||
nSize = EXPR_TOKENONLYSIZE | EP_TokenOnly;
|
||||
}
|
||||
}
|
||||
@@ -834,7 +845,7 @@ static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){
|
||||
}
|
||||
|
||||
/* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */
|
||||
pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static);
|
||||
pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static|EP_MemToken);
|
||||
pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly);
|
||||
pNew->flags |= staticFlag;
|
||||
|
||||
@@ -854,7 +865,7 @@ static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){
|
||||
}
|
||||
|
||||
/* Fill in pNew->pLeft and pNew->pRight. */
|
||||
if( ExprHasAnyProperty(pNew, EP_Reduced|EP_TokenOnly) ){
|
||||
if( ExprHasProperty(pNew, EP_Reduced|EP_TokenOnly) ){
|
||||
zAlloc += dupedExprNodeSize(p, flags);
|
||||
if( ExprHasProperty(pNew, EP_Reduced) ){
|
||||
pNew->pLeft = exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc);
|
||||
@@ -864,8 +875,7 @@ static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){
|
||||
*pzBuffer = zAlloc;
|
||||
}
|
||||
}else{
|
||||
pNew->flags2 = 0;
|
||||
if( !ExprHasAnyProperty(p, EP_TokenOnly) ){
|
||||
if( !ExprHasProperty(p, EP_TokenOnly) ){
|
||||
pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
|
||||
pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
|
||||
}
|
||||
@@ -1175,7 +1185,7 @@ static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
|
||||
/* If pWalker->u.i is 3 then any term of the expression that comes from
|
||||
** the ON or USING clauses of a join disqualifies the expression
|
||||
** from being considered constant. */
|
||||
if( pWalker->u.i==3 && ExprHasAnyProperty(pExpr, EP_FromJoin) ){
|
||||
if( pWalker->u.i==3 && ExprHasProperty(pExpr, EP_FromJoin) ){
|
||||
pWalker->u.i = 0;
|
||||
return WRC_Abort;
|
||||
}
|
||||
@@ -1606,7 +1616,7 @@ int sqlite3FindInIndex(Parse *pParse, Expr *pX, int *prNotFound){
|
||||
}else{
|
||||
testcase( pParse->nQueryLoop>0 );
|
||||
pParse->nQueryLoop = 0;
|
||||
if( pX->pLeft->iColumn<0 && !ExprHasAnyProperty(pX, EP_xIsSelect) ){
|
||||
if( pX->pLeft->iColumn<0 && !ExprHasProperty(pX, EP_xIsSelect) ){
|
||||
eType = IN_INDEX_ROWID;
|
||||
}
|
||||
}
|
||||
@@ -1675,7 +1685,7 @@ int sqlite3CodeSubselect(
|
||||
** If all of the above are false, then we can run this code just once
|
||||
** save the results, and reuse the same result on subsequent invocations.
|
||||
*/
|
||||
if( !ExprHasAnyProperty(pExpr, EP_VarSelect) ){
|
||||
if( !ExprHasProperty(pExpr, EP_VarSelect) ){
|
||||
testAddr = sqlite3CodeOnce(pParse);
|
||||
}
|
||||
|
||||
@@ -1844,7 +1854,7 @@ int sqlite3CodeSubselect(
|
||||
return 0;
|
||||
}
|
||||
rReg = dest.iSDParm;
|
||||
ExprSetIrreducible(pExpr);
|
||||
ExprSetVVAProperty(pExpr, EP_NoReduce);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -2316,6 +2326,16 @@ static int usedAsColumnCache(Parse *pParse, int iFrom, int iTo){
|
||||
}
|
||||
#endif /* SQLITE_DEBUG || SQLITE_COVERAGE_TEST */
|
||||
|
||||
/*
|
||||
** Convert an expression node to a TK_REGISTER
|
||||
*/
|
||||
static void exprToRegister(Expr *p, int iReg){
|
||||
p->op2 = p->op;
|
||||
p->op = TK_REGISTER;
|
||||
p->iTable = iReg;
|
||||
ExprClearProperty(p, EP_Skip);
|
||||
}
|
||||
|
||||
/*
|
||||
** Generate code into the current Vdbe to evaluate the given
|
||||
** expression. Attempt to store the results in register "target".
|
||||
@@ -2441,7 +2461,7 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
|
||||
int aff, to_op;
|
||||
inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
|
||||
assert( !ExprHasProperty(pExpr, EP_IntValue) );
|
||||
aff = sqlite3AffinityType(pExpr->u.zToken);
|
||||
aff = sqlite3AffinityType(pExpr->u.zToken, 0);
|
||||
to_op = aff - SQLITE_AFF_TEXT + OP_ToText;
|
||||
assert( to_op==OP_ToText || aff!=SQLITE_AFF_TEXT );
|
||||
assert( to_op==OP_ToBlob || aff!=SQLITE_AFF_NONE );
|
||||
@@ -2615,7 +2635,7 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
|
||||
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
|
||||
testcase( op==TK_CONST_FUNC );
|
||||
testcase( op==TK_FUNCTION );
|
||||
if( ExprHasAnyProperty(pExpr, EP_TokenOnly) ){
|
||||
if( ExprHasProperty(pExpr, EP_TokenOnly) ){
|
||||
pFarg = 0;
|
||||
}else{
|
||||
pFarg = pExpr->x.pList;
|
||||
@@ -2634,7 +2654,7 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
|
||||
** IFNULL() functions. This avoids unnecessary evalation of
|
||||
** arguments past the first non-NULL argument.
|
||||
*/
|
||||
if( pDef->flags & SQLITE_FUNC_COALESCE ){
|
||||
if( pDef->funcFlags & SQLITE_FUNC_COALESCE ){
|
||||
int endCoalesce = sqlite3VdbeMakeLabel(v);
|
||||
assert( nFarg>=2 );
|
||||
sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
|
||||
@@ -2649,6 +2669,14 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
|
||||
break;
|
||||
}
|
||||
|
||||
/* The UNLIKELY() function is a no-op. The result is the value
|
||||
** of the first argument.
|
||||
*/
|
||||
if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){
|
||||
assert( nFarg>=1 );
|
||||
sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
|
||||
break;
|
||||
}
|
||||
|
||||
if( pFarg ){
|
||||
r1 = sqlite3GetTempRange(pParse, nFarg);
|
||||
@@ -2658,7 +2686,7 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
|
||||
** or OPFLAG_TYPEOFARG respectively, to avoid unnecessary data
|
||||
** loading.
|
||||
*/
|
||||
if( (pDef->flags & (SQLITE_FUNC_LENGTH|SQLITE_FUNC_TYPEOF))!=0 ){
|
||||
if( (pDef->funcFlags & (SQLITE_FUNC_LENGTH|SQLITE_FUNC_TYPEOF))!=0 ){
|
||||
u8 exprOp;
|
||||
assert( nFarg==1 );
|
||||
assert( pFarg->a[0].pExpr!=0 );
|
||||
@@ -2666,8 +2694,9 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
|
||||
if( exprOp==TK_COLUMN || exprOp==TK_AGG_COLUMN ){
|
||||
assert( SQLITE_FUNC_LENGTH==OPFLAG_LENGTHARG );
|
||||
assert( SQLITE_FUNC_TYPEOF==OPFLAG_TYPEOFARG );
|
||||
testcase( pDef->flags==SQLITE_FUNC_LENGTH );
|
||||
pFarg->a[0].pExpr->op2 = pDef->flags;
|
||||
testcase( (pDef->funcFlags&~SQLITE_FUNC_ENCMASK)
|
||||
==SQLITE_FUNC_LENGTH );
|
||||
pFarg->a[0].pExpr->op2 = pDef->funcFlags&~SQLITE_FUNC_ENCMASK;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2700,11 +2729,11 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
|
||||
if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){
|
||||
constMask |= (1<<i);
|
||||
}
|
||||
if( (pDef->flags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){
|
||||
if( (pDef->funcFlags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){
|
||||
pColl = sqlite3ExprCollSeq(pParse, pFarg->a[i].pExpr);
|
||||
}
|
||||
}
|
||||
if( pDef->flags & SQLITE_FUNC_NEEDCOLL ){
|
||||
if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
|
||||
if( !pColl ) pColl = db->pDfltColl;
|
||||
sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
|
||||
}
|
||||
@@ -2845,9 +2874,9 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
|
||||
** WHEN x=eN THEN rN ELSE y END
|
||||
**
|
||||
** X (if it exists) is in pExpr->pLeft.
|
||||
** Y is in pExpr->pRight. The Y is also optional. If there is no
|
||||
** ELSE clause and no other term matches, then the result of the
|
||||
** exprssion is NULL.
|
||||
** Y is in the last element of pExpr->x.pList if pExpr->x.pList->nExpr is
|
||||
** odd. The Y is also optional. If the number of elements in x.pList
|
||||
** is even, then Y is omitted and the "otherwise" result is NULL.
|
||||
** Ei is in pExpr->pList->a[i*2] and Ri is pExpr->pList->a[i*2+1].
|
||||
**
|
||||
** The result of the expression is the Ri for the first matching Ei,
|
||||
@@ -2868,7 +2897,6 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
|
||||
VVA_ONLY( int iCacheLevel = pParse->iCacheLevel; )
|
||||
|
||||
assert( !ExprHasProperty(pExpr, EP_xIsSelect) && pExpr->x.pList );
|
||||
assert((pExpr->x.pList->nExpr % 2) == 0);
|
||||
assert(pExpr->x.pList->nExpr > 0);
|
||||
pEList = pExpr->x.pList;
|
||||
aListelem = pEList->a;
|
||||
@@ -2878,9 +2906,8 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
|
||||
cacheX = *pX;
|
||||
testcase( pX->op==TK_COLUMN );
|
||||
testcase( pX->op==TK_REGISTER );
|
||||
cacheX.iTable = sqlite3ExprCodeTemp(pParse, pX, ®Free1);
|
||||
exprToRegister(&cacheX, sqlite3ExprCodeTemp(pParse, pX, ®Free1));
|
||||
testcase( regFree1==0 );
|
||||
cacheX.op = TK_REGISTER;
|
||||
opCompare.op = TK_EQ;
|
||||
opCompare.pLeft = &cacheX;
|
||||
pTest = &opCompare;
|
||||
@@ -2890,7 +2917,7 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
|
||||
** purposes and possibly overwritten. */
|
||||
regFree1 = 0;
|
||||
}
|
||||
for(i=0; i<nExpr; i=i+2){
|
||||
for(i=0; i<nExpr-1; i=i+2){
|
||||
sqlite3ExprCachePush(pParse);
|
||||
if( pX ){
|
||||
assert( pTest!=0 );
|
||||
@@ -2908,9 +2935,9 @@ int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target){
|
||||
sqlite3ExprCachePop(pParse, 1);
|
||||
sqlite3VdbeResolveLabel(v, nextCase);
|
||||
}
|
||||
if( pExpr->pRight ){
|
||||
if( (nExpr&1)!=0 ){
|
||||
sqlite3ExprCachePush(pParse);
|
||||
sqlite3ExprCode(pParse, pExpr->pRight, target);
|
||||
sqlite3ExprCode(pParse, pEList->a[nExpr-1].pExpr, target);
|
||||
sqlite3ExprCachePop(pParse, 1);
|
||||
}else{
|
||||
sqlite3VdbeAddOp2(v, OP_Null, 0, target);
|
||||
@@ -3022,9 +3049,7 @@ int sqlite3ExprCodeAndCache(Parse *pParse, Expr *pExpr, int target){
|
||||
int iMem;
|
||||
iMem = ++pParse->nMem;
|
||||
sqlite3VdbeAddOp2(v, OP_Copy, inReg, iMem);
|
||||
pExpr->iTable = iMem;
|
||||
pExpr->op2 = pExpr->op;
|
||||
pExpr->op = TK_REGISTER;
|
||||
exprToRegister(pExpr, iMem);
|
||||
}
|
||||
return inReg;
|
||||
}
|
||||
@@ -3103,7 +3128,7 @@ void sqlite3ExplainExpr(Vdbe *pOut, Expr *pExpr){
|
||||
case TK_CAST: {
|
||||
/* Expressions of the form: CAST(pLeft AS token) */
|
||||
const char *zAff = "unk";
|
||||
switch( sqlite3AffinityType(pExpr->u.zToken) ){
|
||||
switch( sqlite3AffinityType(pExpr->u.zToken, 0) ){
|
||||
case SQLITE_AFF_TEXT: zAff = "TEXT"; break;
|
||||
case SQLITE_AFF_NONE: zAff = "NONE"; break;
|
||||
case SQLITE_AFF_NUMERIC: zAff = "NUMERIC"; break;
|
||||
@@ -3154,7 +3179,7 @@ void sqlite3ExplainExpr(Vdbe *pOut, Expr *pExpr){
|
||||
case TK_CONST_FUNC:
|
||||
case TK_FUNCTION: {
|
||||
ExprList *pFarg; /* List of function arguments */
|
||||
if( ExprHasAnyProperty(pExpr, EP_TokenOnly) ){
|
||||
if( ExprHasProperty(pExpr, EP_TokenOnly) ){
|
||||
pFarg = 0;
|
||||
}else{
|
||||
pFarg = pExpr->x.pList;
|
||||
@@ -3403,9 +3428,7 @@ static int evalConstExpr(Walker *pWalker, Expr *pExpr){
|
||||
** but suboptimal, so we want to know about the situation to fix it.
|
||||
** Hence the following assert: */
|
||||
assert( r2==r1 );
|
||||
pExpr->op2 = pExpr->op;
|
||||
pExpr->op = TK_REGISTER;
|
||||
pExpr->iTable = r2;
|
||||
exprToRegister(pExpr, r2);
|
||||
return WRC_Prune;
|
||||
}
|
||||
return WRC_Continue;
|
||||
@@ -3503,9 +3526,7 @@ static void exprCodeBetween(
|
||||
compRight.op = TK_LE;
|
||||
compRight.pLeft = &exprX;
|
||||
compRight.pRight = pExpr->x.pList->a[1].pExpr;
|
||||
exprX.iTable = sqlite3ExprCodeTemp(pParse, &exprX, ®Free1);
|
||||
exprX.op2 = exprX.op;
|
||||
exprX.op = TK_REGISTER;
|
||||
exprToRegister(&exprX, sqlite3ExprCodeTemp(pParse, &exprX, ®Free1));
|
||||
if( jumpIfTrue ){
|
||||
sqlite3ExprIfTrue(pParse, &exprAnd, dest, jumpIfNull);
|
||||
}else{
|
||||
@@ -3820,8 +3841,8 @@ int sqlite3ExprCompare(Expr *pA, Expr *pB, int iTab){
|
||||
if( pA==0||pB==0 ){
|
||||
return pB==pA ? 0 : 2;
|
||||
}
|
||||
assert( !ExprHasAnyProperty(pA, EP_TokenOnly|EP_Reduced) );
|
||||
assert( !ExprHasAnyProperty(pB, EP_TokenOnly|EP_Reduced) );
|
||||
assert( !ExprHasProperty(pA, EP_TokenOnly|EP_Reduced) );
|
||||
assert( !ExprHasProperty(pB, EP_TokenOnly|EP_Reduced) );
|
||||
if( ExprHasProperty(pA, EP_xIsSelect) || ExprHasProperty(pB, EP_xIsSelect) ){
|
||||
return 2;
|
||||
}
|
||||
@@ -4035,7 +4056,7 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
|
||||
struct SrcList_item *pItem = pSrcList->a;
|
||||
for(i=0; i<pSrcList->nSrc; i++, pItem++){
|
||||
struct AggInfo_col *pCol;
|
||||
assert( !ExprHasAnyProperty(pExpr, EP_TokenOnly|EP_Reduced) );
|
||||
assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
|
||||
if( pExpr->iTable==pItem->iCursor ){
|
||||
/* If we reach this point, it means that pExpr refers to a table
|
||||
** that is in the FROM clause of the aggregate query.
|
||||
@@ -4084,7 +4105,7 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
|
||||
** Convert the pExpr to be a TK_AGG_COLUMN referring to that
|
||||
** pAggInfo->aCol[] entry.
|
||||
*/
|
||||
ExprSetIrreducible(pExpr);
|
||||
ExprSetVVAProperty(pExpr, EP_NoReduce);
|
||||
pExpr->pAggInfo = pAggInfo;
|
||||
pExpr->op = TK_AGG_COLUMN;
|
||||
pExpr->iAgg = (i16)k;
|
||||
@@ -4130,8 +4151,8 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
|
||||
}
|
||||
/* Make pExpr point to the appropriate pAggInfo->aFunc[] entry
|
||||
*/
|
||||
assert( !ExprHasAnyProperty(pExpr, EP_TokenOnly|EP_Reduced) );
|
||||
ExprSetIrreducible(pExpr);
|
||||
assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
|
||||
ExprSetVVAProperty(pExpr, EP_NoReduce);
|
||||
pExpr->iAgg = (i16)i;
|
||||
pExpr->pAggInfo = pAggInfo;
|
||||
return WRC_Prune;
|
||||
|
||||
+89
-23
@@ -682,6 +682,70 @@ void sqlite3FkDropTable(Parse *pParse, SrcList *pName, Table *pTab){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** The second argument points to an FKey object representing a foreign key
|
||||
** for which pTab is the child table. An UPDATE statement against pTab
|
||||
** is currently being processed. For each column of the table that is
|
||||
** actually updated, the corresponding element in the aChange[] array
|
||||
** is zero or greater (if a column is unmodified the corresponding element
|
||||
** is set to -1). If the rowid column is modified by the UPDATE statement
|
||||
** the bChngRowid argument is non-zero.
|
||||
**
|
||||
** This function returns true if any of the columns that are part of the
|
||||
** child key for FK constraint *p are modified.
|
||||
*/
|
||||
static int fkChildIsModified(
|
||||
Table *pTab, /* Table being updated */
|
||||
FKey *p, /* Foreign key for which pTab is the child */
|
||||
int *aChange, /* Array indicating modified columns */
|
||||
int bChngRowid /* True if rowid is modified by this update */
|
||||
){
|
||||
int i;
|
||||
for(i=0; i<p->nCol; i++){
|
||||
int iChildKey = p->aCol[i].iFrom;
|
||||
if( aChange[iChildKey]>=0 ) return 1;
|
||||
if( iChildKey==pTab->iPKey && bChngRowid ) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** The second argument points to an FKey object representing a foreign key
|
||||
** for which pTab is the parent table. An UPDATE statement against pTab
|
||||
** is currently being processed. For each column of the table that is
|
||||
** actually updated, the corresponding element in the aChange[] array
|
||||
** is zero or greater (if a column is unmodified the corresponding element
|
||||
** is set to -1). If the rowid column is modified by the UPDATE statement
|
||||
** the bChngRowid argument is non-zero.
|
||||
**
|
||||
** This function returns true if any of the columns that are part of the
|
||||
** parent key for FK constraint *p are modified.
|
||||
*/
|
||||
static int fkParentIsModified(
|
||||
Table *pTab,
|
||||
FKey *p,
|
||||
int *aChange,
|
||||
int bChngRowid
|
||||
){
|
||||
int i;
|
||||
for(i=0; i<p->nCol; i++){
|
||||
char *zKey = p->aCol[i].zCol;
|
||||
int iKey;
|
||||
for(iKey=0; iKey<pTab->nCol; iKey++){
|
||||
if( aChange[iKey]>=0 || (iKey==pTab->iPKey && bChngRowid) ){
|
||||
Column *pCol = &pTab->aCol[iKey];
|
||||
if( zKey ){
|
||||
if( 0==sqlite3StrICmp(pCol->zName, zKey) ) return 1;
|
||||
}else if( pCol->colFlags & COLFLAG_PRIMKEY ){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** This function is called when inserting, deleting or updating a row of
|
||||
** table pTab to generate VDBE code to perform foreign key constraint
|
||||
@@ -706,7 +770,9 @@ void sqlite3FkCheck(
|
||||
Parse *pParse, /* Parse context */
|
||||
Table *pTab, /* Row is being deleted from this table */
|
||||
int regOld, /* Previous row data is stored here */
|
||||
int regNew /* New row data is stored here */
|
||||
int regNew, /* New row data is stored here */
|
||||
int *aChange, /* Array indicating UPDATEd columns (or 0) */
|
||||
int bChngRowid /* True if rowid is UPDATEd */
|
||||
){
|
||||
sqlite3 *db = pParse->db; /* Database handle */
|
||||
FKey *pFKey; /* Used to iterate through FKs */
|
||||
@@ -734,6 +800,13 @@ void sqlite3FkCheck(
|
||||
int i;
|
||||
int isIgnore = 0;
|
||||
|
||||
if( aChange
|
||||
&& sqlite3_stricmp(pTab->zName, pFKey->zTo)!=0
|
||||
&& fkChildIsModified(pTab, pFKey, aChange, bChngRowid)==0
|
||||
){
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Find the parent table of this foreign key. Also find a unique index
|
||||
** on the parent key columns in the parent table. If either of these
|
||||
** schema items cannot be located, set an error in pParse and return
|
||||
@@ -816,6 +889,10 @@ void sqlite3FkCheck(
|
||||
SrcList *pSrc;
|
||||
int *aiCol = 0;
|
||||
|
||||
if( aChange && fkParentIsModified(pTab, pFKey, aChange, bChngRowid)==0 ){
|
||||
continue;
|
||||
}
|
||||
|
||||
if( !pFKey->isDeferred && !(db->flags & SQLITE_DeferFKs)
|
||||
&& !pParse->pToplevel && !pParse->isMultiWrite
|
||||
){
|
||||
@@ -889,6 +966,7 @@ u32 sqlite3FkOldmask(
|
||||
return mask;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** This function is called before generating code to update or delete a
|
||||
** row contained in table pTab. If the operation is a DELETE, then
|
||||
@@ -918,32 +996,16 @@ int sqlite3FkRequired(
|
||||
}else{
|
||||
/* This is an UPDATE. Foreign key processing is only required if the
|
||||
** operation modifies one or more child or parent key columns. */
|
||||
int i;
|
||||
FKey *p;
|
||||
|
||||
/* Check if any child key columns are being modified. */
|
||||
for(p=pTab->pFKey; p; p=p->pNextFrom){
|
||||
for(i=0; i<p->nCol; i++){
|
||||
int iChildKey = p->aCol[i].iFrom;
|
||||
if( aChange[iChildKey]>=0 ) return 1;
|
||||
if( iChildKey==pTab->iPKey && chngRowid ) return 1;
|
||||
}
|
||||
if( fkChildIsModified(pTab, p, aChange, chngRowid) ) return 1;
|
||||
}
|
||||
|
||||
/* Check if any parent key columns are being modified. */
|
||||
for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
|
||||
for(i=0; i<p->nCol; i++){
|
||||
char *zKey = p->aCol[i].zCol;
|
||||
int iKey;
|
||||
for(iKey=0; iKey<pTab->nCol; iKey++){
|
||||
Column *pCol = &pTab->aCol[iKey];
|
||||
if( (zKey ? !sqlite3StrICmp(pCol->zName, zKey)
|
||||
: (pCol->colFlags & COLFLAG_PRIMKEY)!=0) ){
|
||||
if( aChange[iKey]>=0 ) return 1;
|
||||
if( iKey==pTab->iPKey && chngRowid ) return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( fkParentIsModified(pTab, p, aChange, chngRowid) ) return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1169,7 +1231,9 @@ void sqlite3FkActions(
|
||||
Parse *pParse, /* Parse context */
|
||||
Table *pTab, /* Table being updated or deleted from */
|
||||
ExprList *pChanges, /* Change-list for UPDATE, NULL for DELETE */
|
||||
int regOld /* Address of array containing old row */
|
||||
int regOld, /* Address of array containing old row */
|
||||
int *aChange, /* Array indicating UPDATEd columns (or 0) */
|
||||
int bChngRowid /* True if rowid is UPDATEd */
|
||||
){
|
||||
/* If foreign-key support is enabled, iterate through all FKs that
|
||||
** refer to table pTab. If there is an action associated with the FK
|
||||
@@ -1178,9 +1242,11 @@ void sqlite3FkActions(
|
||||
if( pParse->db->flags&SQLITE_ForeignKeys ){
|
||||
FKey *pFKey; /* Iterator variable */
|
||||
for(pFKey = sqlite3FkReferences(pTab); pFKey; pFKey=pFKey->pNextTo){
|
||||
Trigger *pAction = fkActionTrigger(pParse, pTab, pFKey, pChanges);
|
||||
if( pAction ){
|
||||
sqlite3CodeRowTriggerDirect(pParse, pAction, pTab, regOld, OE_Abort, 0);
|
||||
if( aChange==0 || fkParentIsModified(pTab, pFKey, aChange, bChngRowid) ){
|
||||
Trigger *pAct = fkActionTrigger(pParse, pTab, pFKey, pChanges);
|
||||
if( pAct ){
|
||||
sqlite3CodeRowTriggerDirect(pParse, pAct, pTab, regOld, OE_Abort, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+22
-20
@@ -418,14 +418,14 @@ static void lowerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
}
|
||||
|
||||
/*
|
||||
** The COALESCE() and IFNULL() functions are implemented as VDBE code so
|
||||
** that unused argument values do not have to be computed. However, we
|
||||
** still need some kind of function implementation for this routines in
|
||||
** the function table. That function implementation will never be called
|
||||
** so it doesn't matter what the implementation is. We might as well use
|
||||
** the "version()" function as a substitute.
|
||||
** Some functions like COALESCE() and IFNULL() and UNLIKELY() are implemented
|
||||
** as VDBE code so that unused argument values do not have to be computed.
|
||||
** However, we still need some kind of function implementation for this
|
||||
** routines in the function table. The noopFunc macro provides this.
|
||||
** noopFunc will never be called so it doesn't matter what the implementation
|
||||
** is. We might as well use the "version()" function as a substitute.
|
||||
*/
|
||||
#define ifnullFunc versionFunc /* Substitute function - never called */
|
||||
#define noopFunc versionFunc /* Substitute function - never called */
|
||||
|
||||
/*
|
||||
** Implementation of random(). Return a random integer.
|
||||
@@ -544,9 +544,9 @@ struct compareInfo {
|
||||
*/
|
||||
#if defined(SQLITE_EBCDIC)
|
||||
# define sqlite3Utf8Read(A) (*((*A)++))
|
||||
# define GlogUpperToLower(A) A = sqlite3UpperToLower[A]
|
||||
# define GlobUpperToLower(A) A = sqlite3UpperToLower[A]
|
||||
#else
|
||||
# define GlogUpperToLower(A) if( !((A)&~0x7f) ){ A = sqlite3UpperToLower[A]; }
|
||||
# define GlobUpperToLower(A) if( !((A)&~0x7f) ){ A = sqlite3UpperToLower[A]; }
|
||||
#endif
|
||||
|
||||
static const struct compareInfo globInfo = { '*', '?', '[', 0 };
|
||||
@@ -625,11 +625,11 @@ static int patternCompare(
|
||||
}
|
||||
while( (c2 = sqlite3Utf8Read(&zString))!=0 ){
|
||||
if( noCase ){
|
||||
GlogUpperToLower(c2);
|
||||
GlogUpperToLower(c);
|
||||
GlobUpperToLower(c2);
|
||||
GlobUpperToLower(c);
|
||||
while( c2 != 0 && c2 != c ){
|
||||
c2 = sqlite3Utf8Read(&zString);
|
||||
GlogUpperToLower(c2);
|
||||
GlobUpperToLower(c2);
|
||||
}
|
||||
}else{
|
||||
while( c2 != 0 && c2 != c ){
|
||||
@@ -681,8 +681,8 @@ static int patternCompare(
|
||||
}else{
|
||||
c2 = sqlite3Utf8Read(&zString);
|
||||
if( noCase ){
|
||||
GlogUpperToLower(c);
|
||||
GlogUpperToLower(c2);
|
||||
GlobUpperToLower(c);
|
||||
GlobUpperToLower(c2);
|
||||
}
|
||||
if( c!=c2 ){
|
||||
return 0;
|
||||
@@ -1554,7 +1554,7 @@ static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
|
||||
pDef = sqlite3FindFunction(db, zName, sqlite3Strlen30(zName),
|
||||
2, SQLITE_UTF8, 0);
|
||||
if( ALWAYS(pDef) ){
|
||||
pDef->flags = flagVal;
|
||||
pDef->funcFlags |= flagVal;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1598,7 +1598,7 @@ int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
|
||||
pDef = sqlite3FindFunction(db, pExpr->u.zToken,
|
||||
sqlite3Strlen30(pExpr->u.zToken),
|
||||
2, SQLITE_UTF8, 0);
|
||||
if( NEVER(pDef==0) || (pDef->flags & SQLITE_FUNC_LIKE)==0 ){
|
||||
if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1610,7 +1610,7 @@ int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
|
||||
assert( (char*)&likeInfoAlt == (char*)&likeInfoAlt.matchAll );
|
||||
assert( &((char*)&likeInfoAlt)[1] == (char*)&likeInfoAlt.matchOne );
|
||||
assert( &((char*)&likeInfoAlt)[2] == (char*)&likeInfoAlt.matchSet );
|
||||
*pIsNocase = (pDef->flags & SQLITE_FUNC_CASE)==0;
|
||||
*pIsNocase = (pDef->funcFlags & SQLITE_FUNC_CASE)==0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1659,9 +1659,11 @@ void sqlite3RegisterGlobalFunctions(void){
|
||||
FUNCTION(lower, 1, 0, 0, lowerFunc ),
|
||||
FUNCTION(coalesce, 1, 0, 0, 0 ),
|
||||
FUNCTION(coalesce, 0, 0, 0, 0 ),
|
||||
FUNCTION2(coalesce, -1, 0, 0, ifnullFunc, SQLITE_FUNC_COALESCE),
|
||||
FUNCTION2(coalesce, -1, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
|
||||
FUNCTION(hex, 1, 0, 0, hexFunc ),
|
||||
FUNCTION2(ifnull, 2, 0, 0, ifnullFunc, SQLITE_FUNC_COALESCE),
|
||||
FUNCTION2(ifnull, 2, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
|
||||
FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
|
||||
FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
|
||||
FUNCTION(random, 0, 0, 0, randomFunc ),
|
||||
FUNCTION(randomblob, 1, 0, 0, randomBlob ),
|
||||
FUNCTION(nullif, 2, 0, 1, nullifFunc ),
|
||||
@@ -1689,7 +1691,7 @@ void sqlite3RegisterGlobalFunctions(void){
|
||||
AGGREGATE(total, 1, 0, 0, sumStep, totalFinalize ),
|
||||
AGGREGATE(avg, 1, 0, 0, sumStep, avgFinalize ),
|
||||
/* AGGREGATE(count, 0, 0, 0, countStep, countFinalize ), */
|
||||
{0,SQLITE_UTF8,SQLITE_FUNC_COUNT,0,0,0,countStep,countFinalize,"count",0,0},
|
||||
{0,SQLITE_UTF8|SQLITE_FUNC_COUNT,0,0,0,countStep,countFinalize,"count",0,0},
|
||||
AGGREGATE(count, 1, 0, 0, countStep, countFinalize ),
|
||||
AGGREGATE(group_concat, 1, 0, 0, groupConcatStep, groupConcatFinalize),
|
||||
AGGREGATE(group_concat, 2, 0, 0, groupConcatStep, groupConcatFinalize),
|
||||
|
||||
+2
-1
@@ -1031,7 +1031,7 @@ void sqlite3Insert(
|
||||
sqlite3GenerateConstraintChecks(pParse, pTab, baseCur, regIns, aRegIdx,
|
||||
keyColumn>=0, 0, onError, endOfLoop, &isReplace
|
||||
);
|
||||
sqlite3FkCheck(pParse, pTab, 0, regIns);
|
||||
sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
|
||||
sqlite3CompleteInsertion(
|
||||
pParse, pTab, baseCur, regIns, aRegIdx, 0, appendFlag, isReplace==0
|
||||
);
|
||||
@@ -1900,6 +1900,7 @@ static int xferOptimization(
|
||||
pKey = sqlite3IndexKeyinfo(pParse, pDestIdx);
|
||||
sqlite3VdbeAddOp4(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest,
|
||||
(char*)pKey, P4_KEYINFO_HANDOFF);
|
||||
sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
|
||||
VdbeComment((v, "%s", pDestIdx->zName));
|
||||
addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0);
|
||||
sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
|
||||
|
||||
+2
-2
@@ -1406,7 +1406,7 @@ int sqlite3CreateFunc(
|
||||
** operation to continue but invalidate all precompiled statements.
|
||||
*/
|
||||
p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 0);
|
||||
if( p && p->iPrefEnc==enc && p->nArg==nArg ){
|
||||
if( p && (p->funcFlags & SQLITE_FUNC_ENCMASK)==enc && p->nArg==nArg ){
|
||||
if( db->nVdbeActive ){
|
||||
sqlite3Error(db, SQLITE_BUSY,
|
||||
"unable to delete/modify user-function due to active statements");
|
||||
@@ -1431,7 +1431,7 @@ int sqlite3CreateFunc(
|
||||
pDestructor->nRef++;
|
||||
}
|
||||
p->pDestructor = pDestructor;
|
||||
p->flags = 0;
|
||||
p->funcFlags &= SQLITE_FUNC_ENCMASK;
|
||||
p->xFunc = xFunc;
|
||||
p->xStep = xStep;
|
||||
p->xFinalize = xFinal;
|
||||
|
||||
@@ -484,6 +484,7 @@ void sqlite3_free(void *p){
|
||||
*/
|
||||
void sqlite3DbFree(sqlite3 *db, void *p){
|
||||
assert( db==0 || sqlite3_mutex_held(db->mutex) );
|
||||
if( p==0 ) return;
|
||||
if( db ){
|
||||
if( db->pnBytesFreed ){
|
||||
*db->pnBytesFreed += sqlite3DbMallocSize(db, p);
|
||||
|
||||
+81
-50
@@ -108,6 +108,14 @@
|
||||
# define winIsDirSep(a) (((a) == '/') || ((a) == '\\'))
|
||||
#endif
|
||||
|
||||
/*
|
||||
** This macro is used when a local variable is set to a value that is
|
||||
** [sometimes] not used by the code (e.g. via conditional compilation).
|
||||
*/
|
||||
#ifndef UNUSED_VARIABLE_VALUE
|
||||
# define UNUSED_VARIABLE_VALUE(x) (void)(x)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Returns the string that should be used as the directory separator.
|
||||
*/
|
||||
@@ -358,7 +366,8 @@ const sqlite3_mem_methods *sqlite3MemGetWin32(void);
|
||||
*/
|
||||
#ifdef SQLITE_TEST
|
||||
int sqlite3_os_type = 0;
|
||||
#else
|
||||
#elif !SQLITE_OS_WINCE && !SQLITE_OS_WINRT && \
|
||||
defined(SQLITE_WIN32_HAS_ANSI) && defined(SQLITE_WIN32_HAS_WIDE)
|
||||
static int sqlite3_os_type = 0;
|
||||
#endif
|
||||
|
||||
@@ -673,10 +682,19 @@ static struct win_syscall {
|
||||
#define osGetVersionExA ((BOOL(WINAPI*)( \
|
||||
LPOSVERSIONINFOA))aSyscall[34].pCurrent)
|
||||
|
||||
#if defined(SQLITE_WIN32_HAS_WIDE)
|
||||
{ "GetVersionExW", (SYSCALL)GetVersionExW, 0 },
|
||||
#else
|
||||
{ "GetVersionExW", (SYSCALL)0, 0 },
|
||||
#endif
|
||||
|
||||
#define osGetVersionExW ((BOOL(WINAPI*)( \
|
||||
LPOSVERSIONINFOW))aSyscall[35].pCurrent)
|
||||
|
||||
{ "HeapAlloc", (SYSCALL)HeapAlloc, 0 },
|
||||
|
||||
#define osHeapAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD, \
|
||||
SIZE_T))aSyscall[35].pCurrent)
|
||||
SIZE_T))aSyscall[36].pCurrent)
|
||||
|
||||
#if !SQLITE_OS_WINRT
|
||||
{ "HeapCreate", (SYSCALL)HeapCreate, 0 },
|
||||
@@ -685,7 +703,7 @@ static struct win_syscall {
|
||||
#endif
|
||||
|
||||
#define osHeapCreate ((HANDLE(WINAPI*)(DWORD,SIZE_T, \
|
||||
SIZE_T))aSyscall[36].pCurrent)
|
||||
SIZE_T))aSyscall[37].pCurrent)
|
||||
|
||||
#if !SQLITE_OS_WINRT
|
||||
{ "HeapDestroy", (SYSCALL)HeapDestroy, 0 },
|
||||
@@ -693,21 +711,21 @@ static struct win_syscall {
|
||||
{ "HeapDestroy", (SYSCALL)0, 0 },
|
||||
#endif
|
||||
|
||||
#define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[37].pCurrent)
|
||||
#define osHeapDestroy ((BOOL(WINAPI*)(HANDLE))aSyscall[38].pCurrent)
|
||||
|
||||
{ "HeapFree", (SYSCALL)HeapFree, 0 },
|
||||
|
||||
#define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[38].pCurrent)
|
||||
#define osHeapFree ((BOOL(WINAPI*)(HANDLE,DWORD,LPVOID))aSyscall[39].pCurrent)
|
||||
|
||||
{ "HeapReAlloc", (SYSCALL)HeapReAlloc, 0 },
|
||||
|
||||
#define osHeapReAlloc ((LPVOID(WINAPI*)(HANDLE,DWORD,LPVOID, \
|
||||
SIZE_T))aSyscall[39].pCurrent)
|
||||
SIZE_T))aSyscall[40].pCurrent)
|
||||
|
||||
{ "HeapSize", (SYSCALL)HeapSize, 0 },
|
||||
|
||||
#define osHeapSize ((SIZE_T(WINAPI*)(HANDLE,DWORD, \
|
||||
LPCVOID))aSyscall[40].pCurrent)
|
||||
LPCVOID))aSyscall[41].pCurrent)
|
||||
|
||||
#if !SQLITE_OS_WINRT
|
||||
{ "HeapValidate", (SYSCALL)HeapValidate, 0 },
|
||||
@@ -716,7 +734,7 @@ static struct win_syscall {
|
||||
#endif
|
||||
|
||||
#define osHeapValidate ((BOOL(WINAPI*)(HANDLE,DWORD, \
|
||||
LPCVOID))aSyscall[41].pCurrent)
|
||||
LPCVOID))aSyscall[42].pCurrent)
|
||||
|
||||
#if defined(SQLITE_WIN32_HAS_ANSI) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
|
||||
{ "LoadLibraryA", (SYSCALL)LoadLibraryA, 0 },
|
||||
@@ -724,7 +742,7 @@ static struct win_syscall {
|
||||
{ "LoadLibraryA", (SYSCALL)0, 0 },
|
||||
#endif
|
||||
|
||||
#define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[42].pCurrent)
|
||||
#define osLoadLibraryA ((HMODULE(WINAPI*)(LPCSTR))aSyscall[43].pCurrent)
|
||||
|
||||
#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \
|
||||
!defined(SQLITE_OMIT_LOAD_EXTENSION)
|
||||
@@ -733,7 +751,7 @@ static struct win_syscall {
|
||||
{ "LoadLibraryW", (SYSCALL)0, 0 },
|
||||
#endif
|
||||
|
||||
#define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[43].pCurrent)
|
||||
#define osLoadLibraryW ((HMODULE(WINAPI*)(LPCWSTR))aSyscall[44].pCurrent)
|
||||
|
||||
#if !SQLITE_OS_WINRT
|
||||
{ "LocalFree", (SYSCALL)LocalFree, 0 },
|
||||
@@ -741,7 +759,7 @@ static struct win_syscall {
|
||||
{ "LocalFree", (SYSCALL)0, 0 },
|
||||
#endif
|
||||
|
||||
#define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[44].pCurrent)
|
||||
#define osLocalFree ((HLOCAL(WINAPI*)(HLOCAL))aSyscall[45].pCurrent)
|
||||
|
||||
#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
|
||||
{ "LockFile", (SYSCALL)LockFile, 0 },
|
||||
@@ -751,7 +769,7 @@ static struct win_syscall {
|
||||
|
||||
#ifndef osLockFile
|
||||
#define osLockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
|
||||
DWORD))aSyscall[45].pCurrent)
|
||||
DWORD))aSyscall[46].pCurrent)
|
||||
#endif
|
||||
|
||||
#if !SQLITE_OS_WINCE
|
||||
@@ -762,7 +780,7 @@ static struct win_syscall {
|
||||
|
||||
#ifndef osLockFileEx
|
||||
#define osLockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD,DWORD, \
|
||||
LPOVERLAPPED))aSyscall[46].pCurrent)
|
||||
LPOVERLAPPED))aSyscall[47].pCurrent)
|
||||
#endif
|
||||
|
||||
#if SQLITE_OS_WINCE || (!SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL))
|
||||
@@ -772,26 +790,26 @@ static struct win_syscall {
|
||||
#endif
|
||||
|
||||
#define osMapViewOfFile ((LPVOID(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
|
||||
SIZE_T))aSyscall[47].pCurrent)
|
||||
SIZE_T))aSyscall[48].pCurrent)
|
||||
|
||||
{ "MultiByteToWideChar", (SYSCALL)MultiByteToWideChar, 0 },
|
||||
|
||||
#define osMultiByteToWideChar ((int(WINAPI*)(UINT,DWORD,LPCSTR,int,LPWSTR, \
|
||||
int))aSyscall[48].pCurrent)
|
||||
int))aSyscall[49].pCurrent)
|
||||
|
||||
{ "QueryPerformanceCounter", (SYSCALL)QueryPerformanceCounter, 0 },
|
||||
|
||||
#define osQueryPerformanceCounter ((BOOL(WINAPI*)( \
|
||||
LARGE_INTEGER*))aSyscall[49].pCurrent)
|
||||
LARGE_INTEGER*))aSyscall[50].pCurrent)
|
||||
|
||||
{ "ReadFile", (SYSCALL)ReadFile, 0 },
|
||||
|
||||
#define osReadFile ((BOOL(WINAPI*)(HANDLE,LPVOID,DWORD,LPDWORD, \
|
||||
LPOVERLAPPED))aSyscall[50].pCurrent)
|
||||
LPOVERLAPPED))aSyscall[51].pCurrent)
|
||||
|
||||
{ "SetEndOfFile", (SYSCALL)SetEndOfFile, 0 },
|
||||
|
||||
#define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[51].pCurrent)
|
||||
#define osSetEndOfFile ((BOOL(WINAPI*)(HANDLE))aSyscall[52].pCurrent)
|
||||
|
||||
#if !SQLITE_OS_WINRT
|
||||
{ "SetFilePointer", (SYSCALL)SetFilePointer, 0 },
|
||||
@@ -800,7 +818,7 @@ static struct win_syscall {
|
||||
#endif
|
||||
|
||||
#define osSetFilePointer ((DWORD(WINAPI*)(HANDLE,LONG,PLONG, \
|
||||
DWORD))aSyscall[52].pCurrent)
|
||||
DWORD))aSyscall[53].pCurrent)
|
||||
|
||||
#if !SQLITE_OS_WINRT
|
||||
{ "Sleep", (SYSCALL)Sleep, 0 },
|
||||
@@ -808,12 +826,12 @@ static struct win_syscall {
|
||||
{ "Sleep", (SYSCALL)0, 0 },
|
||||
#endif
|
||||
|
||||
#define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[53].pCurrent)
|
||||
#define osSleep ((VOID(WINAPI*)(DWORD))aSyscall[54].pCurrent)
|
||||
|
||||
{ "SystemTimeToFileTime", (SYSCALL)SystemTimeToFileTime, 0 },
|
||||
|
||||
#define osSystemTimeToFileTime ((BOOL(WINAPI*)(CONST SYSTEMTIME*, \
|
||||
LPFILETIME))aSyscall[54].pCurrent)
|
||||
LPFILETIME))aSyscall[55].pCurrent)
|
||||
|
||||
#if !SQLITE_OS_WINCE && !SQLITE_OS_WINRT
|
||||
{ "UnlockFile", (SYSCALL)UnlockFile, 0 },
|
||||
@@ -823,7 +841,7 @@ static struct win_syscall {
|
||||
|
||||
#ifndef osUnlockFile
|
||||
#define osUnlockFile ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
|
||||
DWORD))aSyscall[55].pCurrent)
|
||||
DWORD))aSyscall[56].pCurrent)
|
||||
#endif
|
||||
|
||||
#if !SQLITE_OS_WINCE
|
||||
@@ -833,7 +851,7 @@ static struct win_syscall {
|
||||
#endif
|
||||
|
||||
#define osUnlockFileEx ((BOOL(WINAPI*)(HANDLE,DWORD,DWORD,DWORD, \
|
||||
LPOVERLAPPED))aSyscall[56].pCurrent)
|
||||
LPOVERLAPPED))aSyscall[57].pCurrent)
|
||||
|
||||
#if SQLITE_OS_WINCE || !defined(SQLITE_OMIT_WAL)
|
||||
{ "UnmapViewOfFile", (SYSCALL)UnmapViewOfFile, 0 },
|
||||
@@ -841,17 +859,17 @@ static struct win_syscall {
|
||||
{ "UnmapViewOfFile", (SYSCALL)0, 0 },
|
||||
#endif
|
||||
|
||||
#define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[57].pCurrent)
|
||||
#define osUnmapViewOfFile ((BOOL(WINAPI*)(LPCVOID))aSyscall[58].pCurrent)
|
||||
|
||||
{ "WideCharToMultiByte", (SYSCALL)WideCharToMultiByte, 0 },
|
||||
|
||||
#define osWideCharToMultiByte ((int(WINAPI*)(UINT,DWORD,LPCWSTR,int,LPSTR,int, \
|
||||
LPCSTR,LPBOOL))aSyscall[58].pCurrent)
|
||||
LPCSTR,LPBOOL))aSyscall[59].pCurrent)
|
||||
|
||||
{ "WriteFile", (SYSCALL)WriteFile, 0 },
|
||||
|
||||
#define osWriteFile ((BOOL(WINAPI*)(HANDLE,LPCVOID,DWORD,LPDWORD, \
|
||||
LPOVERLAPPED))aSyscall[59].pCurrent)
|
||||
LPOVERLAPPED))aSyscall[60].pCurrent)
|
||||
|
||||
#if SQLITE_OS_WINRT
|
||||
{ "CreateEventExW", (SYSCALL)CreateEventExW, 0 },
|
||||
@@ -860,7 +878,7 @@ static struct win_syscall {
|
||||
#endif
|
||||
|
||||
#define osCreateEventExW ((HANDLE(WINAPI*)(LPSECURITY_ATTRIBUTES,LPCWSTR, \
|
||||
DWORD,DWORD))aSyscall[60].pCurrent)
|
||||
DWORD,DWORD))aSyscall[61].pCurrent)
|
||||
|
||||
#if !SQLITE_OS_WINRT
|
||||
{ "WaitForSingleObject", (SYSCALL)WaitForSingleObject, 0 },
|
||||
@@ -869,7 +887,7 @@ static struct win_syscall {
|
||||
#endif
|
||||
|
||||
#define osWaitForSingleObject ((DWORD(WINAPI*)(HANDLE, \
|
||||
DWORD))aSyscall[61].pCurrent)
|
||||
DWORD))aSyscall[62].pCurrent)
|
||||
|
||||
#if SQLITE_OS_WINRT
|
||||
{ "WaitForSingleObjectEx", (SYSCALL)WaitForSingleObjectEx, 0 },
|
||||
@@ -878,7 +896,7 @@ static struct win_syscall {
|
||||
#endif
|
||||
|
||||
#define osWaitForSingleObjectEx ((DWORD(WINAPI*)(HANDLE,DWORD, \
|
||||
BOOL))aSyscall[62].pCurrent)
|
||||
BOOL))aSyscall[63].pCurrent)
|
||||
|
||||
#if SQLITE_OS_WINRT
|
||||
{ "SetFilePointerEx", (SYSCALL)SetFilePointerEx, 0 },
|
||||
@@ -887,7 +905,7 @@ static struct win_syscall {
|
||||
#endif
|
||||
|
||||
#define osSetFilePointerEx ((BOOL(WINAPI*)(HANDLE,LARGE_INTEGER, \
|
||||
PLARGE_INTEGER,DWORD))aSyscall[63].pCurrent)
|
||||
PLARGE_INTEGER,DWORD))aSyscall[64].pCurrent)
|
||||
|
||||
#if SQLITE_OS_WINRT
|
||||
{ "GetFileInformationByHandleEx", (SYSCALL)GetFileInformationByHandleEx, 0 },
|
||||
@@ -896,7 +914,7 @@ static struct win_syscall {
|
||||
#endif
|
||||
|
||||
#define osGetFileInformationByHandleEx ((BOOL(WINAPI*)(HANDLE, \
|
||||
FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[64].pCurrent)
|
||||
FILE_INFO_BY_HANDLE_CLASS,LPVOID,DWORD))aSyscall[65].pCurrent)
|
||||
|
||||
#if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
|
||||
{ "MapViewOfFileFromApp", (SYSCALL)MapViewOfFileFromApp, 0 },
|
||||
@@ -905,7 +923,7 @@ static struct win_syscall {
|
||||
#endif
|
||||
|
||||
#define osMapViewOfFileFromApp ((LPVOID(WINAPI*)(HANDLE,ULONG,ULONG64, \
|
||||
SIZE_T))aSyscall[65].pCurrent)
|
||||
SIZE_T))aSyscall[66].pCurrent)
|
||||
|
||||
#if SQLITE_OS_WINRT
|
||||
{ "CreateFile2", (SYSCALL)CreateFile2, 0 },
|
||||
@@ -914,7 +932,7 @@ static struct win_syscall {
|
||||
#endif
|
||||
|
||||
#define osCreateFile2 ((HANDLE(WINAPI*)(LPCWSTR,DWORD,DWORD,DWORD, \
|
||||
LPCREATEFILE2_EXTENDED_PARAMETERS))aSyscall[66].pCurrent)
|
||||
LPCREATEFILE2_EXTENDED_PARAMETERS))aSyscall[67].pCurrent)
|
||||
|
||||
#if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_LOAD_EXTENSION)
|
||||
{ "LoadPackagedLibrary", (SYSCALL)LoadPackagedLibrary, 0 },
|
||||
@@ -923,7 +941,7 @@ static struct win_syscall {
|
||||
#endif
|
||||
|
||||
#define osLoadPackagedLibrary ((HMODULE(WINAPI*)(LPCWSTR, \
|
||||
DWORD))aSyscall[67].pCurrent)
|
||||
DWORD))aSyscall[68].pCurrent)
|
||||
|
||||
#if SQLITE_OS_WINRT
|
||||
{ "GetTickCount64", (SYSCALL)GetTickCount64, 0 },
|
||||
@@ -931,7 +949,7 @@ static struct win_syscall {
|
||||
{ "GetTickCount64", (SYSCALL)0, 0 },
|
||||
#endif
|
||||
|
||||
#define osGetTickCount64 ((ULONGLONG(WINAPI*)(VOID))aSyscall[68].pCurrent)
|
||||
#define osGetTickCount64 ((ULONGLONG(WINAPI*)(VOID))aSyscall[69].pCurrent)
|
||||
|
||||
#if SQLITE_OS_WINRT
|
||||
{ "GetNativeSystemInfo", (SYSCALL)GetNativeSystemInfo, 0 },
|
||||
@@ -940,7 +958,7 @@ static struct win_syscall {
|
||||
#endif
|
||||
|
||||
#define osGetNativeSystemInfo ((VOID(WINAPI*)( \
|
||||
LPSYSTEM_INFO))aSyscall[69].pCurrent)
|
||||
LPSYSTEM_INFO))aSyscall[70].pCurrent)
|
||||
|
||||
#if defined(SQLITE_WIN32_HAS_ANSI)
|
||||
{ "OutputDebugStringA", (SYSCALL)OutputDebugStringA, 0 },
|
||||
@@ -948,7 +966,7 @@ static struct win_syscall {
|
||||
{ "OutputDebugStringA", (SYSCALL)0, 0 },
|
||||
#endif
|
||||
|
||||
#define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[70].pCurrent)
|
||||
#define osOutputDebugStringA ((VOID(WINAPI*)(LPCSTR))aSyscall[71].pCurrent)
|
||||
|
||||
#if defined(SQLITE_WIN32_HAS_WIDE)
|
||||
{ "OutputDebugStringW", (SYSCALL)OutputDebugStringW, 0 },
|
||||
@@ -956,11 +974,11 @@ static struct win_syscall {
|
||||
{ "OutputDebugStringW", (SYSCALL)0, 0 },
|
||||
#endif
|
||||
|
||||
#define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[71].pCurrent)
|
||||
#define osOutputDebugStringW ((VOID(WINAPI*)(LPCWSTR))aSyscall[72].pCurrent)
|
||||
|
||||
{ "GetProcessHeap", (SYSCALL)GetProcessHeap, 0 },
|
||||
|
||||
#define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[72].pCurrent)
|
||||
#define osGetProcessHeap ((HANDLE(WINAPI*)(VOID))aSyscall[73].pCurrent)
|
||||
|
||||
#if SQLITE_OS_WINRT && !defined(SQLITE_OMIT_WAL)
|
||||
{ "CreateFileMappingFromApp", (SYSCALL)CreateFileMappingFromApp, 0 },
|
||||
@@ -969,7 +987,7 @@ static struct win_syscall {
|
||||
#endif
|
||||
|
||||
#define osCreateFileMappingFromApp ((HANDLE(WINAPI*)(HANDLE, \
|
||||
LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[73].pCurrent)
|
||||
LPSECURITY_ATTRIBUTES,ULONG,ULONG64,LPCWSTR))aSyscall[74].pCurrent)
|
||||
|
||||
}; /* End of the overrideable system calls */
|
||||
|
||||
@@ -1125,6 +1143,10 @@ void sqlite3_win32_sleep(DWORD milliseconds){
|
||||
** WinNT/2K/XP so that we will know whether or not we can safely call
|
||||
** the LockFileEx() API.
|
||||
*/
|
||||
#ifndef NTDDI_WIN8
|
||||
# define NTDDI_WIN8 0x06020000
|
||||
#endif
|
||||
|
||||
#if SQLITE_OS_WINCE || SQLITE_OS_WINRT || !defined(SQLITE_WIN32_HAS_ANSI)
|
||||
# define osIsNT() (1)
|
||||
#elif !defined(SQLITE_WIN32_HAS_WIDE)
|
||||
@@ -1132,9 +1154,15 @@ void sqlite3_win32_sleep(DWORD milliseconds){
|
||||
#else
|
||||
static int osIsNT(void){
|
||||
if( sqlite3_os_type==0 ){
|
||||
#if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WIN8
|
||||
OSVERSIONINFOW sInfo;
|
||||
sInfo.dwOSVersionInfoSize = sizeof(sInfo);
|
||||
osGetVersionExW(&sInfo);
|
||||
#else
|
||||
OSVERSIONINFOA sInfo;
|
||||
sInfo.dwOSVersionInfoSize = sizeof(sInfo);
|
||||
osGetVersionExA(&sInfo);
|
||||
#endif
|
||||
sqlite3_os_type = sInfo.dwPlatformId==VER_PLATFORM_WIN32_NT ? 2 : 1;
|
||||
}
|
||||
return sqlite3_os_type==2;
|
||||
@@ -1159,7 +1187,7 @@ static void *winMemMalloc(int nBytes){
|
||||
assert( nBytes>=0 );
|
||||
p = osHeapAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, (SIZE_T)nBytes);
|
||||
if( !p ){
|
||||
sqlite3_log(SQLITE_NOMEM, "failed to HeapAlloc %u bytes (%d), heap=%p",
|
||||
sqlite3_log(SQLITE_NOMEM, "failed to HeapAlloc %u bytes (%lu), heap=%p",
|
||||
nBytes, osGetLastError(), (void*)hHeap);
|
||||
}
|
||||
return p;
|
||||
@@ -1180,7 +1208,7 @@ static void winMemFree(void *pPrior){
|
||||
#endif
|
||||
if( !pPrior ) return; /* Passing NULL to HeapFree is undefined. */
|
||||
if( !osHeapFree(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior) ){
|
||||
sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%d), heap=%p",
|
||||
sqlite3_log(SQLITE_NOMEM, "failed to HeapFree block %p (%lu), heap=%p",
|
||||
pPrior, osGetLastError(), (void*)hHeap);
|
||||
}
|
||||
}
|
||||
@@ -1206,7 +1234,7 @@ static void *winMemRealloc(void *pPrior, int nBytes){
|
||||
p = osHeapReAlloc(hHeap, SQLITE_WIN32_HEAP_FLAGS, pPrior, (SIZE_T)nBytes);
|
||||
}
|
||||
if( !p ){
|
||||
sqlite3_log(SQLITE_NOMEM, "failed to %s %u bytes (%d), heap=%p",
|
||||
sqlite3_log(SQLITE_NOMEM, "failed to %s %u bytes (%lu), heap=%p",
|
||||
pPrior ? "HeapReAlloc" : "HeapAlloc", nBytes, osGetLastError(),
|
||||
(void*)hHeap);
|
||||
}
|
||||
@@ -1230,7 +1258,7 @@ static int winMemSize(void *p){
|
||||
if( !p ) return 0;
|
||||
n = osHeapSize(hHeap, SQLITE_WIN32_HEAP_FLAGS, p);
|
||||
if( n==(SIZE_T)-1 ){
|
||||
sqlite3_log(SQLITE_NOMEM, "failed to HeapSize block %p (%d), heap=%p",
|
||||
sqlite3_log(SQLITE_NOMEM, "failed to HeapSize block %p (%lu), heap=%p",
|
||||
p, osGetLastError(), (void*)hHeap);
|
||||
return 0;
|
||||
}
|
||||
@@ -1260,7 +1288,7 @@ static int winMemInit(void *pAppData){
|
||||
SQLITE_WIN32_HEAP_MAX_SIZE);
|
||||
if( !pWinMemData->hHeap ){
|
||||
sqlite3_log(SQLITE_NOMEM,
|
||||
"failed to HeapCreate (%d), flags=%u, initSize=%u, maxSize=%u",
|
||||
"failed to HeapCreate (%lu), flags=%u, initSize=%u, maxSize=%u",
|
||||
osGetLastError(), SQLITE_WIN32_HEAP_FLAGS,
|
||||
SQLITE_WIN32_HEAP_INIT_SIZE, SQLITE_WIN32_HEAP_MAX_SIZE);
|
||||
return SQLITE_NOMEM;
|
||||
@@ -1272,7 +1300,7 @@ static int winMemInit(void *pAppData){
|
||||
pWinMemData->hHeap = osGetProcessHeap();
|
||||
if( !pWinMemData->hHeap ){
|
||||
sqlite3_log(SQLITE_NOMEM,
|
||||
"failed to GetProcessHeap (%d)", osGetLastError());
|
||||
"failed to GetProcessHeap (%lu)", osGetLastError());
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
pWinMemData->bOwned = FALSE;
|
||||
@@ -1300,7 +1328,7 @@ static void winMemShutdown(void *pAppData){
|
||||
#endif
|
||||
if( pWinMemData->bOwned ){
|
||||
if( !osHeapDestroy(pWinMemData->hHeap) ){
|
||||
sqlite3_log(SQLITE_NOMEM, "failed to HeapDestroy (%d), heap=%p",
|
||||
sqlite3_log(SQLITE_NOMEM, "failed to HeapDestroy (%lu), heap=%p",
|
||||
osGetLastError(), (void*)pWinMemData->hHeap);
|
||||
}
|
||||
pWinMemData->bOwned = FALSE;
|
||||
@@ -3185,7 +3213,6 @@ static int winDelete(sqlite3_vfs *,const char*,int);
|
||||
static void winShmPurge(sqlite3_vfs *pVfs, int deleteFlag){
|
||||
winShmNode **pp;
|
||||
winShmNode *p;
|
||||
BOOL bRc;
|
||||
assert( winShmMutexHeld() );
|
||||
OSTRACE(("SHM-PURGE pid=%lu, deleteFlag=%d\n",
|
||||
osGetCurrentProcessId(), deleteFlag));
|
||||
@@ -3195,12 +3222,14 @@ static void winShmPurge(sqlite3_vfs *pVfs, int deleteFlag){
|
||||
int i;
|
||||
if( p->mutex ) sqlite3_mutex_free(p->mutex);
|
||||
for(i=0; i<p->nRegion; i++){
|
||||
bRc = osUnmapViewOfFile(p->aRegion[i].pMap);
|
||||
BOOL bRc = osUnmapViewOfFile(p->aRegion[i].pMap);
|
||||
OSTRACE(("SHM-PURGE-UNMAP pid=%lu, region=%d, rc=%s\n",
|
||||
osGetCurrentProcessId(), i, bRc ? "ok" : "failed"));
|
||||
UNUSED_VARIABLE_VALUE(bRc);
|
||||
bRc = osCloseHandle(p->aRegion[i].hMap);
|
||||
OSTRACE(("SHM-PURGE-CLOSE pid=%lu, region=%d, rc=%s\n",
|
||||
osGetCurrentProcessId(), i, bRc ? "ok" : "failed"));
|
||||
UNUSED_VARIABLE_VALUE(bRc);
|
||||
}
|
||||
if( p->hFile.h!=NULL && p->hFile.h!=INVALID_HANDLE_VALUE ){
|
||||
SimulateIOErrorBenign(1);
|
||||
@@ -3919,6 +3948,7 @@ static const sqlite3_io_methods winIoMethod = {
|
||||
** sqlite3_vfs object.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
/*
|
||||
** Convert a filename from whatever the underlying operating system
|
||||
** supports for filenames into UTF-8. Space to hold the result is
|
||||
@@ -3937,6 +3967,7 @@ static char *winConvertToUtf8Filename(const void *zFilename){
|
||||
/* caller will handle out of memory */
|
||||
return zConverted;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Convert a UTF-8 filename into whatever form the underlying
|
||||
@@ -5154,7 +5185,7 @@ int sqlite3_os_init(void){
|
||||
|
||||
/* Double-check that the aSyscall[] array has been constructed
|
||||
** correctly. See ticket [bb3a86e890c8e96ab] */
|
||||
assert( ArraySize(aSyscall)==74 );
|
||||
assert( ArraySize(aSyscall)==75 );
|
||||
|
||||
/* get memory map allocation granularity */
|
||||
memset(&winSysInfo, 0, sizeof(SYSTEM_INFO));
|
||||
|
||||
+3
-2
@@ -1081,12 +1081,13 @@ expr(A) ::= expr(W) between_op(N) expr(X) AND expr(Y). [BETWEEN] {
|
||||
|
||||
/* CASE expressions */
|
||||
expr(A) ::= CASE(C) case_operand(X) case_exprlist(Y) case_else(Z) END(E). {
|
||||
A.pExpr = sqlite3PExpr(pParse, TK_CASE, X, Z, 0);
|
||||
A.pExpr = sqlite3PExpr(pParse, TK_CASE, X, 0, 0);
|
||||
if( A.pExpr ){
|
||||
A.pExpr->x.pList = Y;
|
||||
A.pExpr->x.pList = Z ? sqlite3ExprListAppend(pParse,Y,Z) : Y;
|
||||
sqlite3ExprSetHeight(pParse, A.pExpr);
|
||||
}else{
|
||||
sqlite3ExprListDelete(pParse->db, Y);
|
||||
sqlite3ExprDelete(pParse->db, Z);
|
||||
}
|
||||
A.zStart = C.z;
|
||||
A.zEnd = &E.z[E.n];
|
||||
|
||||
+675
-294
File diff suppressed because it is too large
Load Diff
+31
-4
@@ -107,6 +107,7 @@ static void resolveAlias(
|
||||
incrAggFunctionDepth(pDup, nSubquery);
|
||||
pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0);
|
||||
if( pDup==0 ) return;
|
||||
ExprSetProperty(pDup, EP_Skip);
|
||||
if( pEList->a[iCol].iAlias==0 ){
|
||||
pEList->a[iCol].iAlias = (u16)(++pParse->nAlias);
|
||||
}
|
||||
@@ -129,7 +130,7 @@ static void resolveAlias(
|
||||
if( !ExprHasProperty(pExpr, EP_IntValue) && pExpr->u.zToken!=0 ){
|
||||
assert( (pExpr->flags & (EP_Reduced|EP_TokenOnly))==0 );
|
||||
pExpr->u.zToken = sqlite3DbStrDup(db, pExpr->u.zToken);
|
||||
pExpr->flags2 |= EP2_MallocedToken;
|
||||
pExpr->flags |= EP_MemToken;
|
||||
}
|
||||
sqlite3DbFree(db, pDup);
|
||||
}
|
||||
@@ -229,12 +230,12 @@ static int lookupName(
|
||||
|
||||
assert( pNC ); /* the name context cannot be NULL. */
|
||||
assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
|
||||
assert( !ExprHasAnyProperty(pExpr, EP_TokenOnly|EP_Reduced) );
|
||||
assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
|
||||
|
||||
/* Initialize the node to no-match */
|
||||
pExpr->iTable = -1;
|
||||
pExpr->pTab = 0;
|
||||
ExprSetIrreducible(pExpr);
|
||||
ExprSetVVAProperty(pExpr, EP_NoReduce);
|
||||
|
||||
/* Translate the schema name in zDb into a pointer to the corresponding
|
||||
** schema. If not found, pSchema will remain NULL and nothing will match
|
||||
@@ -570,6 +571,19 @@ static void notValidCheckConstraint(
|
||||
# define notValidCheckConstraint(P,N,M)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Expression p should encode a floating point value between 1.0 and 0.0.
|
||||
** Return 1024 times this value. Or return -1 if p is not a floating point
|
||||
** value between 1.0 and 0.0.
|
||||
*/
|
||||
static int exprProbability(Expr *p){
|
||||
double r = -1.0;
|
||||
if( p->op!=TK_FLOAT ) return -1;
|
||||
sqlite3AtoF(p->u.zToken, &r, sqlite3Strlen30(p->u.zToken), SQLITE_UTF8);
|
||||
assert( r>=0.0 );
|
||||
if( r>1.0 ) return -1;
|
||||
return (int)(r*1000.0);
|
||||
}
|
||||
|
||||
/*
|
||||
** This routine is callback for sqlite3WalkExpr().
|
||||
@@ -591,7 +605,7 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
||||
pParse = pNC->pParse;
|
||||
assert( pParse==pWalker->pParse );
|
||||
|
||||
if( ExprHasAnyProperty(pExpr, EP_Resolved) ) return WRC_Prune;
|
||||
if( ExprHasProperty(pExpr, EP_Resolved) ) return WRC_Prune;
|
||||
ExprSetProperty(pExpr, EP_Resolved);
|
||||
#ifndef NDEBUG
|
||||
if( pNC->pSrcList && pNC->pSrcList->nAlloc>0 ){
|
||||
@@ -683,6 +697,19 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
|
||||
}
|
||||
}else{
|
||||
is_agg = pDef->xFunc==0;
|
||||
if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){
|
||||
ExprSetProperty(pExpr, EP_Unlikely|EP_Skip);
|
||||
if( n==2 ){
|
||||
pExpr->iTable = exprProbability(pList->a[1].pExpr);
|
||||
if( pExpr->iTable<0 ){
|
||||
sqlite3ErrorMsg(pParse, "second argument to likelihood() must be a "
|
||||
"constant between 0.0 and 1.0");
|
||||
pNC->nErr++;
|
||||
}
|
||||
}else{
|
||||
pExpr->iTable = 62; /* TUNING: Default 2nd arg to unlikely() is 0.0625 */
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifndef SQLITE_OMIT_AUTHORIZATION
|
||||
if( pDef ){
|
||||
|
||||
+17
-17
@@ -264,8 +264,8 @@ static void addWhereTerm(
|
||||
pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2, 0);
|
||||
if( pEq && isOuterJoin ){
|
||||
ExprSetProperty(pEq, EP_FromJoin);
|
||||
assert( !ExprHasAnyProperty(pEq, EP_TokenOnly|EP_Reduced) );
|
||||
ExprSetIrreducible(pEq);
|
||||
assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) );
|
||||
ExprSetVVAProperty(pEq, EP_NoReduce);
|
||||
pEq->iRightJoinTable = (i16)pE2->iTable;
|
||||
}
|
||||
*ppWhere = sqlite3ExprAnd(db, *ppWhere, pEq);
|
||||
@@ -300,8 +300,8 @@ static void addWhereTerm(
|
||||
static void setJoinExpr(Expr *p, int iTable){
|
||||
while( p ){
|
||||
ExprSetProperty(p, EP_FromJoin);
|
||||
assert( !ExprHasAnyProperty(p, EP_TokenOnly|EP_Reduced) );
|
||||
ExprSetIrreducible(p);
|
||||
assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
|
||||
ExprSetVVAProperty(p, EP_NoReduce);
|
||||
p->iRightJoinTable = (i16)iTable;
|
||||
setJoinExpr(p->pLeft, iTable);
|
||||
p = p->pRight;
|
||||
@@ -1480,7 +1480,7 @@ Table *sqlite3ResultSetOfSelect(Parse *pParse, Select *pSelect){
|
||||
assert( db->lookaside.bEnabled==0 );
|
||||
pTab->nRef = 1;
|
||||
pTab->zName = 0;
|
||||
pTab->nRowEst = 1000000;
|
||||
pTab->nRowEst = 200;
|
||||
selectColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
|
||||
selectAddColumnTypeAndCollation(pParse, pTab->nCol, pTab->aCol, pSelect);
|
||||
pTab->iPKey = -1;
|
||||
@@ -3228,7 +3228,7 @@ static Table *isSimpleCount(Select *p, AggInfo *pAggInfo){
|
||||
if( IsVirtual(pTab) ) return 0;
|
||||
if( pExpr->op!=TK_AGG_FUNCTION ) return 0;
|
||||
if( NEVER(pAggInfo->nFunc==0) ) return 0;
|
||||
if( (pAggInfo->aFunc[0].pFunc->flags&SQLITE_FUNC_COUNT)==0 ) return 0;
|
||||
if( (pAggInfo->aFunc[0].pFunc->funcFlags&SQLITE_FUNC_COUNT)==0 ) return 0;
|
||||
if( pExpr->flags&EP_Distinct ) return 0;
|
||||
|
||||
return pTab;
|
||||
@@ -3398,7 +3398,7 @@ static int selectExpander(Walker *pWalker, Select *p){
|
||||
while( pSel->pPrior ){ pSel = pSel->pPrior; }
|
||||
selectColumnsFromExprList(pParse, pSel->pEList, &pTab->nCol, &pTab->aCol);
|
||||
pTab->iPKey = -1;
|
||||
pTab->nRowEst = 1000000;
|
||||
pTab->nRowEst = 200;
|
||||
pTab->tabFlags |= TF_Ephemeral;
|
||||
#endif
|
||||
}else{
|
||||
@@ -3825,7 +3825,7 @@ static void updateAccumulator(Parse *pParse, AggInfo *pAggInfo){
|
||||
assert( nArg==1 );
|
||||
codeDistinct(pParse, pF->iDistinct, addrNext, 1, regAgg);
|
||||
}
|
||||
if( pF->pFunc->flags & SQLITE_FUNC_NEEDCOLL ){
|
||||
if( pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
|
||||
CollSeq *pColl = 0;
|
||||
struct ExprList_item *pItem;
|
||||
int j;
|
||||
@@ -4597,25 +4597,25 @@ int sqlite3Select(
|
||||
sqlite3CodeVerifySchema(pParse, iDb);
|
||||
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
|
||||
|
||||
/* Search for the index that has the least amount of columns. If
|
||||
** there is such an index, and it has less columns than the table
|
||||
** does, then we can assume that it consumes less space on disk and
|
||||
** will therefore be cheaper to scan to determine the query result.
|
||||
** In this case set iRoot to the root page number of the index b-tree
|
||||
** and pKeyInfo to the KeyInfo structure required to navigate the
|
||||
** index.
|
||||
/* Search for the index that has the lowest scan cost.
|
||||
**
|
||||
** (2011-04-15) Do not do a full scan of an unordered index.
|
||||
**
|
||||
** (2013-10-03) Do not count the entires in a partial index.
|
||||
**
|
||||
** In practice the KeyInfo structure will not be used. It is only
|
||||
** passed to keep OP_OpenRead happy.
|
||||
*/
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
if( pIdx->bUnordered==0 && (!pBest || pIdx->nColumn<pBest->nColumn) ){
|
||||
if( pIdx->bUnordered==0
|
||||
&& pIdx->szIdxRow<pTab->szTabRow
|
||||
&& pIdx->pPartIdxWhere==0
|
||||
&& (!pBest || pIdx->szIdxRow<pBest->szIdxRow)
|
||||
){
|
||||
pBest = pIdx;
|
||||
}
|
||||
}
|
||||
if( pBest && pBest->nColumn<pTab->nCol ){
|
||||
if( pBest ){
|
||||
iRoot = pBest->tnum;
|
||||
pKeyInfo = sqlite3IndexKeyinfo(pParse, pBest);
|
||||
}
|
||||
|
||||
+9
-5
@@ -974,7 +974,7 @@ static int run_table_dump_query(
|
||||
rc = sqlite3_prepare(p->db, zSelect, -1, &pSelect, 0);
|
||||
if( rc!=SQLITE_OK || !pSelect ){
|
||||
fprintf(p->out, "/**** ERROR: (%d) %s *****/\n", rc, sqlite3_errmsg(p->db));
|
||||
p->nErr++;
|
||||
if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++;
|
||||
return rc;
|
||||
}
|
||||
rc = sqlite3_step(pSelect);
|
||||
@@ -1001,7 +1001,7 @@ static int run_table_dump_query(
|
||||
rc = sqlite3_finalize(pSelect);
|
||||
if( rc!=SQLITE_OK ){
|
||||
fprintf(p->out, "/**** ERROR: (%d) %s *****/\n", rc, sqlite3_errmsg(p->db));
|
||||
p->nErr++;
|
||||
if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@@ -1194,7 +1194,7 @@ static int shell_exec(
|
||||
char **azCols = (char **)pData; /* Names of result columns */
|
||||
char **azVals = &azCols[nCol]; /* Results */
|
||||
int *aiTypes = (int *)&azVals[nCol]; /* Result types */
|
||||
int i;
|
||||
int i, x;
|
||||
assert(sizeof(int) <= sizeof(char *));
|
||||
/* save off ptrs to column names */
|
||||
for(i=0; i<nCol; i++){
|
||||
@@ -1203,8 +1203,12 @@ static int shell_exec(
|
||||
do{
|
||||
/* extract the data and data types */
|
||||
for(i=0; i<nCol; i++){
|
||||
azVals[i] = (char *)sqlite3_column_text(pStmt, i);
|
||||
aiTypes[i] = sqlite3_column_type(pStmt, i);
|
||||
aiTypes[i] = x = sqlite3_column_type(pStmt, i);
|
||||
if( x==SQLITE_BLOB && pArg->mode==MODE_Insert ){
|
||||
azVals[i] = "";
|
||||
}else{
|
||||
azVals[i] = (char*)sqlite3_column_text(pStmt, i);
|
||||
}
|
||||
if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
|
||||
rc = SQLITE_NOMEM;
|
||||
break; /* from for */
|
||||
|
||||
+13
-9
@@ -17,7 +17,11 @@
|
||||
#include "winresrc.h"
|
||||
#else
|
||||
#include "windows.h"
|
||||
#endif
|
||||
#endif /* !defined(_WIN32_WCE) */
|
||||
|
||||
#if !defined(VS_FF_NONE)
|
||||
# define VS_FF_NONE 0x00000000L
|
||||
#endif /* !defined(VS_FF_NONE) */
|
||||
|
||||
#include "sqlite3.h"
|
||||
#include "sqlite3rc.h"
|
||||
@@ -26,10 +30,10 @@
|
||||
* English (U.S.) resources
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#if defined(_WIN32)
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif /* _WIN32 */
|
||||
#endif /* defined(_WIN32) */
|
||||
|
||||
/*
|
||||
* Version
|
||||
@@ -38,14 +42,14 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION SQLITE_RESOURCE_VERSION
|
||||
PRODUCTVERSION SQLITE_RESOURCE_VERSION
|
||||
FILEFLAGSMASK 0x3F
|
||||
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
|
||||
#if defined(_DEBUG)
|
||||
FILEFLAGS 0x1L
|
||||
FILEFLAGS VS_FF_DEBUG
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEFLAGS VS_FF_NONE
|
||||
#endif /* defined(_DEBUG) */
|
||||
FILEOS VOS__WINDOWS32
|
||||
FILETYPE VFT_APP
|
||||
FILETYPE VFT_DLL
|
||||
FILESUBTYPE VFT2_UNKNOWN
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
@@ -64,6 +68,6 @@ BEGIN
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
VALUE "Translation", 0x409, 0x4b0
|
||||
END
|
||||
END
|
||||
|
||||
+104
-73
@@ -470,6 +470,31 @@ typedef INT8_TYPE i8; /* 1-byte signed integer */
|
||||
typedef u32 tRowcnt; /* 32-bit is the default */
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Estimated quantities used for query planning are stored as 16-bit
|
||||
** logarithms. For quantity X, the value stored is 10*log2(X). This
|
||||
** gives a possible range of values of approximately 1.0e986 to 1e-986.
|
||||
** But the allowed values are "grainy". Not every value is representable.
|
||||
** For example, quantities 16 and 17 are both represented by a LogEst
|
||||
** of 40. However, since LogEst quantatites are suppose to be estimates,
|
||||
** not exact values, this imprecision is not a problem.
|
||||
**
|
||||
** "LogEst" is short for "Logarithimic Estimate".
|
||||
**
|
||||
** Examples:
|
||||
** 1 -> 0 20 -> 43 10000 -> 132
|
||||
** 2 -> 10 25 -> 46 25000 -> 146
|
||||
** 3 -> 16 100 -> 66 1000000 -> 199
|
||||
** 4 -> 20 1000 -> 99 1048576 -> 200
|
||||
** 10 -> 33 1024 -> 100 4294967296 -> 320
|
||||
**
|
||||
** The LogEst can be negative to indicate fractional values.
|
||||
** Examples:
|
||||
**
|
||||
** 0.5 -> -10 0.1 -> -33 0.0625 -> -40
|
||||
*/
|
||||
typedef INT16_TYPE LogEst;
|
||||
|
||||
/*
|
||||
** Macros to determine whether the machine is big or little endian,
|
||||
** evaluated at runtime.
|
||||
@@ -921,8 +946,6 @@ struct sqlite3 {
|
||||
void(*xCollNeeded16)(void*,sqlite3*,int eTextRep,const void*);
|
||||
void *pCollNeededArg;
|
||||
sqlite3_value *pErr; /* Most recent error message */
|
||||
char *zErrMsg; /* Most recent error message (UTF-8 encoded) */
|
||||
char *zErrMsg16; /* Most recent error message (UTF-16 encoded) */
|
||||
union {
|
||||
volatile int isInterrupted; /* True if sqlite3_interrupt has been called */
|
||||
double notUsed1; /* Spacer */
|
||||
@@ -1032,6 +1055,7 @@ struct sqlite3 {
|
||||
#define SQLITE_Transitive 0x0200 /* Transitive constraints */
|
||||
#define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */
|
||||
#define SQLITE_Stat3 0x0800 /* Use the SQLITE_STAT3 table */
|
||||
#define SQLITE_AdjustOutEst 0x1000 /* Adjust output estimates using WHERE */
|
||||
#define SQLITE_AllOpts 0xffff /* All optimizations */
|
||||
|
||||
/*
|
||||
@@ -1065,8 +1089,7 @@ struct sqlite3 {
|
||||
*/
|
||||
struct FuncDef {
|
||||
i16 nArg; /* Number of arguments. -1 means unlimited */
|
||||
u8 iPrefEnc; /* Preferred text encoding (SQLITE_UTF8, 16LE, 16BE) */
|
||||
u8 flags; /* Some combination of SQLITE_FUNC_* */
|
||||
u16 funcFlags; /* Some combination of SQLITE_FUNC_* */
|
||||
void *pUserData; /* User data parameter */
|
||||
FuncDef *pNext; /* Next function with same name */
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value**); /* Regular function */
|
||||
@@ -1102,14 +1125,16 @@ struct FuncDestructor {
|
||||
** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. There
|
||||
** are assert() statements in the code to verify this.
|
||||
*/
|
||||
#define SQLITE_FUNC_LIKE 0x01 /* Candidate for the LIKE optimization */
|
||||
#define SQLITE_FUNC_CASE 0x02 /* Case-sensitive LIKE-type function */
|
||||
#define SQLITE_FUNC_EPHEM 0x04 /* Ephemeral. Delete with VDBE */
|
||||
#define SQLITE_FUNC_NEEDCOLL 0x08 /* sqlite3GetFuncCollSeq() might be called */
|
||||
#define SQLITE_FUNC_COUNT 0x10 /* Built-in count(*) aggregate */
|
||||
#define SQLITE_FUNC_COALESCE 0x20 /* Built-in coalesce() or ifnull() function */
|
||||
#define SQLITE_FUNC_LENGTH 0x40 /* Built-in length() function */
|
||||
#define SQLITE_FUNC_TYPEOF 0x80 /* Built-in typeof() function */
|
||||
#define SQLITE_FUNC_ENCMASK 0x003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
|
||||
#define SQLITE_FUNC_LIKE 0x004 /* Candidate for the LIKE optimization */
|
||||
#define SQLITE_FUNC_CASE 0x008 /* Case-sensitive LIKE-type function */
|
||||
#define SQLITE_FUNC_EPHEM 0x010 /* Ephemeral. Delete with VDBE */
|
||||
#define SQLITE_FUNC_NEEDCOLL 0x020 /* sqlite3GetFuncCollSeq() might be called */
|
||||
#define SQLITE_FUNC_LENGTH 0x040 /* Built-in length() function */
|
||||
#define SQLITE_FUNC_TYPEOF 0x080 /* Built-in typeof() function */
|
||||
#define SQLITE_FUNC_COUNT 0x100 /* Built-in count(*) aggregate */
|
||||
#define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */
|
||||
#define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */
|
||||
|
||||
/*
|
||||
** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
|
||||
@@ -1137,18 +1162,18 @@ struct FuncDestructor {
|
||||
** parameter.
|
||||
*/
|
||||
#define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
|
||||
{nArg, SQLITE_UTF8, (bNC*SQLITE_FUNC_NEEDCOLL), \
|
||||
{nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
|
||||
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
|
||||
#define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
|
||||
{nArg, SQLITE_UTF8, (bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags, \
|
||||
{nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags, \
|
||||
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
|
||||
#define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
|
||||
{nArg, SQLITE_UTF8, bNC*SQLITE_FUNC_NEEDCOLL, \
|
||||
{nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
|
||||
pArg, 0, xFunc, 0, 0, #zName, 0, 0}
|
||||
#define LIKEFUNC(zName, nArg, arg, flags) \
|
||||
{nArg, SQLITE_UTF8, flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
|
||||
{nArg, SQLITE_UTF8|flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
|
||||
#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
|
||||
{nArg, SQLITE_UTF8, nc*SQLITE_FUNC_NEEDCOLL, \
|
||||
{nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
|
||||
SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
|
||||
|
||||
/*
|
||||
@@ -1197,7 +1222,8 @@ struct Column {
|
||||
char *zColl; /* Collating sequence. If NULL, use the default */
|
||||
u8 notNull; /* An OE_ code for handling a NOT NULL constraint */
|
||||
char affinity; /* One of the SQLITE_AFF_... values */
|
||||
u16 colFlags; /* Boolean properties. See COLFLAG_ defines below */
|
||||
u8 szEst; /* Estimated size of this column. INT==1 */
|
||||
u8 colFlags; /* Boolean properties. See COLFLAG_ defines below */
|
||||
};
|
||||
|
||||
/* Allowed values for Column.colFlags:
|
||||
@@ -1356,11 +1382,12 @@ struct Table {
|
||||
#ifndef SQLITE_OMIT_CHECK
|
||||
ExprList *pCheck; /* All CHECK constraints */
|
||||
#endif
|
||||
tRowcnt nRowEst; /* Estimated rows in table - from sqlite_stat1 table */
|
||||
int tnum; /* Root BTree node for this table (see note above) */
|
||||
i16 iPKey; /* If not negative, use aCol[iPKey] as the primary key */
|
||||
i16 nCol; /* Number of columns in this table */
|
||||
u16 nRef; /* Number of pointers to this Table */
|
||||
LogEst nRowEst; /* Estimated number of rows in the table */
|
||||
LogEst szTabRow; /* Estimated size of each table row in bytes */
|
||||
u8 tabFlags; /* Mask of TF_* values */
|
||||
u8 keyConf; /* What to do in case of uniqueness conflict on iPKey */
|
||||
#ifndef SQLITE_OMIT_ALTERTABLE
|
||||
@@ -1472,7 +1499,7 @@ struct FKey {
|
||||
#define OE_SetDflt 8 /* Set the foreign key value to its default */
|
||||
#define OE_Cascade 9 /* Cascade the changes */
|
||||
|
||||
#define OE_Default 99 /* Do whatever the default action is */
|
||||
#define OE_Default 10 /* Do whatever the default action is */
|
||||
|
||||
|
||||
/*
|
||||
@@ -1550,7 +1577,7 @@ struct UnpackedRecord {
|
||||
struct Index {
|
||||
char *zName; /* Name of this index */
|
||||
int *aiColumn; /* Which columns are used by this index. 1st is 0 */
|
||||
tRowcnt *aiRowEst; /* From ANALYZE: Est. rows selected by each column */
|
||||
LogEst *aiRowEst; /* From ANALYZE: Est. rows selected by each column */
|
||||
Table *pTable; /* The SQL table being indexed */
|
||||
char *zColAff; /* String defining the affinity of each column */
|
||||
Index *pNext; /* The next index associated with the same table */
|
||||
@@ -1559,6 +1586,7 @@ struct Index {
|
||||
char **azColl; /* Array of collation sequence names for index */
|
||||
Expr *pPartIdxWhere; /* WHERE clause for partial indices */
|
||||
int tnum; /* DB Page containing root of this index */
|
||||
LogEst szIdxRow; /* Estimated average row size in bytes */
|
||||
u16 nColumn; /* Number of columns in table used by this index */
|
||||
u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
|
||||
unsigned autoIndex:2; /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */
|
||||
@@ -1567,7 +1595,7 @@ struct Index {
|
||||
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
|
||||
int nSample; /* Number of elements in aSample[] */
|
||||
int nSampleCol; /* Size of IndexSample.anEq[] and so on */
|
||||
tRowcnt *aAvgEq; /* Average nEq values for keys not in aSample */
|
||||
LogEst *aAvgEq; /* Average nEq values for keys not in aSample */
|
||||
IndexSample *aSample; /* Samples of the left-most key */
|
||||
#endif
|
||||
};
|
||||
@@ -1580,9 +1608,9 @@ struct Index {
|
||||
struct IndexSample {
|
||||
void *p; /* Pointer to sampled record */
|
||||
int n; /* Size of record in bytes */
|
||||
tRowcnt *anEq; /* Est. number of rows where the key equals this sample */
|
||||
tRowcnt *anLt; /* Est. number of rows where key is less than this sample */
|
||||
tRowcnt *anDLt; /* Est. number of distinct keys less than this sample */
|
||||
LogEst *anEq; /* Est. number of rows where the key equals this sample */
|
||||
LogEst *anLt; /* Est. number of rows where key is less than this sample */
|
||||
LogEst *anDLt; /* Est. number of distinct keys less than this sample */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -1723,7 +1751,7 @@ typedef int ynVar;
|
||||
struct Expr {
|
||||
u8 op; /* Operation performed by this node */
|
||||
char affinity; /* The affinity of the column or 0 if not a column */
|
||||
u16 flags; /* Various flags. EP_* See below */
|
||||
u32 flags; /* Various flags. EP_* See below */
|
||||
union {
|
||||
char *zToken; /* Token value. Zero terminated and dequoted */
|
||||
int iValue; /* Non-negative integer value if EP_IntValue */
|
||||
@@ -1737,8 +1765,8 @@ struct Expr {
|
||||
Expr *pLeft; /* Left subnode */
|
||||
Expr *pRight; /* Right subnode */
|
||||
union {
|
||||
ExprList *pList; /* Function arguments or in "<expr> IN (<expr-list)" */
|
||||
Select *pSelect; /* Used for sub-selects and "<expr> IN (<select>)" */
|
||||
ExprList *pList; /* op = IN, EXISTS, SELECT, CASE, FUNCTION, BETWEEN */
|
||||
Select *pSelect; /* EP_xIsSelect and op = IN, EXISTS, SELECT */
|
||||
} x;
|
||||
|
||||
/* If the EP_Reduced flag is set in the Expr.flags mask, then no
|
||||
@@ -1751,12 +1779,12 @@ struct Expr {
|
||||
#endif
|
||||
int iTable; /* TK_COLUMN: cursor number of table holding column
|
||||
** TK_REGISTER: register number
|
||||
** TK_TRIGGER: 1 -> new, 0 -> old */
|
||||
** TK_TRIGGER: 1 -> new, 0 -> old
|
||||
** EP_Unlikely: 1000 times likelihood */
|
||||
ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
|
||||
** TK_VARIABLE: variable number (always >= 1). */
|
||||
i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
|
||||
i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
|
||||
u8 flags2; /* Second set of flags. EP2_... */
|
||||
u8 op2; /* TK_REGISTER: original value of Expr.op
|
||||
** TK_COLUMN: the value of p5 for OP_Column
|
||||
** TK_AGG_FUNCTION: nesting depth */
|
||||
@@ -1767,50 +1795,45 @@ struct Expr {
|
||||
/*
|
||||
** The following are the meanings of bits in the Expr.flags field.
|
||||
*/
|
||||
#define EP_FromJoin 0x0001 /* Originated in ON or USING clause of a join */
|
||||
#define EP_Agg 0x0002 /* Contains one or more aggregate functions */
|
||||
#define EP_Resolved 0x0004 /* IDs have been resolved to COLUMNs */
|
||||
#define EP_Error 0x0008 /* Expression contains one or more errors */
|
||||
#define EP_Distinct 0x0010 /* Aggregate function with DISTINCT keyword */
|
||||
#define EP_VarSelect 0x0020 /* pSelect is correlated, not constant */
|
||||
#define EP_DblQuoted 0x0040 /* token.z was originally in "..." */
|
||||
#define EP_InfixFunc 0x0080 /* True for an infix function: LIKE, GLOB, etc */
|
||||
#define EP_Collate 0x0100 /* Tree contains a TK_COLLATE opeartor */
|
||||
#define EP_FixedDest 0x0200 /* Result needed in a specific register */
|
||||
#define EP_IntValue 0x0400 /* Integer value contained in u.iValue */
|
||||
#define EP_xIsSelect 0x0800 /* x.pSelect is valid (otherwise x.pList is) */
|
||||
#define EP_Hint 0x1000 /* Not used */
|
||||
#define EP_Reduced 0x2000 /* Expr struct is EXPR_REDUCEDSIZE bytes only */
|
||||
#define EP_TokenOnly 0x4000 /* Expr struct is EXPR_TOKENONLYSIZE bytes only */
|
||||
#define EP_Static 0x8000 /* Held in memory not obtained from malloc() */
|
||||
|
||||
/*
|
||||
** The following are the meanings of bits in the Expr.flags2 field.
|
||||
*/
|
||||
#define EP2_MallocedToken 0x0001 /* Need to sqlite3DbFree() Expr.zToken */
|
||||
#define EP2_Irreducible 0x0002 /* Cannot EXPRDUP_REDUCE this Expr */
|
||||
|
||||
/*
|
||||
** The pseudo-routine sqlite3ExprSetIrreducible sets the EP2_Irreducible
|
||||
** flag on an expression structure. This flag is used for VV&A only. The
|
||||
** routine is implemented as a macro that only works when in debugging mode,
|
||||
** so as not to burden production code.
|
||||
*/
|
||||
#ifdef SQLITE_DEBUG
|
||||
# define ExprSetIrreducible(X) (X)->flags2 |= EP2_Irreducible
|
||||
#else
|
||||
# define ExprSetIrreducible(X)
|
||||
#endif
|
||||
#define EP_FromJoin 0x000001 /* Originated in ON or USING clause of a join */
|
||||
#define EP_Agg 0x000002 /* Contains one or more aggregate functions */
|
||||
#define EP_Resolved 0x000004 /* IDs have been resolved to COLUMNs */
|
||||
#define EP_Error 0x000008 /* Expression contains one or more errors */
|
||||
#define EP_Distinct 0x000010 /* Aggregate function with DISTINCT keyword */
|
||||
#define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
|
||||
#define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
|
||||
#define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */
|
||||
#define EP_Collate 0x000100 /* Tree contains a TK_COLLATE opeartor */
|
||||
#define EP_FixedDest 0x000200 /* Result needed in a specific register */
|
||||
#define EP_IntValue 0x000400 /* Integer value contained in u.iValue */
|
||||
#define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */
|
||||
#define EP_Skip 0x001000 /* COLLATE, AS, or UNLIKELY */
|
||||
#define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
|
||||
#define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
|
||||
#define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
|
||||
#define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
|
||||
#define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
|
||||
#define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
|
||||
|
||||
/*
|
||||
** These macros can be used to test, set, or clear bits in the
|
||||
** Expr.flags field.
|
||||
*/
|
||||
#define ExprHasProperty(E,P) (((E)->flags&(P))==(P))
|
||||
#define ExprHasAnyProperty(E,P) (((E)->flags&(P))!=0)
|
||||
#define ExprHasProperty(E,P) (((E)->flags&(P))!=0)
|
||||
#define ExprHasAllProperty(E,P) (((E)->flags&(P))==(P))
|
||||
#define ExprSetProperty(E,P) (E)->flags|=(P)
|
||||
#define ExprClearProperty(E,P) (E)->flags&=~(P)
|
||||
|
||||
/* The ExprSetVVAProperty() macro is used for Verification, Validation,
|
||||
** and Accreditation only. It works like ExprSetProperty() during VVA
|
||||
** processes but is a no-op for delivery.
|
||||
*/
|
||||
#ifdef SQLITE_DEBUG
|
||||
# define ExprSetVVAProperty(E,P) (E)->flags|=(P)
|
||||
#else
|
||||
# define ExprSetVVAProperty(E,P)
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Macros to determine the number of bytes required by a normal Expr
|
||||
** struct, an Expr struct with the EP_Reduced flag set in Expr.flags
|
||||
@@ -2419,6 +2442,7 @@ typedef struct DbFixer DbFixer;
|
||||
struct DbFixer {
|
||||
Parse *pParse; /* The parsing context. Error messages written here */
|
||||
Schema *pSchema; /* Fix items to this schema */
|
||||
int bVarOnly; /* Check for variable references only */
|
||||
const char *zDb; /* Make sure all objects are contained in this database */
|
||||
const char *zType; /* Type of the container - used for error messages */
|
||||
const Token *pName; /* Name of the container - used for error messages */
|
||||
@@ -2957,7 +2981,7 @@ void sqlite3DeferForeignKey(Parse*, int);
|
||||
#endif
|
||||
void sqlite3Attach(Parse*, Expr*, Expr*, Expr*);
|
||||
void sqlite3Detach(Parse*, Expr*);
|
||||
int sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*);
|
||||
void sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*);
|
||||
int sqlite3FixSrcList(DbFixer*, SrcList*);
|
||||
int sqlite3FixSelect(DbFixer*, Select*);
|
||||
int sqlite3FixExpr(DbFixer*, Expr*);
|
||||
@@ -2969,6 +2993,12 @@ int sqlite3Atoi(const char*);
|
||||
int sqlite3Utf16ByteLen(const void *pData, int nChar);
|
||||
int sqlite3Utf8CharLen(const char *pData, int nByte);
|
||||
u32 sqlite3Utf8Read(const u8**);
|
||||
LogEst sqlite3LogEst(u64);
|
||||
LogEst sqlite3LogEstAdd(LogEst,LogEst);
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
LogEst sqlite3LogEstFromDouble(double);
|
||||
#endif
|
||||
u64 sqlite3LogEstToInt(LogEst);
|
||||
|
||||
/*
|
||||
** Routines to read and write variable-length integers. These used to
|
||||
@@ -3085,7 +3115,7 @@ void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
|
||||
void sqlite3AlterFinishAddColumn(Parse *, Token *);
|
||||
void sqlite3AlterBeginAddColumn(Parse *, SrcList *);
|
||||
CollSeq *sqlite3GetCollSeq(Parse*, u8, CollSeq *, const char*);
|
||||
char sqlite3AffinityType(const char*);
|
||||
char sqlite3AffinityType(const char*, u8*);
|
||||
void sqlite3Analyze(Parse*, Token*, Token*);
|
||||
int sqlite3InvokeBusyHandler(BusyHandler*);
|
||||
int sqlite3FindDb(sqlite3*, Token*);
|
||||
@@ -3189,6 +3219,7 @@ int sqlite3VtabCallDestroy(sqlite3*, int, const char *);
|
||||
int sqlite3VtabBegin(sqlite3 *, VTable *);
|
||||
FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
|
||||
void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
|
||||
sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
|
||||
int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
|
||||
int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
|
||||
int sqlite3Reprepare(Vdbe*);
|
||||
@@ -3209,18 +3240,18 @@ const char *sqlite3JournalModename(int);
|
||||
** provided (enforcement of FK constraints requires the triggers sub-system).
|
||||
*/
|
||||
#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
|
||||
void sqlite3FkCheck(Parse*, Table*, int, int);
|
||||
void sqlite3FkCheck(Parse*, Table*, int, int, int*, int);
|
||||
void sqlite3FkDropTable(Parse*, SrcList *, Table*);
|
||||
void sqlite3FkActions(Parse*, Table*, ExprList*, int);
|
||||
void sqlite3FkActions(Parse*, Table*, ExprList*, int, int*, int);
|
||||
int sqlite3FkRequired(Parse*, Table*, int*, int);
|
||||
u32 sqlite3FkOldmask(Parse*, Table*);
|
||||
FKey *sqlite3FkReferences(Table *);
|
||||
#else
|
||||
#define sqlite3FkActions(a,b,c,d)
|
||||
#define sqlite3FkActions(a,b,c,d,e,f)
|
||||
#define sqlite3FkCheck(a,b,c,d)
|
||||
#define sqlite3FkDropTable(a,b,c)
|
||||
#define sqlite3FkOldmask(a,b) 0
|
||||
#define sqlite3FkRequired(a,b,c,d) 0
|
||||
#define sqlite3FkOldmask(a,b) 0
|
||||
#define sqlite3FkRequired(a,b,c,d,e,f) 0
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_FOREIGN_KEY
|
||||
void sqlite3FkDelete(sqlite3 *, Table*);
|
||||
|
||||
@@ -3377,7 +3377,6 @@ static void MD5Final(unsigned char digest[16], MD5Context *ctx){
|
||||
MD5Transform(ctx->buf, (uint32 *)ctx->in);
|
||||
byteReverse((unsigned char *)ctx->buf, 4);
|
||||
memcpy(digest, ctx->buf, 16);
|
||||
memset(ctx, 0, sizeof(ctx)); /* In case it is sensitive */
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -265,6 +265,7 @@ static int getIndexArray(
|
||||
while( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){
|
||||
const char *zIdx = (const char *)sqlite3_column_text(pStmt, 1);
|
||||
sqlite3_stmt *pStmt2 = 0;
|
||||
if( zIdx==0 ) continue;
|
||||
zSql = sqlite3_mprintf("PRAGMA index_info(%s)", zIdx);
|
||||
if( !zSql ){
|
||||
rc = SQLITE_NOMEM;
|
||||
|
||||
@@ -219,7 +219,6 @@ static int init_wrapper_uninstall(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
memset(&wrapped, 0, sizeof(&wrapped));
|
||||
sqlite3_shutdown();
|
||||
sqlite3_config(SQLITE_CONFIG_MUTEX, &wrapped.mutex);
|
||||
sqlite3_config(SQLITE_CONFIG_MALLOC, &wrapped.mem);
|
||||
|
||||
+6
-4
@@ -148,8 +148,8 @@ void sqlite3BeginTrigger(
|
||||
/* Ensure the table name matches database name and that the table exists */
|
||||
if( db->mallocFailed ) goto trigger_cleanup;
|
||||
assert( pTableName->nSrc==1 );
|
||||
if( sqlite3FixInit(&sFix, pParse, iDb, "trigger", pName) &&
|
||||
sqlite3FixSrcList(&sFix, pTableName) ){
|
||||
sqlite3FixInit(&sFix, pParse, iDb, "trigger", pName);
|
||||
if( sqlite3FixSrcList(&sFix, pTableName) ){
|
||||
goto trigger_cleanup;
|
||||
}
|
||||
pTab = sqlite3SrcListLookup(pParse, pTableName);
|
||||
@@ -291,8 +291,10 @@ void sqlite3FinishTrigger(
|
||||
}
|
||||
nameToken.z = pTrig->zName;
|
||||
nameToken.n = sqlite3Strlen30(nameToken.z);
|
||||
if( sqlite3FixInit(&sFix, pParse, iDb, "trigger", &nameToken)
|
||||
&& sqlite3FixTriggerStep(&sFix, pTrig->step_list) ){
|
||||
sqlite3FixInit(&sFix, pParse, iDb, "trigger", &nameToken);
|
||||
if( sqlite3FixTriggerStep(&sFix, pTrig->step_list)
|
||||
|| sqlite3FixExpr(&sFix, pTrig->pWhen)
|
||||
){
|
||||
goto triggerfinish_cleanup;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -488,7 +488,7 @@ void sqlite3Update(
|
||||
|
||||
/* Do FK constraint checks. */
|
||||
if( hasFK ){
|
||||
sqlite3FkCheck(pParse, pTab, regOldRowid, 0);
|
||||
sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngRowid);
|
||||
}
|
||||
|
||||
/* Delete the index entries associated with the current record. */
|
||||
@@ -502,7 +502,7 @@ void sqlite3Update(
|
||||
sqlite3VdbeJumpHere(v, j1);
|
||||
|
||||
if( hasFK ){
|
||||
sqlite3FkCheck(pParse, pTab, 0, regNewRowid);
|
||||
sqlite3FkCheck(pParse, pTab, 0, regNewRowid, aXRef, chngRowid);
|
||||
}
|
||||
|
||||
/* Insert the new index entries and the new record. */
|
||||
@@ -512,7 +512,7 @@ void sqlite3Update(
|
||||
** handle rows (possibly in other tables) that refer via a foreign key
|
||||
** to the row just updated. */
|
||||
if( hasFK ){
|
||||
sqlite3FkActions(pParse, pTab, pChanges, regOldRowid);
|
||||
sqlite3FkActions(pParse, pTab, pChanges, regOldRowid, aXRef, chngRowid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+78
-1
@@ -193,7 +193,8 @@ int sqlite3Dequote(char *z){
|
||||
case '[': quote = ']'; break; /* For MS SqlServer compatibility */
|
||||
default: return -1;
|
||||
}
|
||||
for(i=1, j=0; ALWAYS(z[i]); i++){
|
||||
for(i=1, j=0;; i++){
|
||||
assert( z[i] );
|
||||
if( z[i]==quote ){
|
||||
if( z[i+1]==quote ){
|
||||
z[j++] = quote;
|
||||
@@ -1207,3 +1208,79 @@ void sqlite3FileSuffix3(const char *zBaseFilename, char *z){
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Find (an approximate) sum of two LogEst values. This computation is
|
||||
** not a simple "+" operator because LogEst is stored as a logarithmic
|
||||
** value.
|
||||
*/
|
||||
LogEst sqlite3LogEstAdd(LogEst a, LogEst b){
|
||||
static const unsigned char x[] = {
|
||||
10, 10, /* 0,1 */
|
||||
9, 9, /* 2,3 */
|
||||
8, 8, /* 4,5 */
|
||||
7, 7, 7, /* 6,7,8 */
|
||||
6, 6, 6, /* 9,10,11 */
|
||||
5, 5, 5, /* 12-14 */
|
||||
4, 4, 4, 4, /* 15-18 */
|
||||
3, 3, 3, 3, 3, 3, /* 19-24 */
|
||||
2, 2, 2, 2, 2, 2, 2, /* 25-31 */
|
||||
};
|
||||
if( a>=b ){
|
||||
if( a>b+49 ) return a;
|
||||
if( a>b+31 ) return a+1;
|
||||
return a+x[a-b];
|
||||
}else{
|
||||
if( b>a+49 ) return b;
|
||||
if( b>a+31 ) return b+1;
|
||||
return b+x[b-a];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert an integer into a LogEst. In other words, compute a
|
||||
** good approximatation for 10*log2(x).
|
||||
*/
|
||||
LogEst sqlite3LogEst(u64 x){
|
||||
static LogEst a[] = { 0, 2, 3, 5, 6, 7, 8, 9 };
|
||||
LogEst y = 40;
|
||||
if( x<8 ){
|
||||
if( x<2 ) return 0;
|
||||
while( x<8 ){ y -= 10; x <<= 1; }
|
||||
}else{
|
||||
while( x>255 ){ y += 40; x >>= 4; }
|
||||
while( x>15 ){ y += 10; x >>= 1; }
|
||||
}
|
||||
return a[x&7] + y - 10;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
/*
|
||||
** Convert a double into a LogEst
|
||||
** In other words, compute an approximation for 10*log2(x).
|
||||
*/
|
||||
LogEst sqlite3LogEstFromDouble(double x){
|
||||
u64 a;
|
||||
LogEst e;
|
||||
assert( sizeof(x)==8 && sizeof(a)==8 );
|
||||
if( x<=1 ) return 0;
|
||||
if( x<=2000000000 ) return sqlite3LogEst((u64)x);
|
||||
memcpy(&a, &x, 8);
|
||||
e = (a>>52) - 1022;
|
||||
return e*10;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_VIRTUALTABLE */
|
||||
|
||||
/*
|
||||
** Convert a LogEst into an integer.
|
||||
*/
|
||||
u64 sqlite3LogEstToInt(LogEst x){
|
||||
u64 n;
|
||||
if( x<10 ) return 1;
|
||||
n = x%10;
|
||||
x /= 10;
|
||||
if( n>=5 ) n -= 2;
|
||||
else if( n>=1 ) n -= 1;
|
||||
if( x>=3 ) return (n+8)<<(x-3);
|
||||
return (n+8)>>(3-x);
|
||||
}
|
||||
|
||||
+26
-6
@@ -72,14 +72,34 @@ static int execExecSql(sqlite3 *db, char **pzErrMsg, const char *zSql){
|
||||
}
|
||||
|
||||
/*
|
||||
** The non-standard VACUUM command is used to clean up the database,
|
||||
** The VACUUM command is used to clean up the database,
|
||||
** collapse free space, etc. It is modelled after the VACUUM command
|
||||
** in PostgreSQL.
|
||||
** in PostgreSQL. The VACUUM command works as follows:
|
||||
**
|
||||
** In version 1.0.x of SQLite, the VACUUM command would call
|
||||
** gdbm_reorganize() on all the database tables. But beginning
|
||||
** with 2.0.0, SQLite no longer uses GDBM so this command has
|
||||
** become a no-op.
|
||||
** (1) Create a new transient database file
|
||||
** (2) Copy all content from the database being vacuumed into
|
||||
** the new transient database file
|
||||
** (3) Copy content from the transient database back into the
|
||||
** original database.
|
||||
**
|
||||
** The transient database requires temporary disk space approximately
|
||||
** equal to the size of the original database. The copy operation of
|
||||
** step (3) requires additional temporary disk space approximately equal
|
||||
** to the size of the original database for the rollback journal.
|
||||
** Hence, temporary disk space that is approximately 2x the size of the
|
||||
** orginal database is required. Every page of the database is written
|
||||
** approximately 3 times: Once for step (2) and twice for step (3).
|
||||
** Two writes per page are required in step (3) because the original
|
||||
** database content must be written into the rollback journal prior to
|
||||
** overwriting the database with the vacuumed content.
|
||||
**
|
||||
** Only 1x temporary space and only 1x writes would be required if
|
||||
** the copy of step (3) were replace by deleting the original database
|
||||
** and renaming the transient database as the original. But that will
|
||||
** not work if other processes are attached to the original database.
|
||||
** And a power loss in between deleting the original and renaming the
|
||||
** transient would cause the database file to appear to be deleted
|
||||
** following reboot.
|
||||
*/
|
||||
void sqlite3Vacuum(Parse *pParse){
|
||||
Vdbe *v = sqlite3GetVdbe(pParse);
|
||||
|
||||
+3
-2
@@ -567,6 +567,7 @@ int sqlite3VdbeExec(
|
||||
assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY );
|
||||
assert( p->bIsReader || p->readOnly!=0 );
|
||||
p->rc = SQLITE_OK;
|
||||
p->iCurrentTime = 0;
|
||||
assert( p->explain==0 );
|
||||
p->pResultSet = 0;
|
||||
db->busyHandler.nBusy = 0;
|
||||
@@ -1437,7 +1438,7 @@ case OP_Function: {
|
||||
MemSetTypeFlag(&ctx.s, MEM_Null);
|
||||
|
||||
ctx.fErrorOrAux = 0;
|
||||
if( ctx.pFunc->flags & SQLITE_FUNC_NEEDCOLL ){
|
||||
if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
|
||||
assert( pOp>aOp );
|
||||
assert( pOp[-1].p4type==P4_COLLSEQ );
|
||||
assert( pOp[-1].opcode==OP_CollSeq );
|
||||
@@ -5437,7 +5438,7 @@ case OP_AggStep: {
|
||||
ctx.isError = 0;
|
||||
ctx.pColl = 0;
|
||||
ctx.skipFlag = 0;
|
||||
if( ctx.pFunc->flags & SQLITE_FUNC_NEEDCOLL ){
|
||||
if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
|
||||
assert( pOp>p->aOp );
|
||||
assert( pOp[-1].p4type==P4_COLLSEQ );
|
||||
assert( pOp[-1].opcode==OP_CollSeq );
|
||||
|
||||
@@ -350,6 +350,7 @@ struct Vdbe {
|
||||
#ifndef SQLITE_OMIT_TRACE
|
||||
i64 startTime; /* Time when query started - used for profiling */
|
||||
#endif
|
||||
i64 iCurrentTime; /* Value of julianday('now') for this statement */
|
||||
i64 nFkConstraint; /* Number of imm. FK constraints this VM */
|
||||
i64 nStmtDefCons; /* Number of def. constraints when stmt started */
|
||||
i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
|
||||
|
||||
@@ -510,6 +510,7 @@ int sqlite3_step(sqlite3_stmt *pStmt){
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Extract the user data from a sqlite3_context structure and return a
|
||||
** pointer to it.
|
||||
@@ -534,6 +535,19 @@ sqlite3 *sqlite3_context_db_handle(sqlite3_context *p){
|
||||
return p->s.db;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the current time for a statement
|
||||
*/
|
||||
sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context *p){
|
||||
Vdbe *v = p->pVdbe;
|
||||
int rc;
|
||||
if( v->iCurrentTime==0 ){
|
||||
rc = sqlite3OsCurrentTimeInt64(p->s.db->pVfs, &v->iCurrentTime);
|
||||
if( rc ) v->iCurrentTime = 0;
|
||||
}
|
||||
return v->iCurrentTime;
|
||||
}
|
||||
|
||||
/*
|
||||
** The following is the implementation of an SQL function that always
|
||||
** fails with an error message stating that the function is used in the
|
||||
|
||||
+2
-1
@@ -604,7 +604,7 @@ void sqlite3VdbeJumpHere(Vdbe *p, int addr){
|
||||
** the FuncDef is not ephermal, then do nothing.
|
||||
*/
|
||||
static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
|
||||
if( ALWAYS(pDef) && (pDef->flags & SQLITE_FUNC_EPHEM)!=0 ){
|
||||
if( ALWAYS(pDef) && (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
|
||||
sqlite3DbFree(db, pDef);
|
||||
}
|
||||
}
|
||||
@@ -2436,6 +2436,7 @@ int sqlite3VdbeReset(Vdbe *p){
|
||||
}
|
||||
}
|
||||
#endif
|
||||
p->iCurrentTime = 0;
|
||||
p->magic = VDBE_MAGIC_INIT;
|
||||
return p->rc & db->errMask;
|
||||
}
|
||||
|
||||
+9
-5
@@ -1304,6 +1304,8 @@ int sqlite3Stat4ProbeSetValue(
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
sqlite3_value *pVal = 0;
|
||||
sqlite3 *db = pParse->db;
|
||||
|
||||
|
||||
struct ValueNewStat4Ctx alloc;
|
||||
alloc.pParse = pParse;
|
||||
@@ -1311,8 +1313,11 @@ int sqlite3Stat4ProbeSetValue(
|
||||
alloc.ppRec = ppRec;
|
||||
alloc.iVal = iVal;
|
||||
|
||||
/* Skip over any TK_COLLATE nodes */
|
||||
pExpr = sqlite3ExprSkipCollate(pExpr);
|
||||
|
||||
if( !pExpr ){
|
||||
pVal = valueNew(pParse->db, &alloc);
|
||||
pVal = valueNew(db, &alloc);
|
||||
if( pVal ){
|
||||
sqlite3VdbeMemSetNull((Mem*)pVal);
|
||||
*pbOk = 1;
|
||||
@@ -1324,11 +1329,11 @@ int sqlite3Stat4ProbeSetValue(
|
||||
int iBindVar = pExpr->iColumn;
|
||||
sqlite3VdbeSetVarmask(pParse->pVdbe, iBindVar);
|
||||
if( (v = pParse->pReprepare)!=0 ){
|
||||
pVal = valueNew(pParse->db, &alloc);
|
||||
pVal = valueNew(db, &alloc);
|
||||
if( pVal ){
|
||||
rc = sqlite3VdbeMemCopy((Mem*)pVal, &v->aVar[iBindVar-1]);
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8);
|
||||
sqlite3ValueApplyAffinity(pVal, affinity, ENC(db));
|
||||
}
|
||||
pVal->db = pParse->db;
|
||||
*pbOk = 1;
|
||||
@@ -1338,12 +1343,11 @@ int sqlite3Stat4ProbeSetValue(
|
||||
*pbOk = 0;
|
||||
}
|
||||
}else{
|
||||
sqlite3 *db = pParse->db;
|
||||
rc = valueFromExpr(db, pExpr, ENC(db), affinity, &pVal, &alloc);
|
||||
*pbOk = (pVal!=0);
|
||||
}
|
||||
|
||||
assert( pVal==0 || pVal->db==pParse->db );
|
||||
assert( pVal==0 || pVal->db==db );
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1013,7 +1013,7 @@ FuncDef *sqlite3VtabOverloadFunction(
|
||||
memcpy(pNew->zName, pDef->zName, sqlite3Strlen30(pDef->zName)+1);
|
||||
pNew->xFunc = xFunc;
|
||||
pNew->pUserData = pArg;
|
||||
pNew->flags |= SQLITE_FUNC_EPHEM;
|
||||
pNew->funcFlags |= SQLITE_FUNC_EPHEM;
|
||||
return pNew;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ int sqlite3WalkExpr(Walker *pWalker, Expr *pExpr){
|
||||
testcase( ExprHasProperty(pExpr, EP_Reduced) );
|
||||
rc = pWalker->xExprCallback(pWalker, pExpr);
|
||||
if( rc==WRC_Continue
|
||||
&& !ExprHasAnyProperty(pExpr,EP_TokenOnly) ){
|
||||
&& !ExprHasProperty(pExpr,EP_TokenOnly) ){
|
||||
if( sqlite3WalkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
|
||||
if( sqlite3WalkExpr(pWalker, pExpr->pRight) ) return WRC_Abort;
|
||||
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
|
||||
|
||||
+208
-241
@@ -48,25 +48,6 @@ typedef struct WhereScan WhereScan;
|
||||
typedef struct WhereOrCost WhereOrCost;
|
||||
typedef struct WhereOrSet WhereOrSet;
|
||||
|
||||
/*
|
||||
** Cost X is tracked as 10*log2(X) stored in a 16-bit integer. The
|
||||
** maximum cost for ordinary tables is 64*(2**63) which becomes 6900.
|
||||
** (Virtual tables can return a larger cost, but let's assume they do not.)
|
||||
** So all costs can be stored in a 16-bit unsigned integer without risk
|
||||
** of overflow.
|
||||
**
|
||||
** Costs are estimates, so no effort is made to compute 10*log2(X) exactly.
|
||||
** Instead, a close estimate is used. Any value of X<=1 is stored as 0.
|
||||
** X=2 is 10. X=3 is 16. X=1000 is 99. etc.
|
||||
**
|
||||
** The tool/wherecosttest.c source file implements a command-line program
|
||||
** that will convert WhereCosts to integers, convert integers to WhereCosts
|
||||
** and do addition and multiplication on WhereCost values. The wherecosttest
|
||||
** command-line program is a useful utility to have around when working with
|
||||
** this module.
|
||||
*/
|
||||
typedef unsigned short int WhereCost;
|
||||
|
||||
/*
|
||||
** This object contains information needed to implement a single nested
|
||||
** loop in WHERE clause.
|
||||
@@ -106,6 +87,7 @@ struct WhereLevel {
|
||||
Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */
|
||||
} u;
|
||||
struct WhereLoop *pWLoop; /* The selected WhereLoop object */
|
||||
Bitmask notReady; /* FROM entries not usable at this level */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -130,9 +112,9 @@ struct WhereLoop {
|
||||
#endif
|
||||
u8 iTab; /* Position in FROM clause of table for this loop */
|
||||
u8 iSortIdx; /* Sorting index number. 0==None */
|
||||
WhereCost rSetup; /* One-time setup cost (ex: create transient index) */
|
||||
WhereCost rRun; /* Cost of running each loop */
|
||||
WhereCost nOut; /* Estimated number of output rows */
|
||||
LogEst rSetup; /* One-time setup cost (ex: create transient index) */
|
||||
LogEst rRun; /* Cost of running each loop */
|
||||
LogEst nOut; /* Estimated number of output rows */
|
||||
union {
|
||||
struct { /* Information for internal btree tables */
|
||||
int nEq; /* Number of equality constraints */
|
||||
@@ -162,8 +144,8 @@ struct WhereLoop {
|
||||
*/
|
||||
struct WhereOrCost {
|
||||
Bitmask prereq; /* Prerequisites */
|
||||
WhereCost rRun; /* Cost of running this subquery */
|
||||
WhereCost nOut; /* Number of outputs for this subquery */
|
||||
LogEst rRun; /* Cost of running this subquery */
|
||||
LogEst nOut; /* Number of outputs for this subquery */
|
||||
};
|
||||
|
||||
/* The WhereOrSet object holds a set of possible WhereOrCosts that
|
||||
@@ -201,8 +183,8 @@ static int whereLoopResize(sqlite3*, WhereLoop*, int);
|
||||
struct WherePath {
|
||||
Bitmask maskLoop; /* Bitmask of all WhereLoop objects in this path */
|
||||
Bitmask revLoop; /* aLoop[]s that should be reversed for ORDER BY */
|
||||
WhereCost nRow; /* Estimated number of rows generated by this path */
|
||||
WhereCost rCost; /* Total cost of this path */
|
||||
LogEst nRow; /* Estimated number of rows generated by this path */
|
||||
LogEst rCost; /* Total cost of this path */
|
||||
u8 isOrdered; /* True if this path satisfies ORDER BY */
|
||||
u8 isOrderedValid; /* True if the isOrdered field is valid */
|
||||
WhereLoop **aLoop; /* Array of WhereLoop objects implementing this path */
|
||||
@@ -268,6 +250,7 @@ struct WhereTerm {
|
||||
WhereOrInfo *pOrInfo; /* Extra information if (eOperator & WO_OR)!=0 */
|
||||
WhereAndInfo *pAndInfo; /* Extra information if (eOperator& WO_AND)!=0 */
|
||||
} u;
|
||||
LogEst truthProb; /* Probability of truth for this expression */
|
||||
u16 eOperator; /* A WO_xx value describing <op> */
|
||||
u8 wtFlags; /* TERM_xxx bit flags. See below */
|
||||
u8 nChild; /* Number of children that must disable us */
|
||||
@@ -415,7 +398,7 @@ struct WhereInfo {
|
||||
ExprList *pResultSet; /* Result set. DISTINCT operates on these */
|
||||
WhereLoop *pLoops; /* List of all WhereLoop objects */
|
||||
Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
|
||||
WhereCost nRowOut; /* Estimated number of output rows */
|
||||
LogEst nRowOut; /* Estimated number of output rows */
|
||||
u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
|
||||
u8 bOBSat; /* ORDER BY satisfied by indices */
|
||||
u8 okOnePass; /* Ok to use one-pass algorithm for UPDATE/DELETE */
|
||||
@@ -475,26 +458,11 @@ struct WhereInfo {
|
||||
#define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
|
||||
#define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
|
||||
|
||||
|
||||
/* Convert a WhereCost value (10 times log2(X)) into its integer value X.
|
||||
** A rough approximation is used. The value returned is not exact.
|
||||
*/
|
||||
static u64 whereCostToInt(WhereCost x){
|
||||
u64 n;
|
||||
if( x<10 ) return 1;
|
||||
n = x%10;
|
||||
x /= 10;
|
||||
if( n>=5 ) n -= 2;
|
||||
else if( n>=1 ) n -= 1;
|
||||
if( x>=3 ) return (n+8)<<(x-3);
|
||||
return (n+8)>>(3-x);
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the estimated number of output rows from a WHERE clause
|
||||
*/
|
||||
u64 sqlite3WhereOutputRowCount(WhereInfo *pWInfo){
|
||||
return whereCostToInt(pWInfo->nRowOut);
|
||||
return sqlite3LogEstToInt(pWInfo->nRowOut);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -556,8 +524,8 @@ static void whereOrMove(WhereOrSet *pDest, WhereOrSet *pSrc){
|
||||
static int whereOrInsert(
|
||||
WhereOrSet *pSet, /* The WhereOrSet to be updated */
|
||||
Bitmask prereq, /* Prerequisites of the new entry */
|
||||
WhereCost rRun, /* Run-cost of the new entry */
|
||||
WhereCost nOut /* Number of outputs for the new entry */
|
||||
LogEst rRun, /* Run-cost of the new entry */
|
||||
LogEst nOut /* Number of outputs for the new entry */
|
||||
){
|
||||
u16 i;
|
||||
WhereOrCost *p;
|
||||
@@ -683,6 +651,11 @@ static int whereClauseInsert(WhereClause *pWC, Expr *p, u8 wtFlags){
|
||||
pWC->nSlot = sqlite3DbMallocSize(db, pWC->a)/sizeof(pWC->a[0]);
|
||||
}
|
||||
pTerm = &pWC->a[idx = pWC->nTerm++];
|
||||
if( p && ExprHasProperty(p, EP_Unlikely) ){
|
||||
pTerm->truthProb = sqlite3LogEst(p->iTable) - 99;
|
||||
}else{
|
||||
pTerm->truthProb = -1;
|
||||
}
|
||||
pTerm->pExpr = sqlite3ExprSkipCollate(p);
|
||||
pTerm->wtFlags = wtFlags;
|
||||
pTerm->pWC = pWC;
|
||||
@@ -1943,75 +1916,12 @@ static int isDistinctRedundant(
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Find (an approximate) sum of two WhereCosts. This computation is
|
||||
** not a simple "+" operator because WhereCost is stored as a logarithmic
|
||||
** value.
|
||||
**
|
||||
*/
|
||||
static WhereCost whereCostAdd(WhereCost a, WhereCost b){
|
||||
static const unsigned char x[] = {
|
||||
10, 10, /* 0,1 */
|
||||
9, 9, /* 2,3 */
|
||||
8, 8, /* 4,5 */
|
||||
7, 7, 7, /* 6,7,8 */
|
||||
6, 6, 6, /* 9,10,11 */
|
||||
5, 5, 5, /* 12-14 */
|
||||
4, 4, 4, 4, /* 15-18 */
|
||||
3, 3, 3, 3, 3, 3, /* 19-24 */
|
||||
2, 2, 2, 2, 2, 2, 2, /* 25-31 */
|
||||
};
|
||||
if( a>=b ){
|
||||
if( a>b+49 ) return a;
|
||||
if( a>b+31 ) return a+1;
|
||||
return a+x[a-b];
|
||||
}else{
|
||||
if( b>a+49 ) return b;
|
||||
if( b>a+31 ) return b+1;
|
||||
return b+x[b-a];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert an integer into a WhereCost. In other words, compute a
|
||||
** good approximatation for 10*log2(x).
|
||||
*/
|
||||
static WhereCost whereCost(tRowcnt x){
|
||||
static WhereCost a[] = { 0, 2, 3, 5, 6, 7, 8, 9 };
|
||||
WhereCost y = 40;
|
||||
if( x<8 ){
|
||||
if( x<2 ) return 0;
|
||||
while( x<8 ){ y -= 10; x <<= 1; }
|
||||
}else{
|
||||
while( x>255 ){ y += 40; x >>= 4; }
|
||||
while( x>15 ){ y += 10; x >>= 1; }
|
||||
}
|
||||
return a[x&7] + y - 10;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
/*
|
||||
** Convert a double (as received from xBestIndex of a virtual table)
|
||||
** into a WhereCost. In other words, compute an approximation for
|
||||
** 10*log2(x).
|
||||
*/
|
||||
static WhereCost whereCostFromDouble(double x){
|
||||
u64 a;
|
||||
WhereCost e;
|
||||
assert( sizeof(x)==8 && sizeof(a)==8 );
|
||||
if( x<=1 ) return 0;
|
||||
if( x<=2000000000 ) return whereCost((tRowcnt)x);
|
||||
memcpy(&a, &x, 8);
|
||||
e = (a>>52) - 1022;
|
||||
return e*10;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_VIRTUALTABLE */
|
||||
|
||||
/*
|
||||
** Estimate the logarithm of the input value to base 2.
|
||||
*/
|
||||
static WhereCost estLog(WhereCost N){
|
||||
WhereCost x = whereCost(N);
|
||||
static LogEst estLog(LogEst N){
|
||||
LogEst x = sqlite3LogEst(N);
|
||||
return x>33 ? x - 33 : 0;
|
||||
}
|
||||
|
||||
@@ -2418,15 +2328,18 @@ static void whereKeyStats(
|
||||
Index *pIdx, /* Index to consider domain of */
|
||||
UnpackedRecord *pRec, /* Vector of values to consider */
|
||||
int roundUp, /* Round up if true. Round down if false */
|
||||
tRowcnt *aStat /* OUT: stats written here */
|
||||
LogEst *aStat /* OUT: stats written here */
|
||||
){
|
||||
IndexSample *aSample = pIdx->aSample;
|
||||
int iCol = pRec->nField-1; /* Index of required stats in anEq[] etc. */
|
||||
int iCol; /* Index of required stats in anEq[] etc. */
|
||||
int iMin = 0; /* Smallest sample not yet tested */
|
||||
int i = pIdx->nSample; /* Smallest sample larger than or equal to pRec */
|
||||
int iTest; /* Next sample to test */
|
||||
int res; /* Result of comparison operation */
|
||||
|
||||
assert( pRec!=0 || pParse->db->mallocFailed );
|
||||
if( pRec==0 ) return;
|
||||
iCol = pRec->nField - 1;
|
||||
assert( pIdx->nSample>0 );
|
||||
assert( pRec->nField>0 && iCol<pIdx->nSampleCol );
|
||||
do{
|
||||
@@ -2468,15 +2381,16 @@ static void whereKeyStats(
|
||||
aStat[0] = aSample[i].anLt[iCol];
|
||||
aStat[1] = aSample[i].anEq[iCol];
|
||||
}else{
|
||||
tRowcnt iLower, iUpper, iGap;
|
||||
LogEst iLower, iUpper, iGap;
|
||||
if( i==0 ){
|
||||
iLower = 0;
|
||||
iUpper = aSample[0].anLt[iCol];
|
||||
}else{
|
||||
iUpper = i>=pIdx->nSample ? pIdx->aiRowEst[0] : aSample[i].anLt[iCol];
|
||||
iLower = aSample[i-1].anEq[iCol] + aSample[i-1].anLt[iCol];
|
||||
iLower = sqlite3LogEstAdd(aSample[i-1].anEq[iCol],
|
||||
aSample[i-1].anLt[iCol]);
|
||||
}
|
||||
aStat[1] = (pIdx->nColumn>iCol ? pIdx->aAvgEq[iCol] : 1);
|
||||
aStat[1] = (pIdx->nColumn>iCol ? pIdx->aAvgEq[iCol] : 0);
|
||||
if( iLower>=iUpper ){
|
||||
iGap = 0;
|
||||
}else{
|
||||
@@ -2521,7 +2435,7 @@ static void whereKeyStats(
|
||||
**
|
||||
** then nEq is set to 0.
|
||||
**
|
||||
** When this function is called, *pnOut is set to the whereCost() of the
|
||||
** When this function is called, *pnOut is set to the sqlite3LogEst() of the
|
||||
** number of rows that the index scan is expected to visit without
|
||||
** considering the range constraints. If nEq is 0, this is the number of
|
||||
** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced)
|
||||
@@ -2537,23 +2451,24 @@ static int whereRangeScanEst(
|
||||
WhereLoopBuilder *pBuilder,
|
||||
WhereTerm *pLower, /* Lower bound on the range. ex: "x>123" Might be NULL */
|
||||
WhereTerm *pUpper, /* Upper bound on the range. ex: "x<455" Might be NULL */
|
||||
WhereCost *pnOut /* IN/OUT: Number of rows visited */
|
||||
LogEst *pnOut /* IN/OUT: Number of rows visited */
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
int nOut = (int)*pnOut;
|
||||
LogEst nNew;
|
||||
|
||||
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
|
||||
Index *p = pBuilder->pNew->u.btree.pIndex;
|
||||
int nEq = pBuilder->pNew->u.btree.nEq;
|
||||
|
||||
if( nEq==pBuilder->nRecValid
|
||||
if( p->nSample>0
|
||||
&& nEq==pBuilder->nRecValid
|
||||
&& nEq<p->nSampleCol
|
||||
&& p->nSample
|
||||
&& OptimizationEnabled(pParse->db, SQLITE_Stat3)
|
||||
){
|
||||
UnpackedRecord *pRec = pBuilder->pRec;
|
||||
tRowcnt a[2];
|
||||
u8 aff = p->pTable->aCol[p->aiColumn[0]].affinity;
|
||||
LogEst a[2];
|
||||
u8 aff;
|
||||
|
||||
/* Variable iLower will be set to the estimate of the number of rows in
|
||||
** the index that are less than the lower bound of the range query. The
|
||||
@@ -2572,9 +2487,14 @@ static int whereRangeScanEst(
|
||||
** is either ($P) or ($P:$U). Again, even if $U is available, both values
|
||||
** of iUpper are requested of whereKeyStats() and the smaller used.
|
||||
*/
|
||||
tRowcnt iLower;
|
||||
tRowcnt iUpper;
|
||||
LogEst iLower;
|
||||
LogEst iUpper;
|
||||
|
||||
if( nEq==p->nColumn ){
|
||||
aff = SQLITE_AFF_INTEGER;
|
||||
}else{
|
||||
aff = p->pTable->aCol[p->aiColumn[nEq]].affinity;
|
||||
}
|
||||
/* Determine iLower and iUpper using ($P) only. */
|
||||
if( nEq==0 ){
|
||||
iLower = 0;
|
||||
@@ -2584,7 +2504,7 @@ static int whereRangeScanEst(
|
||||
** have been requested when testing key $P in whereEqualScanEst(). */
|
||||
whereKeyStats(pParse, p, pRec, 0, a);
|
||||
iLower = a[0];
|
||||
iUpper = a[0] + a[1];
|
||||
iUpper = sqlite3LogEstAdd(a[0],a[1]);
|
||||
}
|
||||
|
||||
/* If possible, improve on the iLower estimate using ($P:$L). */
|
||||
@@ -2594,10 +2514,11 @@ static int whereRangeScanEst(
|
||||
assert( (pLower->eOperator & (WO_GT|WO_GE))!=0 );
|
||||
rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
|
||||
if( rc==SQLITE_OK && bOk ){
|
||||
tRowcnt iNew;
|
||||
LogEst iNew;
|
||||
whereKeyStats(pParse, p, pRec, 0, a);
|
||||
iNew = a[0] + ((pLower->eOperator & WO_GT) ? a[1] : 0);
|
||||
iNew = sqlite3LogEstAdd(a[0],((pLower->eOperator & WO_GT) ? a[1] : 0));
|
||||
if( iNew>iLower ) iLower = iNew;
|
||||
nOut--;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2608,27 +2529,27 @@ static int whereRangeScanEst(
|
||||
assert( (pUpper->eOperator & (WO_LT|WO_LE))!=0 );
|
||||
rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, aff, nEq, &bOk);
|
||||
if( rc==SQLITE_OK && bOk ){
|
||||
tRowcnt iNew;
|
||||
LogEst iNew;
|
||||
whereKeyStats(pParse, p, pRec, 1, a);
|
||||
iNew = a[0] + ((pUpper->eOperator & WO_LE) ? a[1] : 0);
|
||||
iNew = sqlite3LogEstAdd(a[0],((pUpper->eOperator & WO_LE) ? a[1] : 0));
|
||||
if( iNew<iUpper ) iUpper = iNew;
|
||||
nOut--;
|
||||
}
|
||||
}
|
||||
|
||||
pBuilder->pRec = pRec;
|
||||
if( rc==SQLITE_OK ){
|
||||
WhereCost nNew;
|
||||
if( iUpper>iLower ){
|
||||
nNew = whereCost(iUpper - iLower);
|
||||
}else{
|
||||
nNew = 10; assert( 10==whereCost(2) );
|
||||
}
|
||||
if( iUpper<=iLower ) iUpper = iLower+1;
|
||||
nNew = sqlite3LogEst(sqlite3LogEstToInt(iUpper)
|
||||
- sqlite3LogEstToInt(iLower));
|
||||
if( nNew<nOut ){
|
||||
nOut = nNew;
|
||||
}
|
||||
*pnOut = (WhereCost)nOut;
|
||||
WHERETRACE(0x100, ("range scan regions: %u..%u est=%d\n",
|
||||
(u32)iLower, (u32)iUpper, nOut));
|
||||
*pnOut = (LogEst)nOut;
|
||||
WHERETRACE(0x100, ("range scan regions: %llu..%llu est=%d\n",
|
||||
sqlite3LogEstToInt(iLower),
|
||||
sqlite3LogEstToInt(iUpper),
|
||||
nOut));
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
@@ -2639,14 +2560,18 @@ static int whereRangeScanEst(
|
||||
assert( pLower || pUpper );
|
||||
/* TUNING: Each inequality constraint reduces the search space 4-fold.
|
||||
** A BETWEEN operator, therefore, reduces the search space 16-fold */
|
||||
nNew = nOut;
|
||||
if( pLower && (pLower->wtFlags & TERM_VNULL)==0 ){
|
||||
nOut -= 20; assert( 20==whereCost(4) );
|
||||
nNew -= 20; assert( 20==sqlite3LogEst(4) );
|
||||
nOut--;
|
||||
}
|
||||
if( pUpper ){
|
||||
nOut -= 20; assert( 20==whereCost(4) );
|
||||
nNew -= 20; assert( 20==sqlite3LogEst(4) );
|
||||
nOut--;
|
||||
}
|
||||
if( nOut<10 ) nOut = 10;
|
||||
*pnOut = (WhereCost)nOut;
|
||||
if( nNew<10 ) nNew = 10;
|
||||
if( nNew<nOut ) nOut = nNew;
|
||||
*pnOut = (LogEst)nOut;
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2672,14 +2597,14 @@ static int whereEqualScanEst(
|
||||
Parse *pParse, /* Parsing & code generating context */
|
||||
WhereLoopBuilder *pBuilder,
|
||||
Expr *pExpr, /* Expression for VALUE in the x=VALUE constraint */
|
||||
tRowcnt *pnRow /* Write the revised row estimate here */
|
||||
LogEst *pnRow /* Write the revised row estimate here */
|
||||
){
|
||||
Index *p = pBuilder->pNew->u.btree.pIndex;
|
||||
int nEq = pBuilder->pNew->u.btree.nEq;
|
||||
UnpackedRecord *pRec = pBuilder->pRec;
|
||||
u8 aff; /* Column affinity */
|
||||
int rc; /* Subfunction return code */
|
||||
tRowcnt a[2]; /* Statistics */
|
||||
LogEst a[2]; /* Statistics */
|
||||
int bOk;
|
||||
|
||||
assert( nEq>=1 );
|
||||
@@ -2709,7 +2634,8 @@ static int whereEqualScanEst(
|
||||
pBuilder->nRecValid = nEq;
|
||||
|
||||
whereKeyStats(pParse, p, pRec, 0, a);
|
||||
WHERETRACE(0x100,("equality scan regions: %d\n", (int)a[1]));
|
||||
WHERETRACE(0x100,("equality scan regions: %d (%llu)\n", a[1],
|
||||
sqlite3LogEstToInt(a[1])));
|
||||
*pnRow = a[1];
|
||||
|
||||
return rc;
|
||||
@@ -2737,27 +2663,28 @@ static int whereInScanEst(
|
||||
Parse *pParse, /* Parsing & code generating context */
|
||||
WhereLoopBuilder *pBuilder,
|
||||
ExprList *pList, /* The value list on the RHS of "x IN (v1,v2,v3,...)" */
|
||||
tRowcnt *pnRow /* Write the revised row estimate here */
|
||||
LogEst *pnRow /* Write the revised row estimate here */
|
||||
){
|
||||
Index *p = pBuilder->pNew->u.btree.pIndex;
|
||||
int nRecValid = pBuilder->nRecValid;
|
||||
int rc = SQLITE_OK; /* Subfunction return code */
|
||||
tRowcnt nEst; /* Number of rows for a single term */
|
||||
tRowcnt nRowEst = 0; /* New estimate of the number of rows */
|
||||
LogEst nEst; /* Number of rows for a single term */
|
||||
u64 nRowEst = 0; /* New estimate of the number of rows */
|
||||
int i; /* Loop counter */
|
||||
|
||||
assert( p->aSample!=0 );
|
||||
for(i=0; rc==SQLITE_OK && i<pList->nExpr; i++){
|
||||
nEst = p->aiRowEst[0];
|
||||
rc = whereEqualScanEst(pParse, pBuilder, pList->a[i].pExpr, &nEst);
|
||||
nRowEst += nEst;
|
||||
nRowEst += sqlite3LogEstToInt(nEst);
|
||||
pBuilder->nRecValid = nRecValid;
|
||||
}
|
||||
|
||||
if( rc==SQLITE_OK ){
|
||||
if( nRowEst > p->aiRowEst[0] ) nRowEst = p->aiRowEst[0];
|
||||
*pnRow = nRowEst;
|
||||
WHERETRACE(0x100,("IN row estimate: est=%g\n", nRowEst));
|
||||
nEst = sqlite3LogEst(nRowEst);
|
||||
if( nEst > p->aiRowEst[0] ) nEst = p->aiRowEst[0];
|
||||
*pnRow = nEst;
|
||||
WHERETRACE(0x100,("IN row estimate: est=%d (%llu)\n", nEst, nRowEst));
|
||||
}
|
||||
assert( pBuilder->nRecValid==nRecValid );
|
||||
return rc;
|
||||
@@ -2791,6 +2718,7 @@ static void disableTerm(WhereLevel *pLevel, WhereTerm *pTerm){
|
||||
if( pTerm
|
||||
&& (pTerm->wtFlags & TERM_CODED)==0
|
||||
&& (pLevel->iLeftJoin==0 || ExprHasProperty(pTerm->pExpr, EP_FromJoin))
|
||||
&& (pLevel->notReady & pTerm->prereqAll)==0
|
||||
){
|
||||
pTerm->wtFlags |= TERM_CODED;
|
||||
if( pTerm->iParent>=0 ){
|
||||
@@ -3216,7 +3144,6 @@ static Bitmask codeOneLoopStart(
|
||||
int addrCont; /* Jump here to continue with next cycle */
|
||||
int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
|
||||
int iReleaseReg = 0; /* Temp register to free before returning */
|
||||
Bitmask newNotReady; /* Return value */
|
||||
|
||||
pParse = pWInfo->pParse;
|
||||
v = pParse->pVdbe;
|
||||
@@ -3226,6 +3153,7 @@ static Bitmask codeOneLoopStart(
|
||||
pLoop = pLevel->pWLoop;
|
||||
pTabItem = &pWInfo->pTabList->a[pLevel->iFrom];
|
||||
iCur = pTabItem->iCursor;
|
||||
pLevel->notReady = notReady & ~getMask(&pWInfo->sMaskSet, iCur);
|
||||
bRev = (pWInfo->revMask>>iLevel)&1;
|
||||
omitTable = (pLoop->wsFlags & WHERE_IDX_ONLY)!=0
|
||||
&& (pWInfo->wctrlFlags & WHERE_FORCE_TABLE)==0;
|
||||
@@ -3878,7 +3806,6 @@ static Bitmask codeOneLoopStart(
|
||||
pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
|
||||
pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
|
||||
}
|
||||
newNotReady = notReady & ~getMask(&pWInfo->sMaskSet, iCur);
|
||||
|
||||
/* Insert code to test every subexpression that can be completely
|
||||
** computed using the current set of tables.
|
||||
@@ -3888,7 +3815,7 @@ static Bitmask codeOneLoopStart(
|
||||
testcase( pTerm->wtFlags & TERM_VIRTUAL );
|
||||
testcase( pTerm->wtFlags & TERM_CODED );
|
||||
if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
|
||||
if( (pTerm->prereqAll & newNotReady)!=0 ){
|
||||
if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
|
||||
testcase( pWInfo->untestedTerms==0
|
||||
&& (pWInfo->wctrlFlags & WHERE_ONETABLE_ONLY)!=0 );
|
||||
pWInfo->untestedTerms = 1;
|
||||
@@ -3920,7 +3847,7 @@ static Bitmask codeOneLoopStart(
|
||||
if( pLevel->iLeftJoin ) continue;
|
||||
pE = pTerm->pExpr;
|
||||
assert( !ExprHasProperty(pE, EP_FromJoin) );
|
||||
assert( (pTerm->prereqRight & newNotReady)!=0 );
|
||||
assert( (pTerm->prereqRight & pLevel->notReady)!=0 );
|
||||
pAlt = findTerm(pWC, iCur, pTerm->u.leftColumn, notReady, WO_EQ|WO_IN, 0);
|
||||
if( pAlt==0 ) continue;
|
||||
if( pAlt->wtFlags & (TERM_CODED) ) continue;
|
||||
@@ -3948,7 +3875,7 @@ static Bitmask codeOneLoopStart(
|
||||
testcase( pTerm->wtFlags & TERM_VIRTUAL );
|
||||
testcase( pTerm->wtFlags & TERM_CODED );
|
||||
if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
|
||||
if( (pTerm->prereqAll & newNotReady)!=0 ){
|
||||
if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
|
||||
assert( pWInfo->untestedTerms );
|
||||
continue;
|
||||
}
|
||||
@@ -3959,7 +3886,7 @@ static Bitmask codeOneLoopStart(
|
||||
}
|
||||
sqlite3ReleaseTempReg(pParse, iReleaseReg);
|
||||
|
||||
return newNotReady;
|
||||
return pLevel->notReady;
|
||||
}
|
||||
|
||||
#ifdef WHERETRACE_ENABLED
|
||||
@@ -4060,8 +3987,11 @@ static int whereLoopResize(sqlite3 *db, WhereLoop *p, int n){
|
||||
** Transfer content from the second pLoop into the first.
|
||||
*/
|
||||
static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){
|
||||
if( whereLoopResize(db, pTo, pFrom->nLTerm) ) return SQLITE_NOMEM;
|
||||
whereLoopClearUnion(db, pTo);
|
||||
if( whereLoopResize(db, pTo, pFrom->nLTerm) ){
|
||||
memset(&pTo->u, 0, sizeof(pTo->u));
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
|
||||
memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));
|
||||
if( pFrom->wsFlags & WHERE_VIRTUALTABLE ){
|
||||
@@ -4175,11 +4105,11 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){
|
||||
** all of (1) dependencies (2) setup-cost, (3) run-cost, and
|
||||
** (4) number of output rows. */
|
||||
assert( p->rSetup==pTemplate->rSetup );
|
||||
if( p->nLTerm<pTemplate->nLTerm
|
||||
&& (p->wsFlags & WHERE_INDEXED)!=0
|
||||
&& (pTemplate->wsFlags & WHERE_INDEXED)!=0
|
||||
&& p->u.btree.pIndex==pTemplate->u.btree.pIndex
|
||||
&& p->prereq==pTemplate->prereq
|
||||
if( p->prereq==pTemplate->prereq
|
||||
&& p->nLTerm<pTemplate->nLTerm
|
||||
&& (p->wsFlags & pTemplate->wsFlags & WHERE_INDEXED)!=0
|
||||
&& (p->u.btree.pIndex==pTemplate->u.btree.pIndex
|
||||
|| pTemplate->rRun+p->nLTerm<=p->rRun+pTemplate->nLTerm)
|
||||
){
|
||||
/* Overwrite an existing WhereLoop with an similar one that uses
|
||||
** more terms of the index */
|
||||
@@ -4194,12 +4124,12 @@ static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){
|
||||
if( (p->prereq & pTemplate->prereq)==pTemplate->prereq
|
||||
&& p->rRun>=pTemplate->rRun
|
||||
&& p->nOut>=pTemplate->nOut
|
||||
&& ALWAYS(p->rSetup>=pTemplate->rSetup) /* See SETUP-INVARIANT above */
|
||||
){
|
||||
/* Overwrite an existing WhereLoop with a better one: one that is
|
||||
** better at one of (1) dependencies, (2) setup-cost, (3) run-cost
|
||||
** or (4) number of output rows, and is no worse in any of those
|
||||
** categories. */
|
||||
assert( p->rSetup>=pTemplate->rSetup ); /* SETUP-INVARIANT above */
|
||||
pNext = p->pNextLoop;
|
||||
break;
|
||||
}
|
||||
@@ -4246,6 +4176,36 @@ whereLoopInsert_noop:
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Adjust the WhereLoop.nOut value downward to account for terms of the
|
||||
** WHERE clause that reference the loop but which are not used by an
|
||||
** index.
|
||||
**
|
||||
** In the current implementation, the first extra WHERE clause term reduces
|
||||
** the number of output rows by a factor of 10 and each additional term
|
||||
** reduces the number of output rows by sqrt(2).
|
||||
*/
|
||||
static void whereLoopOutputAdjust(WhereClause *pWC, WhereLoop *pLoop, int iCur){
|
||||
WhereTerm *pTerm, *pX;
|
||||
Bitmask notAllowed = ~(pLoop->prereq|pLoop->maskSelf);
|
||||
int i, j;
|
||||
|
||||
if( !OptimizationEnabled(pWC->pWInfo->pParse->db, SQLITE_AdjustOutEst) ){
|
||||
return;
|
||||
}
|
||||
for(i=pWC->nTerm, pTerm=pWC->a; i>0; i--, pTerm++){
|
||||
if( (pTerm->wtFlags & TERM_VIRTUAL)!=0 ) break;
|
||||
if( (pTerm->prereqAll & pLoop->maskSelf)==0 ) continue;
|
||||
if( (pTerm->prereqAll & notAllowed)!=0 ) continue;
|
||||
for(j=pLoop->nLTerm-1; j>=0; j--){
|
||||
pX = pLoop->aLTerm[j];
|
||||
if( pX==pTerm ) break;
|
||||
if( pX->iParent>=0 && (&pWC->a[pX->iParent])==pTerm ) break;
|
||||
}
|
||||
if( j<0 ) pLoop->nOut += pTerm->truthProb;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** We have so far matched pBuilder->pNew->u.btree.nEq terms of the index pIndex.
|
||||
** Try to match one more.
|
||||
@@ -4257,7 +4217,7 @@ static int whereLoopAddBtreeIndex(
|
||||
WhereLoopBuilder *pBuilder, /* The WhereLoop factory */
|
||||
struct SrcList_item *pSrc, /* FROM clause term being analyzed */
|
||||
Index *pProbe, /* An index on pSrc */
|
||||
WhereCost nInMul /* log(Number of iterations due to IN) */
|
||||
LogEst nInMul /* log(Number of iterations due to IN) */
|
||||
){
|
||||
WhereInfo *pWInfo = pBuilder->pWInfo; /* WHERE analyse context */
|
||||
Parse *pParse = pWInfo->pParse; /* Parsing context */
|
||||
@@ -4270,11 +4230,11 @@ static int whereLoopAddBtreeIndex(
|
||||
u16 saved_nLTerm; /* Original value of pNew->nLTerm */
|
||||
int saved_nEq; /* Original value of pNew->u.btree.nEq */
|
||||
u32 saved_wsFlags; /* Original value of pNew->wsFlags */
|
||||
WhereCost saved_nOut; /* Original value of pNew->nOut */
|
||||
LogEst saved_nOut; /* Original value of pNew->nOut */
|
||||
int iCol; /* Index of the column in the table */
|
||||
int rc = SQLITE_OK; /* Return code */
|
||||
WhereCost nRowEst; /* Estimated index selectivity */
|
||||
WhereCost rLogSize; /* Logarithm of table size */
|
||||
LogEst nRowEst; /* Estimated index selectivity */
|
||||
LogEst rLogSize; /* Logarithm of table size */
|
||||
WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */
|
||||
|
||||
pNew = pBuilder->pNew;
|
||||
@@ -4294,8 +4254,8 @@ static int whereLoopAddBtreeIndex(
|
||||
assert( pNew->u.btree.nEq<=pProbe->nColumn );
|
||||
if( pNew->u.btree.nEq < pProbe->nColumn ){
|
||||
iCol = pProbe->aiColumn[pNew->u.btree.nEq];
|
||||
nRowEst = whereCost(pProbe->aiRowEst[pNew->u.btree.nEq+1]);
|
||||
if( nRowEst==0 && pProbe->onError==OE_None ) nRowEst = 1;
|
||||
nRowEst = pProbe->aiRowEst[pNew->u.btree.nEq+1];
|
||||
if( nRowEst<10 && pProbe->onError==OE_None ) nRowEst = 10;
|
||||
}else{
|
||||
iCol = -1;
|
||||
nRowEst = 0;
|
||||
@@ -4308,7 +4268,7 @@ static int whereLoopAddBtreeIndex(
|
||||
saved_prereq = pNew->prereq;
|
||||
saved_nOut = pNew->nOut;
|
||||
pNew->rSetup = 0;
|
||||
rLogSize = estLog(whereCost(pProbe->aiRowEst[0]));
|
||||
rLogSize = estLog(pProbe->aiRowEst[0]);
|
||||
for(; rc==SQLITE_OK && pTerm!=0; pTerm = whereScanNext(&scan)){
|
||||
int nIn = 0;
|
||||
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
|
||||
@@ -4335,10 +4295,10 @@ static int whereLoopAddBtreeIndex(
|
||||
pNew->wsFlags |= WHERE_COLUMN_IN;
|
||||
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
|
||||
/* "x IN (SELECT ...)": TUNING: the SELECT returns 25 rows */
|
||||
nIn = 46; assert( 46==whereCost(25) );
|
||||
nIn = 46; assert( 46==sqlite3LogEst(25) );
|
||||
}else if( ALWAYS(pExpr->x.pList && pExpr->x.pList->nExpr) ){
|
||||
/* "x IN (value, value, ...)" */
|
||||
nIn = whereCost(pExpr->x.pList->nExpr);
|
||||
nIn = sqlite3LogEst(pExpr->x.pList->nExpr);
|
||||
}
|
||||
pNew->rRun += nIn;
|
||||
pNew->u.btree.nEq++;
|
||||
@@ -4360,7 +4320,7 @@ static int whereLoopAddBtreeIndex(
|
||||
pNew->wsFlags |= WHERE_COLUMN_NULL;
|
||||
pNew->u.btree.nEq++;
|
||||
/* TUNING: IS NULL selects 2 rows */
|
||||
nIn = 10; assert( 10==whereCost(2) );
|
||||
nIn = 10; assert( 10==sqlite3LogEst(2) );
|
||||
pNew->nOut = nRowEst + nInMul + nIn;
|
||||
}else if( pTerm->eOperator & (WO_GT|WO_GE) ){
|
||||
testcase( pTerm->eOperator & WO_GT );
|
||||
@@ -4389,7 +4349,7 @@ static int whereLoopAddBtreeIndex(
|
||||
&& OptimizationEnabled(db, SQLITE_Stat3)
|
||||
){
|
||||
Expr *pExpr = pTerm->pExpr;
|
||||
tRowcnt nOut = 0;
|
||||
LogEst nOut = pNew->nOut;
|
||||
if( (pTerm->eOperator & (WO_EQ|WO_ISNULL))!=0 ){
|
||||
testcase( pTerm->eOperator & WO_EQ );
|
||||
testcase( pTerm->eOperator & WO_ISNULL );
|
||||
@@ -4398,21 +4358,18 @@ static int whereLoopAddBtreeIndex(
|
||||
&& !ExprHasProperty(pExpr, EP_xIsSelect) ){
|
||||
rc = whereInScanEst(pParse, pBuilder, pExpr->x.pList, &nOut);
|
||||
}
|
||||
assert( nOut==0 || rc==SQLITE_OK );
|
||||
if( nOut ){
|
||||
nOut = whereCost(nOut);
|
||||
pNew->nOut = MIN(nOut, saved_nOut);
|
||||
}
|
||||
assert( nOut==pNew->nOut || rc==SQLITE_OK );
|
||||
if( nOut<pNew->nOut ) pNew->nOut = nOut;
|
||||
}
|
||||
#endif
|
||||
if( (pNew->wsFlags & (WHERE_IDX_ONLY|WHERE_IPK))==0 ){
|
||||
/* Each row involves a step of the index, then a binary search of
|
||||
** the main table */
|
||||
pNew->rRun = whereCostAdd(pNew->rRun, rLogSize>27 ? rLogSize-17 : 10);
|
||||
pNew->rRun = sqlite3LogEstAdd(pNew->rRun,rLogSize>27 ? rLogSize-17 : 10);
|
||||
}
|
||||
/* Step cost for each output row */
|
||||
pNew->rRun = whereCostAdd(pNew->rRun, pNew->nOut);
|
||||
/* TBD: Adjust nOut for additional constraints */
|
||||
pNew->rRun = sqlite3LogEstAdd(pNew->rRun, pNew->nOut);
|
||||
whereLoopOutputAdjust(pBuilder->pWC, pNew, pSrc->iCursor);
|
||||
rc = whereLoopInsert(pBuilder, pNew);
|
||||
if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0
|
||||
&& pNew->u.btree.nEq<(pProbe->nColumn + (pProbe->zName!=0))
|
||||
@@ -4503,7 +4460,7 @@ static int whereLoopAddBtree(
|
||||
WhereInfo *pWInfo; /* WHERE analysis context */
|
||||
Index *pProbe; /* An index we are evaluating */
|
||||
Index sPk; /* A fake index object for the primary key */
|
||||
tRowcnt aiRowEstPk[2]; /* The aiRowEst[] value for the sPk index */
|
||||
LogEst aiRowEstPk[2]; /* The aiRowEst[] value for the sPk index */
|
||||
int aiColumnPk = -1; /* The aColumn[] value for the sPk index */
|
||||
SrcList *pTabList; /* The FROM clause */
|
||||
struct SrcList_item *pSrc; /* The FROM clause btree term to add */
|
||||
@@ -4511,8 +4468,8 @@ static int whereLoopAddBtree(
|
||||
int rc = SQLITE_OK; /* Return code */
|
||||
int iSortIdx = 1; /* Index number */
|
||||
int b; /* A boolean value */
|
||||
WhereCost rSize; /* number of rows in the table */
|
||||
WhereCost rLogSize; /* Logarithm of the number of rows in the table */
|
||||
LogEst rSize; /* number of rows in the table */
|
||||
LogEst rLogSize; /* Logarithm of the number of rows in the table */
|
||||
WhereClause *pWC; /* The parsed WHERE clause */
|
||||
|
||||
pNew = pBuilder->pNew;
|
||||
@@ -4538,7 +4495,7 @@ static int whereLoopAddBtree(
|
||||
sPk.onError = OE_Replace;
|
||||
sPk.pTable = pSrc->pTab;
|
||||
aiRowEstPk[0] = pSrc->pTab->nRowEst;
|
||||
aiRowEstPk[1] = 1;
|
||||
aiRowEstPk[1] = 0;
|
||||
pFirst = pSrc->pTab->pIndex;
|
||||
if( pSrc->notIndexed==0 ){
|
||||
/* The real indices of the table are only considered if the
|
||||
@@ -4547,7 +4504,7 @@ static int whereLoopAddBtree(
|
||||
}
|
||||
pProbe = &sPk;
|
||||
}
|
||||
rSize = whereCost(pSrc->pTab->nRowEst);
|
||||
rSize = pSrc->pTab->nRowEst;
|
||||
rLogSize = estLog(rSize);
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
|
||||
@@ -4572,13 +4529,13 @@ static int whereLoopAddBtree(
|
||||
/* TUNING: One-time cost for computing the automatic index is
|
||||
** approximately 7*N*log2(N) where N is the number of rows in
|
||||
** the table being indexed. */
|
||||
pNew->rSetup = rLogSize + rSize + 28; assert( 28==whereCost(7) );
|
||||
pNew->rSetup = rLogSize + rSize + 28; assert( 28==sqlite3LogEst(7) );
|
||||
/* TUNING: Each index lookup yields 20 rows in the table. This
|
||||
** is more than the usual guess of 10 rows, since we have no way
|
||||
** of knowning how selective the index will ultimately be. It would
|
||||
** not be unreasonable to make this value much larger. */
|
||||
pNew->nOut = 43; assert( 43==whereCost(20) );
|
||||
pNew->rRun = whereCostAdd(rLogSize,pNew->nOut);
|
||||
pNew->nOut = 43; assert( 43==sqlite3LogEst(20) );
|
||||
pNew->rRun = sqlite3LogEstAdd(rLogSize,pNew->nOut);
|
||||
pNew->wsFlags = WHERE_AUTO_INDEX;
|
||||
pNew->prereq = mExtra | pTerm->prereqRight;
|
||||
rc = whereLoopInsert(pBuilder, pNew);
|
||||
@@ -4612,11 +4569,11 @@ static int whereLoopAddBtree(
|
||||
pNew->iSortIdx = b ? iSortIdx : 0;
|
||||
/* TUNING: Cost of full table scan is 3*(N + log2(N)).
|
||||
** + The extra 3 factor is to encourage the use of indexed lookups
|
||||
** over full scans. A smaller constant 2 is used for covering
|
||||
** index scans so that a covering index scan will be favored over
|
||||
** a table scan. */
|
||||
pNew->rRun = whereCostAdd(rSize,rLogSize) + 16;
|
||||
** over full scans. FIXME */
|
||||
pNew->rRun = sqlite3LogEstAdd(rSize,rLogSize) + 16;
|
||||
whereLoopOutputAdjust(pWC, pNew, pSrc->iCursor);
|
||||
rc = whereLoopInsert(pBuilder, pNew);
|
||||
pNew->nOut = rSize;
|
||||
if( rc ) break;
|
||||
}else{
|
||||
Bitmask m = pSrc->colUsed & ~columnsInIndex(pProbe);
|
||||
@@ -4633,22 +4590,21 @@ static int whereLoopAddBtree(
|
||||
){
|
||||
pNew->iSortIdx = b ? iSortIdx : 0;
|
||||
if( m==0 ){
|
||||
/* TUNING: Cost of a covering index scan is 2*(N + log2(N)).
|
||||
** + The extra 2 factor is to encourage the use of indexed lookups
|
||||
** over index scans. A table scan uses a factor of 3 so that
|
||||
** index scans are favored over table scans.
|
||||
** + If this covering index might also help satisfy the ORDER BY
|
||||
** clause, then the cost is fudged down slightly so that this
|
||||
** index is favored above other indices that have no hope of
|
||||
** helping with the ORDER BY. */
|
||||
pNew->rRun = 10 + whereCostAdd(rSize,rLogSize) - b;
|
||||
/* TUNING: Cost of a covering index scan is K*(N + log2(N)).
|
||||
** + The extra factor K of between 1.1 (iScanRatio between 0
|
||||
** and 9) and 2.8 (iScanRatio between 126 and 127) is added
|
||||
** to encourage the use of indexed lookups. FIXME
|
||||
*/
|
||||
pNew->rRun = sqlite3LogEstAdd(rSize,rLogSize) + 10;
|
||||
}else{
|
||||
assert( b!=0 );
|
||||
/* TUNING: Cost of scanning a non-covering index is (N+1)*log2(N)
|
||||
** which we will simplify to just N*log2(N) */
|
||||
pNew->rRun = rSize + rLogSize;
|
||||
}
|
||||
whereLoopOutputAdjust(pWC, pNew, pSrc->iCursor);
|
||||
rc = whereLoopInsert(pBuilder, pNew);
|
||||
pNew->nOut = rSize;
|
||||
if( rc ) break;
|
||||
}
|
||||
}
|
||||
@@ -4817,9 +4773,9 @@ static int whereLoopAddVirtual(
|
||||
pNew->u.vtab.isOrdered = (u8)((pIdxInfo->nOrderBy!=0)
|
||||
&& pIdxInfo->orderByConsumed);
|
||||
pNew->rSetup = 0;
|
||||
pNew->rRun = whereCostFromDouble(pIdxInfo->estimatedCost);
|
||||
pNew->rRun = sqlite3LogEstFromDouble(pIdxInfo->estimatedCost);
|
||||
/* TUNING: Every virtual table query returns 25 rows */
|
||||
pNew->nOut = 46; assert( 46==whereCost(25) );
|
||||
pNew->nOut = 46; assert( 46==sqlite3LogEst(25) );
|
||||
whereLoopInsert(pBuilder, pNew);
|
||||
if( pNew->u.vtab.needFree ){
|
||||
sqlite3_free(pNew->u.vtab.idxStr);
|
||||
@@ -4909,8 +4865,8 @@ static int whereLoopAddOr(WhereLoopBuilder *pBuilder, Bitmask mExtra){
|
||||
for(i=0; i<sPrev.n; i++){
|
||||
for(j=0; j<sCur.n; j++){
|
||||
whereOrInsert(&sSum, sPrev.a[i].prereq | sCur.a[j].prereq,
|
||||
whereCostAdd(sPrev.a[i].rRun, sCur.a[j].rRun),
|
||||
whereCostAdd(sPrev.a[i].nOut, sCur.a[j].nOut));
|
||||
sqlite3LogEstAdd(sPrev.a[i].rRun, sCur.a[j].rRun),
|
||||
sqlite3LogEstAdd(sPrev.a[i].nOut, sCur.a[j].nOut));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5248,16 +5204,19 @@ static const char *wherePathName(WherePath *pPath, int nLoop, WhereLoop *pLast){
|
||||
** Return SQLITE_OK on success or SQLITE_NOMEM of a memory allocation
|
||||
** error occurs.
|
||||
*/
|
||||
static int wherePathSolver(WhereInfo *pWInfo, WhereCost nRowEst){
|
||||
static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){
|
||||
int mxChoice; /* Maximum number of simultaneous paths tracked */
|
||||
int nLoop; /* Number of terms in the join */
|
||||
Parse *pParse; /* Parsing context */
|
||||
sqlite3 *db; /* The database connection */
|
||||
int iLoop; /* Loop counter over the terms of the join */
|
||||
int ii, jj; /* Loop counters */
|
||||
WhereCost rCost; /* Cost of a path */
|
||||
WhereCost mxCost = 0; /* Maximum cost of a set of paths */
|
||||
WhereCost rSortCost; /* Cost to do a sort */
|
||||
int mxI = 0; /* Index of next entry to replace */
|
||||
LogEst rCost; /* Cost of a path */
|
||||
LogEst nOut; /* Number of outputs */
|
||||
LogEst mxCost = 0; /* Maximum cost of a set of paths */
|
||||
LogEst mxOut = 0; /* Maximum nOut value on the set of paths */
|
||||
LogEst rSortCost; /* Cost to do a sort */
|
||||
int nTo, nFrom; /* Number of valid entries in aTo[] and aFrom[] */
|
||||
WherePath *aFrom; /* All nFrom paths at the previous level */
|
||||
WherePath *aTo; /* The nTo best paths at the current level */
|
||||
@@ -5294,7 +5253,7 @@ static int wherePathSolver(WhereInfo *pWInfo, WhereCost nRowEst){
|
||||
** TUNING: Do not let the number of iterations go above 25. If the cost
|
||||
** of computing an automatic index is not paid back within the first 25
|
||||
** rows, then do not use the automatic index. */
|
||||
aFrom[0].nRow = MIN(pParse->nQueryLoop, 46); assert( 46==whereCost(25) );
|
||||
aFrom[0].nRow = MIN(pParse->nQueryLoop, 46); assert( 46==sqlite3LogEst(25) );
|
||||
nFrom = 1;
|
||||
|
||||
/* Precompute the cost of sorting the final result set, if the caller
|
||||
@@ -5324,8 +5283,9 @@ static int wherePathSolver(WhereInfo *pWInfo, WhereCost nRowEst){
|
||||
if( (pWLoop->maskSelf & pFrom->maskLoop)!=0 ) continue;
|
||||
/* At this point, pWLoop is a candidate to be the next loop.
|
||||
** Compute its cost */
|
||||
rCost = whereCostAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow);
|
||||
rCost = whereCostAdd(rCost, pFrom->rCost);
|
||||
rCost = sqlite3LogEstAdd(pWLoop->rSetup,pWLoop->rRun + pFrom->nRow);
|
||||
rCost = sqlite3LogEstAdd(rCost, pFrom->rCost);
|
||||
nOut = pFrom->nRow + pWLoop->nOut;
|
||||
maskNew = pFrom->maskLoop | pWLoop->maskSelf;
|
||||
if( !isOrderedValid ){
|
||||
switch( wherePathSatisfiesOrderBy(pWInfo,
|
||||
@@ -5338,7 +5298,7 @@ static int wherePathSolver(WhereInfo *pWInfo, WhereCost nRowEst){
|
||||
case 0: /* No. pFrom+pWLoop will require a separate sort */
|
||||
isOrdered = 0;
|
||||
isOrderedValid = 1;
|
||||
rCost = whereCostAdd(rCost, rSortCost);
|
||||
rCost = sqlite3LogEstAdd(rCost, rSortCost);
|
||||
break;
|
||||
default: /* Cannot tell yet. Try again on the next iteration */
|
||||
break;
|
||||
@@ -5348,7 +5308,11 @@ static int wherePathSolver(WhereInfo *pWInfo, WhereCost nRowEst){
|
||||
}
|
||||
/* Check to see if pWLoop should be added to the mxChoice best so far */
|
||||
for(jj=0, pTo=aTo; jj<nTo; jj++, pTo++){
|
||||
if( pTo->maskLoop==maskNew && pTo->isOrderedValid==isOrderedValid ){
|
||||
if( pTo->maskLoop==maskNew
|
||||
&& pTo->isOrderedValid==isOrderedValid
|
||||
&& ((pTo->rCost<=rCost && pTo->nRow<=nOut) ||
|
||||
(pTo->rCost>=rCost && pTo->nRow>=nOut))
|
||||
){
|
||||
testcase( jj==nTo-1 );
|
||||
break;
|
||||
}
|
||||
@@ -5357,8 +5321,8 @@ static int wherePathSolver(WhereInfo *pWInfo, WhereCost nRowEst){
|
||||
if( nTo>=mxChoice && rCost>=mxCost ){
|
||||
#ifdef WHERETRACE_ENABLED
|
||||
if( sqlite3WhereTrace&0x4 ){
|
||||
sqlite3DebugPrintf("Skip %s cost=%3d order=%c\n",
|
||||
wherePathName(pFrom, iLoop, pWLoop), rCost,
|
||||
sqlite3DebugPrintf("Skip %s cost=%-3d,%3d order=%c\n",
|
||||
wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
|
||||
isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
|
||||
}
|
||||
#endif
|
||||
@@ -5370,26 +5334,26 @@ static int wherePathSolver(WhereInfo *pWInfo, WhereCost nRowEst){
|
||||
jj = nTo++;
|
||||
}else{
|
||||
/* New path replaces the prior worst to keep count below mxChoice */
|
||||
for(jj=nTo-1; aTo[jj].rCost<mxCost; jj--){ assert(jj>0); }
|
||||
jj = mxI;
|
||||
}
|
||||
pTo = &aTo[jj];
|
||||
#ifdef WHERETRACE_ENABLED
|
||||
if( sqlite3WhereTrace&0x4 ){
|
||||
sqlite3DebugPrintf("New %s cost=%-3d order=%c\n",
|
||||
wherePathName(pFrom, iLoop, pWLoop), rCost,
|
||||
sqlite3DebugPrintf("New %s cost=%-3d,%3d order=%c\n",
|
||||
wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
|
||||
isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
|
||||
}
|
||||
#endif
|
||||
}else{
|
||||
if( pTo->rCost<=rCost ){
|
||||
if( pTo->rCost<=rCost && pTo->nRow<=nOut ){
|
||||
#ifdef WHERETRACE_ENABLED
|
||||
if( sqlite3WhereTrace&0x4 ){
|
||||
sqlite3DebugPrintf(
|
||||
"Skip %s cost=%-3d order=%c",
|
||||
wherePathName(pFrom, iLoop, pWLoop), rCost,
|
||||
"Skip %s cost=%-3d,%3d order=%c",
|
||||
wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
|
||||
isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
|
||||
sqlite3DebugPrintf(" vs %s cost=%-3d order=%c\n",
|
||||
wherePathName(pTo, iLoop+1, 0), pTo->rCost,
|
||||
sqlite3DebugPrintf(" vs %s cost=%-3d,%d order=%c\n",
|
||||
wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
|
||||
pTo->isOrderedValid ? (pTo->isOrdered ? 'Y' : 'N') : '?');
|
||||
}
|
||||
#endif
|
||||
@@ -5401,11 +5365,11 @@ static int wherePathSolver(WhereInfo *pWInfo, WhereCost nRowEst){
|
||||
#ifdef WHERETRACE_ENABLED
|
||||
if( sqlite3WhereTrace&0x4 ){
|
||||
sqlite3DebugPrintf(
|
||||
"Update %s cost=%-3d order=%c",
|
||||
wherePathName(pFrom, iLoop, pWLoop), rCost,
|
||||
"Update %s cost=%-3d,%3d order=%c",
|
||||
wherePathName(pFrom, iLoop, pWLoop), rCost, nOut,
|
||||
isOrderedValid ? (isOrdered ? 'Y' : 'N') : '?');
|
||||
sqlite3DebugPrintf(" was %s cost=%-3d order=%c\n",
|
||||
wherePathName(pTo, iLoop+1, 0), pTo->rCost,
|
||||
sqlite3DebugPrintf(" was %s cost=%-3d,%3d order=%c\n",
|
||||
wherePathName(pTo, iLoop+1, 0), pTo->rCost, pTo->nRow,
|
||||
pTo->isOrderedValid ? (pTo->isOrdered ? 'Y' : 'N') : '?');
|
||||
}
|
||||
#endif
|
||||
@@ -5413,16 +5377,22 @@ static int wherePathSolver(WhereInfo *pWInfo, WhereCost nRowEst){
|
||||
/* pWLoop is a winner. Add it to the set of best so far */
|
||||
pTo->maskLoop = pFrom->maskLoop | pWLoop->maskSelf;
|
||||
pTo->revLoop = revMask;
|
||||
pTo->nRow = pFrom->nRow + pWLoop->nOut;
|
||||
pTo->nRow = nOut;
|
||||
pTo->rCost = rCost;
|
||||
pTo->isOrderedValid = isOrderedValid;
|
||||
pTo->isOrdered = isOrdered;
|
||||
memcpy(pTo->aLoop, pFrom->aLoop, sizeof(WhereLoop*)*iLoop);
|
||||
pTo->aLoop[iLoop] = pWLoop;
|
||||
if( nTo>=mxChoice ){
|
||||
mxI = 0;
|
||||
mxCost = aTo[0].rCost;
|
||||
mxOut = aTo[0].nRow;
|
||||
for(jj=1, pTo=&aTo[1]; jj<mxChoice; jj++, pTo++){
|
||||
if( pTo->rCost>mxCost ) mxCost = pTo->rCost;
|
||||
if( pTo->rCost>mxCost || (pTo->rCost==mxCost && pTo->nRow>mxOut) ){
|
||||
mxCost = pTo->rCost;
|
||||
mxOut = pTo->nRow;
|
||||
mxI = jj;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5459,12 +5429,9 @@ static int wherePathSolver(WhereInfo *pWInfo, WhereCost nRowEst){
|
||||
|
||||
/* Find the lowest cost path. pFrom will be left pointing to that path */
|
||||
pFrom = aFrom;
|
||||
assert( nFrom==1 );
|
||||
#if 0 /* The following is needed if nFrom is ever more than 1 */
|
||||
for(ii=1; ii<nFrom; ii++){
|
||||
if( pFrom->rCost>aFrom[ii].rCost ) pFrom = &aFrom[ii];
|
||||
}
|
||||
#endif
|
||||
assert( pWInfo->nLevel==nLoop );
|
||||
/* Load the lowest cost path into pWInfo */
|
||||
for(iLoop=0; iLoop<nLoop; iLoop++){
|
||||
@@ -5538,7 +5505,7 @@ static int whereShortCut(WhereLoopBuilder *pBuilder){
|
||||
pLoop->nLTerm = 1;
|
||||
pLoop->u.btree.nEq = 1;
|
||||
/* TUNING: Cost of a rowid lookup is 10 */
|
||||
pLoop->rRun = 33; /* 33==whereCost(10) */
|
||||
pLoop->rRun = 33; /* 33==sqlite3LogEst(10) */
|
||||
}else{
|
||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||
assert( pLoop->aLTermSpace==pLoop->aLTerm );
|
||||
@@ -5561,12 +5528,12 @@ static int whereShortCut(WhereLoopBuilder *pBuilder){
|
||||
pLoop->u.btree.nEq = j;
|
||||
pLoop->u.btree.pIndex = pIdx;
|
||||
/* TUNING: Cost of a unique index lookup is 15 */
|
||||
pLoop->rRun = 39; /* 39==whereCost(15) */
|
||||
pLoop->rRun = 39; /* 39==sqlite3LogEst(15) */
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( pLoop->wsFlags ){
|
||||
pLoop->nOut = (WhereCost)1;
|
||||
pLoop->nOut = (LogEst)1;
|
||||
pWInfo->a[0].pWLoop = pLoop;
|
||||
pLoop->maskSelf = getMask(&pWInfo->sMaskSet, iCur);
|
||||
pWInfo->a[0].iTabCur = iCur;
|
||||
@@ -5904,7 +5871,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
&& OptimizationEnabled(db, SQLITE_OmitNoopJoin)
|
||||
){
|
||||
Bitmask tabUsed = exprListTableUsage(pMaskSet, pResultSet);
|
||||
if( pOrderBy ) tabUsed |= exprListTableUsage(pMaskSet, pOrderBy);
|
||||
if( sWLB.pOrderBy ) tabUsed |= exprListTableUsage(pMaskSet, sWLB.pOrderBy);
|
||||
while( pWInfo->nLevel>=2 ){
|
||||
WhereTerm *pTerm, *pEnd;
|
||||
pLoop = pWInfo->a[pWInfo->nLevel-1].pWLoop;
|
||||
@@ -5934,7 +5901,7 @@ WhereInfo *sqlite3WhereBegin(
|
||||
|
||||
/* If the caller is an UPDATE or DELETE statement that is requesting
|
||||
** to use a one-pass algorithm, determine if this is appropriate.
|
||||
** The one-pass algorithm only works if the WHERE clause constraints
|
||||
** The one-pass algorithm only works if the WHERE clause constrains
|
||||
** the statement to update a single row.
|
||||
*/
|
||||
assert( (wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || pWInfo->nLevel==1 );
|
||||
|
||||
@@ -847,6 +847,7 @@ do_test alter-14.2 {
|
||||
set system_table_list {1 sqlite_master}
|
||||
catchsql ANALYZE
|
||||
ifcapable analyze { lappend system_table_list 2 sqlite_stat1 }
|
||||
ifcapable stat3 { lappend system_table_list 3 sqlite_stat3 }
|
||||
ifcapable stat4 { lappend system_table_list 4 sqlite_stat4 }
|
||||
|
||||
foreach {tn tbl} $system_table_list {
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
# 2013-09-30
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#*************************************************************************
|
||||
# This file implements regression tests for "approximate_match" virtual
|
||||
# table that is in the "amatch.c" extension.
|
||||
#
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If SQLITE_ENABLE_FTS4 is defined, omit this file.
|
||||
ifcapable !fts3 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
# Create the fts_kjv_genesis procedure which fills and FTS3/4 table with
|
||||
# the complete text of the Book of Genesis.
|
||||
#
|
||||
source $testdir/genesis.tcl
|
||||
|
||||
|
||||
|
||||
do_test amatch1-1.0 {
|
||||
db eval {
|
||||
CREATE VIRTUAL TABLE t1 USING fts4(words); --, tokenize porter);
|
||||
}
|
||||
fts_kjv_genesis
|
||||
db eval {
|
||||
INSERT INTO t1(t1) VALUES('optimize');
|
||||
CREATE VIRTUAL TABLE temp.t1aux USING fts4aux(main, t1);
|
||||
SELECT term FROM t1aux WHERE col=0 ORDER BY 1 LIMIT 5
|
||||
}
|
||||
} {a abated abel abelmizraim abidah}
|
||||
do_test amatch1-1.1 {
|
||||
db eval {
|
||||
SELECT term FROM t1aux WHERE term>'b' AND col=0 ORDER BY 1 LIMIT 5
|
||||
}
|
||||
} {baalhanan babel back backward bad}
|
||||
do_test amatch1-1.2 {
|
||||
db eval {
|
||||
SELECT term FROM t1aux WHERE term>'b' AND col=0 LIMIT 5
|
||||
}
|
||||
} {baalhanan babel back backward bad}
|
||||
|
||||
# Load the amatch extension
|
||||
load_static_extension db amatch
|
||||
|
||||
do_execsql_test amatch1-2.0 {
|
||||
CREATE TABLE costs(iLang, cFrom, cTo, Cost);
|
||||
INSERT INTO costs VALUES(0, '', '?', 100);
|
||||
INSERT INTO costs VALUES(0, '?', '', 100);
|
||||
INSERT INTO costs VALUES(0, '?', '?', 150);
|
||||
CREATE TABLE vocab(w TEXT UNIQUE);
|
||||
INSERT OR IGNORE INTO vocab SELECT term FROM t1aux;
|
||||
CREATE VIRTUAL TABLE t2 USING approximate_match(
|
||||
vocabulary_table=t1aux,
|
||||
vocabulary_word=term,
|
||||
edit_distances=costs
|
||||
);
|
||||
CREATE VIRTUAL TABLE t3 USING approximate_match(
|
||||
vocabulary_table=vocab,
|
||||
vocabulary_word=w,
|
||||
edit_distances=costs
|
||||
);
|
||||
CREATE VIRTUAL TABLE t4 USING approximate_match(
|
||||
vocabulary_table=vtemp,
|
||||
vocabulary_word=w,
|
||||
edit_distances=costs
|
||||
);
|
||||
} {}
|
||||
puts "Query against fts4aux: [time {
|
||||
do_execsql_test amatch1-2.1 {
|
||||
SELECT word, distance FROM t2
|
||||
WHERE word MATCH 'josxph' AND distance<300;
|
||||
} {joseph 150}} 1]"
|
||||
puts "Query against ordinary table: [time {
|
||||
do_execsql_test amatch1-2.2 {
|
||||
SELECT word, distance FROM t3
|
||||
WHERE word MATCH 'josxph' AND distance<300;
|
||||
} {joseph 150}} 1]"
|
||||
puts "Temp table initialized from fts4aux: [time {
|
||||
do_execsql_test amatch1-2.3a {
|
||||
CREATE TEMP TABLE vtemp(w TEXT UNIQUE);
|
||||
INSERT OR IGNORE INTO vtemp SELECT term FROM t1aux;
|
||||
} {}} 1]"
|
||||
puts "Query against temp table: [time {
|
||||
do_execsql_test amatch1-2.3b {
|
||||
SELECT word, distance FROM t4
|
||||
WHERE word MATCH 'josxph' AND distance<300;
|
||||
} {joseph 150}} 1]"
|
||||
do_execsql_test amatch1-2.11 {
|
||||
SELECT word, distance FROM t2
|
||||
WHERE word MATCH 'joxxph' AND distance<=300;
|
||||
} {joseph 300}
|
||||
do_execsql_test amatch1-2.12 {
|
||||
SELECT word, distance FROM t3
|
||||
WHERE word MATCH 'joxxph' AND distance<=300;
|
||||
} {joseph 300}
|
||||
do_execsql_test amatch1-2.21 {
|
||||
SELECT word, distance FROM t2
|
||||
WHERE word MATCH 'joxxph' AND distance<300;
|
||||
} {}
|
||||
do_execsql_test amatch1-2.22 {
|
||||
SELECT word, distance FROM t3
|
||||
WHERE word MATCH 'joxxph' AND distance<300;
|
||||
} {}
|
||||
|
||||
finish_test
|
||||
+6
-6
@@ -30,14 +30,14 @@ proc eqp {sql {db db}} {
|
||||
|
||||
do_test analyze6-1.0 {
|
||||
db eval {
|
||||
CREATE TABLE cat(x INT);
|
||||
CREATE TABLE cat(x INT, yz TEXT);
|
||||
CREATE UNIQUE INDEX catx ON cat(x);
|
||||
/* Give cat 16 unique integers */
|
||||
INSERT INTO cat VALUES(1);
|
||||
INSERT INTO cat VALUES(2);
|
||||
INSERT INTO cat SELECT x+2 FROM cat;
|
||||
INSERT INTO cat SELECT x+4 FROM cat;
|
||||
INSERT INTO cat SELECT x+8 FROM cat;
|
||||
INSERT INTO cat(x) VALUES(1);
|
||||
INSERT INTO cat(x) VALUES(2);
|
||||
INSERT INTO cat(x) SELECT x+2 FROM cat;
|
||||
INSERT INTO cat(x) SELECT x+4 FROM cat;
|
||||
INSERT INTO cat(x) SELECT x+8 FROM cat;
|
||||
|
||||
CREATE TABLE ev(y INT);
|
||||
CREATE INDEX evy ON ev(y);
|
||||
|
||||
+528
-2
@@ -245,7 +245,7 @@ do_execsql_test 4.3 {
|
||||
ORDER BY rowid DESC LIMIT 2;
|
||||
} {
|
||||
{2 1 1 1} {295 296 296} {120 122 125} {201 4}
|
||||
{5 3 1 1} {290 290 292} {119 119 121} {200 1}
|
||||
{5 3 1 1} {290 290 290} {119 119 119} {200 1}
|
||||
}
|
||||
|
||||
do_execsql_test 4.4 { SELECT count(DISTINCT c) FROM t1 WHERE c<201 } 120
|
||||
@@ -422,5 +422,531 @@ do_eqp_test 9.4.2 {
|
||||
SELECT * FROM t1 WHERE a='x' AND b='y' AND c='z' AND d=$value_d AND e=5
|
||||
} {/t1 USING INDEX i1/}
|
||||
|
||||
finish_test
|
||||
#-------------------------------------------------------------------------
|
||||
# Check that the planner takes stat4 data into account when considering
|
||||
# "IS NULL" and "IS NOT NULL" constraints.
|
||||
#
|
||||
do_execsql_test 10.1.1 {
|
||||
DROP TABLE IF EXISTS t3;
|
||||
CREATE TABLE t3(a, b);
|
||||
CREATE INDEX t3a ON t3(a);
|
||||
CREATE INDEX t3b ON t3(b);
|
||||
}
|
||||
do_test 10.1.2 {
|
||||
for {set i 1} {$i < 100} {incr i} {
|
||||
if {$i>90} { set a $i } else { set a NULL }
|
||||
set b [expr $i % 5]
|
||||
execsql "INSERT INTO t3 VALUES($a, $b)"
|
||||
}
|
||||
execsql ANALYZE
|
||||
} {}
|
||||
do_eqp_test 10.1.3 {
|
||||
SELECT * FROM t3 WHERE a IS NULL AND b = 2
|
||||
} {/t3 USING INDEX t3b/}
|
||||
do_eqp_test 10.1.4 {
|
||||
SELECT * FROM t3 WHERE a IS NOT NULL AND b = 2
|
||||
} {/t3 USING INDEX t3a/}
|
||||
|
||||
do_execsql_test 10.2.1 {
|
||||
DROP TABLE IF EXISTS t3;
|
||||
CREATE TABLE t3(x, a, b);
|
||||
CREATE INDEX t3a ON t3(x, a);
|
||||
CREATE INDEX t3b ON t3(x, b);
|
||||
}
|
||||
do_test 10.2.2 {
|
||||
for {set i 1} {$i < 100} {incr i} {
|
||||
if {$i>90} { set a $i } else { set a NULL }
|
||||
set b [expr $i % 5]
|
||||
execsql "INSERT INTO t3 VALUES('xyz', $a, $b)"
|
||||
}
|
||||
execsql ANALYZE
|
||||
} {}
|
||||
do_eqp_test 10.2.3 {
|
||||
SELECT * FROM t3 WHERE x = 'xyz' AND a IS NULL AND b = 2
|
||||
} {/t3 USING INDEX t3b/}
|
||||
do_eqp_test 10.2.4 {
|
||||
SELECT * FROM t3 WHERE x = 'xyz' AND a IS NOT NULL AND b = 2
|
||||
} {/t3 USING INDEX t3a/}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Check that stat4 data is used correctly with non-default collation
|
||||
# sequences.
|
||||
#
|
||||
foreach {tn schema} {
|
||||
1 {
|
||||
CREATE TABLE t4(a COLLATE nocase, b);
|
||||
CREATE INDEX t4a ON t4(a);
|
||||
CREATE INDEX t4b ON t4(b);
|
||||
}
|
||||
2 {
|
||||
CREATE TABLE t4(a, b);
|
||||
CREATE INDEX t4a ON t4(a COLLATE nocase);
|
||||
CREATE INDEX t4b ON t4(b);
|
||||
}
|
||||
} {
|
||||
drop_all_tables
|
||||
do_test 11.$tn.1 { execsql $schema } {}
|
||||
|
||||
do_test 11.$tn.2 {
|
||||
for {set i 0} {$i < 100} {incr i} {
|
||||
if { ($i % 10)==0 } { set a ABC } else { set a DEF }
|
||||
set b [expr $i % 5]
|
||||
execsql { INSERT INTO t4 VALUES($a, $b) }
|
||||
}
|
||||
execsql ANALYZE
|
||||
} {}
|
||||
|
||||
do_eqp_test 11.$tn.3 {
|
||||
SELECT * FROM t4 WHERE a = 'def' AND b = 3;
|
||||
} {/t4 USING INDEX t4b/}
|
||||
|
||||
if {$tn==1} {
|
||||
set sql "SELECT * FROM t4 WHERE a = 'abc' AND b = 3;"
|
||||
do_eqp_test 11.$tn.4 $sql {/t4 USING INDEX t4a/}
|
||||
} else {
|
||||
|
||||
set sql "SELECT * FROM t4 WHERE a = 'abc' COLLATE nocase AND b = 3;"
|
||||
do_eqp_test 11.$tn.5 $sql {/t4 USING INDEX t4a/}
|
||||
|
||||
set sql "SELECT * FROM t4 WHERE a COLLATE nocase = 'abc' AND b = 3;"
|
||||
do_eqp_test 11.$tn.6 $sql {/t4 USING INDEX t4a/}
|
||||
}
|
||||
}
|
||||
|
||||
foreach {tn schema} {
|
||||
1 {
|
||||
CREATE TABLE t4(x, a COLLATE nocase, b);
|
||||
CREATE INDEX t4a ON t4(x, a);
|
||||
CREATE INDEX t4b ON t4(x, b);
|
||||
}
|
||||
2 {
|
||||
CREATE TABLE t4(x, a, b);
|
||||
CREATE INDEX t4a ON t4(x, a COLLATE nocase);
|
||||
CREATE INDEX t4b ON t4(x, b);
|
||||
}
|
||||
} {
|
||||
drop_all_tables
|
||||
do_test 12.$tn.1 { execsql $schema } {}
|
||||
|
||||
do_test 12.$tn.2 {
|
||||
for {set i 0} {$i < 100} {incr i} {
|
||||
if { ($i % 10)==0 } { set a ABC } else { set a DEF }
|
||||
set b [expr $i % 5]
|
||||
execsql { INSERT INTO t4 VALUES(X'abcdef', $a, $b) }
|
||||
}
|
||||
execsql ANALYZE
|
||||
} {}
|
||||
|
||||
do_eqp_test 12.$tn.3 {
|
||||
SELECT * FROM t4 WHERE x=X'abcdef' AND a = 'def' AND b = 3;
|
||||
} {/t4 USING INDEX t4b/}
|
||||
|
||||
if {$tn==1} {
|
||||
set sql "SELECT * FROM t4 WHERE x=X'abcdef' AND a = 'abc' AND b = 3;"
|
||||
do_eqp_test 12.$tn.4 $sql {/t4 USING INDEX t4a/}
|
||||
} else {
|
||||
set sql {
|
||||
SELECT * FROM t4 WHERE x=X'abcdef' AND a = 'abc' COLLATE nocase AND b = 3
|
||||
}
|
||||
do_eqp_test 12.$tn.5 $sql {/t4 USING INDEX t4a/}
|
||||
set sql {
|
||||
SELECT * FROM t4 WHERE x=X'abcdef' AND a COLLATE nocase = 'abc' AND b = 3
|
||||
}
|
||||
do_eqp_test 12.$tn.6 $sql {/t4 USING INDEX t4a/}
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Check that affinities are taken into account when using stat4 data to
|
||||
# estimate the number of rows scanned by a rowid constraint.
|
||||
#
|
||||
drop_all_tables
|
||||
do_test 13.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a, b, c);
|
||||
CREATE INDEX i1 ON t1(a);
|
||||
CREATE INDEX i2 ON t1(b, c);
|
||||
}
|
||||
for {set i 0} {$i<100} {incr i} {
|
||||
if {$i %2} {set a abc} else {set a def}
|
||||
execsql { INSERT INTO t1(rowid, a, b, c) VALUES($i, $a, $i, $i) }
|
||||
}
|
||||
execsql ANALYZE
|
||||
} {}
|
||||
do_eqp_test 13.2.1 {
|
||||
SELECT * FROM t1 WHERE a='abc' AND rowid<15 AND b<20
|
||||
} {/SEARCH TABLE t1 USING INDEX i1/}
|
||||
do_eqp_test 13.2.2 {
|
||||
SELECT * FROM t1 WHERE a='abc' AND rowid<'15' AND b<20
|
||||
} {/SEARCH TABLE t1 USING INDEX i1/}
|
||||
do_eqp_test 13.3.1 {
|
||||
SELECT * FROM t1 WHERE a='abc' AND rowid<100 AND b<20
|
||||
} {/SEARCH TABLE t1 USING INDEX i2/}
|
||||
do_eqp_test 13.3.2 {
|
||||
SELECT * FROM t1 WHERE a='abc' AND rowid<'100' AND b<20
|
||||
} {/SEARCH TABLE t1 USING INDEX i2/}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Check also that affinities are taken into account when using stat4 data
|
||||
# to estimate the number of rows scanned by any other constraint on a
|
||||
# column other than the leftmost.
|
||||
#
|
||||
drop_all_tables
|
||||
do_test 14.1 {
|
||||
execsql { CREATE TABLE t1(a, b INTEGER, c) }
|
||||
for {set i 0} {$i<100} {incr i} {
|
||||
set c [expr $i % 3]
|
||||
execsql { INSERT INTO t1 VALUES('ott', $i, $c) }
|
||||
}
|
||||
execsql {
|
||||
CREATE INDEX i1 ON t1(a, b);
|
||||
CREATE INDEX i2 ON t1(c);
|
||||
ANALYZE;
|
||||
}
|
||||
} {}
|
||||
do_eqp_test 13.2.1 {
|
||||
SELECT * FROM t1 WHERE a='ott' AND b<10 AND c=1
|
||||
} {/SEARCH TABLE t1 USING INDEX i1/}
|
||||
do_eqp_test 13.2.2 {
|
||||
SELECT * FROM t1 WHERE a='ott' AND b<'10' AND c=1
|
||||
} {/SEARCH TABLE t1 USING INDEX i1/}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# By default, 16 non-periodic samples are collected for the stat4 table.
|
||||
# The following tests attempt to verify that the most common keys are
|
||||
# being collected.
|
||||
#
|
||||
proc check_stat4 {tn} {
|
||||
db eval ANALYZE
|
||||
db eval {SELECT a, b, c, d FROM t1} {
|
||||
incr k($a)
|
||||
incr k([list $a $b])
|
||||
incr k([list $a $b $c])
|
||||
if { [info exists k([list $a $b $c $d])]==0 } { incr nRow }
|
||||
incr k([list $a $b $c $d])
|
||||
}
|
||||
|
||||
set L [list]
|
||||
foreach key [array names k] {
|
||||
lappend L [list $k($key) $key]
|
||||
}
|
||||
|
||||
set nSample $nRow
|
||||
if {$nSample>16} {set nSample 16}
|
||||
|
||||
set nThreshold [lindex [lsort -decr -integer -index 0 $L] [expr $nSample-1] 0]
|
||||
foreach key [array names k] {
|
||||
if {$k($key)>$nThreshold} {
|
||||
set expect($key) 1
|
||||
}
|
||||
if {$k($key)==$nThreshold} {
|
||||
set possible($key) 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
set nPossible [expr $nSample - [llength [array names expect]]]
|
||||
|
||||
#puts "EXPECT: [array names expect]"
|
||||
#puts "POSSIBLE($nPossible/[array size possible]): [array names possible]"
|
||||
#puts "HAVE: [db eval {SELECT test_decode(sample) FROM sqlite_stat4 WHERE idx='i1'}]"
|
||||
|
||||
db eval {SELECT test_decode(sample) AS s FROM sqlite_stat4 WHERE idx='i1'} {
|
||||
set seen 0
|
||||
for {set i 0} {$i<4} {incr i} {
|
||||
unset -nocomplain expect([lrange $s 0 $i])
|
||||
if {[info exists possible([lrange $s 0 $i])]} {
|
||||
set seen 1
|
||||
unset -nocomplain possible([lrange $s 0 $i])
|
||||
}
|
||||
}
|
||||
if {$seen} {incr nPossible -1}
|
||||
}
|
||||
if {$nPossible<0} {set nPossible 0}
|
||||
|
||||
set res [list [llength [array names expect]] $nPossible]
|
||||
uplevel [list do_test $tn [list set {} $res] {0 0}]
|
||||
}
|
||||
|
||||
drop_all_tables
|
||||
do_test 14.1.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a,b,c,d);
|
||||
CREATE INDEX i1 ON t1(a,b,c,d);
|
||||
}
|
||||
for {set i 0} {$i < 160} {incr i} {
|
||||
execsql { INSERT INTO t1 VALUES($i,$i,$i,$i) }
|
||||
if {($i % 10)==0} { execsql { INSERT INTO t1 VALUES($i,$i,$i,$i) } }
|
||||
}
|
||||
} {}
|
||||
check_stat4 14.1.2
|
||||
|
||||
do_test 14.2.1 {
|
||||
execsql { DELETE FROM t1 }
|
||||
for {set i 0} {$i < 1600} {incr i} {
|
||||
execsql { INSERT INTO t1 VALUES($i/10,$i/17,$i/27,$i/37) }
|
||||
}
|
||||
} {}
|
||||
check_stat4 14.2.2
|
||||
|
||||
do_test 14.3.1 {
|
||||
for {set i 0} {$i < 10} {incr i} {
|
||||
execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) }
|
||||
execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) }
|
||||
execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) }
|
||||
execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) }
|
||||
execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) }
|
||||
execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) }
|
||||
execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) }
|
||||
execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) }
|
||||
execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) }
|
||||
execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) }
|
||||
}
|
||||
} {}
|
||||
check_stat4 14.3.2
|
||||
|
||||
do_test 14.4.1 {
|
||||
execsql {DELETE FROM t1}
|
||||
for {set i 1} {$i < 160} {incr i} {
|
||||
set b [expr $i % 10]
|
||||
if {$b==0 || $b==2} {set b 1}
|
||||
execsql { INSERT INTO t1 VALUES($i/10,$b,$i,$i) }
|
||||
}
|
||||
} {}
|
||||
check_stat4 14.4.2
|
||||
db func lrange lrange
|
||||
db func lindex lindex
|
||||
do_execsql_test 14.4.3 {
|
||||
SELECT lrange(test_decode(sample), 0, 1) AS s FROM sqlite_stat4
|
||||
WHERE lindex(s, 1)=='1' ORDER BY rowid
|
||||
} {
|
||||
{0 1} {1 1} {2 1} {3 1}
|
||||
{4 1} {5 1} {6 1} {7 1}
|
||||
{8 1} {9 1} {10 1} {11 1}
|
||||
{12 1} {13 1} {14 1} {15 1}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test that nothing untoward happens if the stat4 table contains entries
|
||||
# for indexes that do not exist. Or NULL values in the idx column.
|
||||
# Or NULL values in any of the other columns.
|
||||
#
|
||||
drop_all_tables
|
||||
do_execsql_test 15.1 {
|
||||
CREATE TABLE x1(a, b, UNIQUE(a, b));
|
||||
INSERT INTO x1 VALUES(1, 2);
|
||||
INSERT INTO x1 VALUES(3, 4);
|
||||
INSERT INTO x1 VALUES(5, 6);
|
||||
ANALYZE;
|
||||
INSERT INTO sqlite_stat4 VALUES(NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
}
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
do_execsql_test 15.2 { SELECT * FROM x1 } {1 2 3 4 5 6}
|
||||
|
||||
do_execsql_test 15.3 {
|
||||
INSERT INTO sqlite_stat4 VALUES(42, 42, 42, 42, 42, 42);
|
||||
}
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
do_execsql_test 15.4 { SELECT * FROM x1 } {1 2 3 4 5 6}
|
||||
|
||||
do_execsql_test 15.5 {
|
||||
UPDATE sqlite_stat1 SET stat = NULL;
|
||||
}
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
do_execsql_test 15.6 { SELECT * FROM x1 } {1 2 3 4 5 6}
|
||||
|
||||
do_execsql_test 15.7 {
|
||||
ANALYZE;
|
||||
UPDATE sqlite_stat1 SET tbl = 'no such tbl';
|
||||
}
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
do_execsql_test 15.8 { SELECT * FROM x1 } {1 2 3 4 5 6}
|
||||
|
||||
do_execsql_test 15.9 {
|
||||
ANALYZE;
|
||||
UPDATE sqlite_stat4 SET neq = NULL, nlt=NULL, ndlt=NULL;
|
||||
}
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
do_execsql_test 15.10 { SELECT * FROM x1 } {1 2 3 4 5 6}
|
||||
|
||||
# This is just for coverage....
|
||||
do_execsql_test 15.11 {
|
||||
ANALYZE;
|
||||
UPDATE sqlite_stat1 SET stat = stat || ' unordered';
|
||||
}
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
do_execsql_test 15.12 { SELECT * FROM x1 } {1 2 3 4 5 6}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test that allocations used for sqlite_stat4 samples are included in
|
||||
# the quantity returned by SQLITE_DBSTATUS_SCHEMA_USED.
|
||||
#
|
||||
set one [string repeat x 1000]
|
||||
set two [string repeat x 2000]
|
||||
do_test 16.1 {
|
||||
reset_db
|
||||
execsql {
|
||||
CREATE TABLE t1(a, UNIQUE(a));
|
||||
INSERT INTO t1 VALUES($one);
|
||||
ANALYZE;
|
||||
}
|
||||
set nByte [lindex [sqlite3_db_status db SCHEMA_USED 0] 1]
|
||||
|
||||
reset_db
|
||||
execsql {
|
||||
CREATE TABLE t1(a, UNIQUE(a));
|
||||
INSERT INTO t1 VALUES($two);
|
||||
ANALYZE;
|
||||
}
|
||||
set nByte2 [lindex [sqlite3_db_status db SCHEMA_USED 0] 1]
|
||||
|
||||
expr {$nByte2 > $nByte+900 && $nByte2 < $nByte+1050}
|
||||
} {1}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test that stat4 data may be used with partial indexes.
|
||||
#
|
||||
do_test 17.1 {
|
||||
reset_db
|
||||
execsql {
|
||||
CREATE TABLE t1(a, b, c, d);
|
||||
CREATE INDEX i1 ON t1(a, b) WHERE d IS NOT NULL;
|
||||
INSERT INTO t1 VALUES(-1, -1, -1, NULL);
|
||||
INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1;
|
||||
INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1;
|
||||
INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1;
|
||||
INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1;
|
||||
INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1;
|
||||
INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1;
|
||||
}
|
||||
|
||||
for {set i 0} {$i < 32} {incr i} {
|
||||
if {$i<8} {set b 0} else { set b $i }
|
||||
execsql { INSERT INTO t1 VALUES($i%2, $b, $i/2, 'abc') }
|
||||
}
|
||||
execsql {ANALYZE main.t1}
|
||||
} {}
|
||||
|
||||
do_catchsql_test 17.1.2 {
|
||||
ANALYZE temp.t1;
|
||||
} {1 {no such table: temp.t1}}
|
||||
|
||||
do_eqp_test 17.2 {
|
||||
SELECT * FROM t1 WHERE d IS NOT NULL AND a=0 AND b=10 AND c=10;
|
||||
} {/USING INDEX i1/}
|
||||
do_eqp_test 17.3 {
|
||||
SELECT * FROM t1 WHERE d IS NOT NULL AND a=0 AND b=0 AND c=10;
|
||||
} {/USING INDEX i1/}
|
||||
|
||||
do_execsql_test 17.4 {
|
||||
CREATE INDEX i2 ON t1(c, d);
|
||||
ANALYZE main.i2;
|
||||
}
|
||||
do_eqp_test 17.5 {
|
||||
SELECT * FROM t1 WHERE d IS NOT NULL AND a=0 AND b=10 AND c=10;
|
||||
} {/USING INDEX i1/}
|
||||
do_eqp_test 17.6 {
|
||||
SELECT * FROM t1 WHERE d IS NOT NULL AND a=0 AND b=0 AND c=10;
|
||||
} {/USING INDEX i2/}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
do_test 18.1 {
|
||||
reset_db
|
||||
execsql {
|
||||
CREATE TABLE t1(a, b);
|
||||
CREATE INDEX i1 ON t1(a, b);
|
||||
}
|
||||
for {set i 0} {$i < 9} {incr i} {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
}
|
||||
}
|
||||
execsql ANALYZE
|
||||
execsql { SELECT count(*) FROM sqlite_stat4 }
|
||||
} {9}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# For coverage.
|
||||
#
|
||||
ifcapable view {
|
||||
do_test 19.1 {
|
||||
reset_db
|
||||
execsql {
|
||||
CREATE TABLE t1(x, y);
|
||||
CREATE INDEX i1 ON t1(x, y);
|
||||
CREATE VIEW v1 AS SELECT * FROM t1;
|
||||
ANALYZE;
|
||||
}
|
||||
} {}
|
||||
}
|
||||
ifcapable auth {
|
||||
proc authproc {op args} {
|
||||
if {$op == "SQLITE_ANALYZE"} { return "SQLITE_DENY" }
|
||||
return "SQLITE_OK"
|
||||
}
|
||||
do_test 19.2 {
|
||||
reset_db
|
||||
db auth authproc
|
||||
execsql {
|
||||
CREATE TABLE t1(x, y);
|
||||
CREATE VIEW v1 AS SELECT * FROM t1;
|
||||
}
|
||||
catchsql ANALYZE
|
||||
} {1 {not authorized}}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
reset_db
|
||||
proc r {args} { expr rand() }
|
||||
db func r r
|
||||
db func lrange lrange
|
||||
do_test 20.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a,b,c,d);
|
||||
CREATE INDEX i1 ON t1(a,b,c,d);
|
||||
}
|
||||
for {set i 0} {$i < 16} {incr i} {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES($i, r(), r(), r());
|
||||
INSERT INTO t1 VALUES($i, $i, r(), r());
|
||||
INSERT INTO t1 VALUES($i, $i, $i, r());
|
||||
INSERT INTO t1 VALUES($i, $i, $i, $i);
|
||||
INSERT INTO t1 VALUES($i, $i, $i, $i);
|
||||
INSERT INTO t1 VALUES($i, $i, $i, r());
|
||||
INSERT INTO t1 VALUES($i, $i, r(), r());
|
||||
INSERT INTO t1 VALUES($i, r(), r(), r());
|
||||
}
|
||||
}
|
||||
} {}
|
||||
do_execsql_test 20.2 { ANALYZE }
|
||||
for {set i 0} {$i<16} {incr i} {
|
||||
set val "$i $i $i $i"
|
||||
do_execsql_test 20.3.$i {
|
||||
SELECT count(*) FROM sqlite_stat4
|
||||
WHERE lrange(test_decode(sample), 0, 3)=$val
|
||||
} {1}
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -0,0 +1,683 @@
|
||||
# 2013 August 3
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# This file contains automated tests used to verify that the sqlite_stat3
|
||||
# functionality is working. The tests in this file are based on a subset
|
||||
# of the sqlite_stat4 tests in analyze9.test.
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
set testprefix analyzeB
|
||||
|
||||
ifcapable !stat3 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE TABLE t1(a TEXT, b TEXT);
|
||||
INSERT INTO t1 VALUES('(0)', '(0)');
|
||||
INSERT INTO t1 VALUES('(1)', '(1)');
|
||||
INSERT INTO t1 VALUES('(2)', '(2)');
|
||||
INSERT INTO t1 VALUES('(3)', '(3)');
|
||||
INSERT INTO t1 VALUES('(4)', '(4)');
|
||||
CREATE INDEX i1 ON t1(a, b);
|
||||
} {}
|
||||
|
||||
|
||||
do_execsql_test 1.1 {
|
||||
ANALYZE;
|
||||
} {}
|
||||
|
||||
do_execsql_test 1.2 {
|
||||
SELECT tbl,idx,nEq,nLt,nDLt,quote(sample) FROM sqlite_stat3;
|
||||
} {
|
||||
t1 i1 1 0 0 '(0)'
|
||||
t1 i1 1 1 1 '(1)'
|
||||
t1 i1 1 2 2 '(2)'
|
||||
t1 i1 1 3 3 '(3)'
|
||||
t1 i1 1 4 4 '(4)'
|
||||
}
|
||||
|
||||
if {[permutation] != "utf16"} {
|
||||
do_execsql_test 1.3 {
|
||||
SELECT tbl,idx,nEq,nLt,nDLt,quote(sample) FROM sqlite_stat3;
|
||||
} {
|
||||
t1 i1 1 0 0 '(0)'
|
||||
t1 i1 1 1 1 '(1)'
|
||||
t1 i1 1 2 2 '(2)'
|
||||
t1 i1 1 3 3 '(3)'
|
||||
t1 i1 1 4 4 '(4)'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# This is really just to test SQL user function "test_decode".
|
||||
#
|
||||
reset_db
|
||||
do_execsql_test 2.1 {
|
||||
CREATE TABLE t1(a, b, c);
|
||||
INSERT INTO t1(a) VALUES('some text');
|
||||
INSERT INTO t1(a) VALUES(14);
|
||||
INSERT INTO t1(a) VALUES(NULL);
|
||||
INSERT INTO t1(a) VALUES(22.0);
|
||||
INSERT INTO t1(a) VALUES(x'656667');
|
||||
CREATE INDEX i1 ON t1(a, b, c);
|
||||
ANALYZE;
|
||||
SELECT quote(sample) FROM sqlite_stat3;
|
||||
} {
|
||||
NULL 14 22.0 {'some text'} X'656667'
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
reset_db
|
||||
do_execsql_test 3.1 {
|
||||
CREATE TABLE t2(a, b);
|
||||
CREATE INDEX i2 ON t2(a, b);
|
||||
BEGIN;
|
||||
}
|
||||
|
||||
do_test 3.2 {
|
||||
for {set i 0} {$i < 1000} {incr i} {
|
||||
set a [expr $i / 10]
|
||||
set b [expr int(rand() * 15.0)]
|
||||
execsql { INSERT INTO t2 VALUES($a, $b) }
|
||||
}
|
||||
execsql COMMIT
|
||||
} {}
|
||||
|
||||
db func lindex lindex
|
||||
|
||||
# Each value of "a" occurs exactly 10 times in the table.
|
||||
#
|
||||
do_execsql_test 3.3.1 {
|
||||
SELECT count(*) FROM t2 GROUP BY a;
|
||||
} [lrange [string repeat "10 " 100] 0 99]
|
||||
|
||||
# The first element in the "nEq" list of all samples should therefore be 10.
|
||||
#
|
||||
do_execsql_test 3.3.2 {
|
||||
ANALYZE;
|
||||
SELECT nEq FROM sqlite_stat3;
|
||||
} [lrange [string repeat "10 " 100] 0 23]
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
do_execsql_test 3.4 {
|
||||
DROP TABLE IF EXISTS t1;
|
||||
CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
|
||||
INSERT INTO t1 VALUES(1, 1, 'one-a');
|
||||
INSERT INTO t1 VALUES(11, 1, 'one-b');
|
||||
INSERT INTO t1 VALUES(21, 1, 'one-c');
|
||||
INSERT INTO t1 VALUES(31, 1, 'one-d');
|
||||
INSERT INTO t1 VALUES(41, 1, 'one-e');
|
||||
INSERT INTO t1 VALUES(51, 1, 'one-f');
|
||||
INSERT INTO t1 VALUES(61, 1, 'one-g');
|
||||
INSERT INTO t1 VALUES(71, 1, 'one-h');
|
||||
INSERT INTO t1 VALUES(81, 1, 'one-i');
|
||||
INSERT INTO t1 VALUES(91, 1, 'one-j');
|
||||
INSERT INTO t1 SELECT a+1,2,'two' || substr(c,4) FROM t1;
|
||||
INSERT INTO t1 SELECT a+2,3,'three'||substr(c,4) FROM t1 WHERE c GLOB 'one-*';
|
||||
INSERT INTO t1 SELECT a+3,4,'four'||substr(c,4) FROM t1 WHERE c GLOB 'one-*';
|
||||
INSERT INTO t1 SELECT a+4,5,'five'||substr(c,4) FROM t1 WHERE c GLOB 'one-*';
|
||||
INSERT INTO t1 SELECT a+5,6,'six'||substr(c,4) FROM t1 WHERE c GLOB 'one-*';
|
||||
CREATE INDEX t1b ON t1(b);
|
||||
ANALYZE;
|
||||
SELECT c FROM t1 WHERE b=3 AND a BETWEEN 30 AND 60;
|
||||
} {three-d three-e three-f}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# These tests verify that the sample selection for stat3 appears to be
|
||||
# working as designed.
|
||||
#
|
||||
|
||||
reset_db
|
||||
db func lindex lindex
|
||||
db func lrange lrange
|
||||
|
||||
do_execsql_test 4.0 {
|
||||
DROP TABLE IF EXISTS t1;
|
||||
CREATE TABLE t1(a, b, c);
|
||||
CREATE INDEX i1 ON t1(c, b, a);
|
||||
}
|
||||
|
||||
|
||||
proc insert_filler_rows_n {iStart args} {
|
||||
set A(-ncopy) 1
|
||||
set A(-nval) 1
|
||||
|
||||
foreach {k v} $args {
|
||||
if {[info exists A($k)]==0} { error "no such option: $k" }
|
||||
set A($k) $v
|
||||
}
|
||||
if {[llength $args] % 2} {
|
||||
error "option requires an argument: [lindex $args end]"
|
||||
}
|
||||
|
||||
for {set i 0} {$i < $A(-nval)} {incr i} {
|
||||
set iVal [expr $iStart+$i]
|
||||
for {set j 0} {$j < $A(-ncopy)} {incr j} {
|
||||
execsql { INSERT INTO t1 VALUES($iVal, $iVal, $iVal) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
do_test 4.1 {
|
||||
execsql { BEGIN }
|
||||
insert_filler_rows_n 0 -ncopy 10 -nval 19
|
||||
insert_filler_rows_n 20 -ncopy 1 -nval 100
|
||||
|
||||
execsql {
|
||||
INSERT INTO t1(c, b, a) VALUES(200, 1, 'a');
|
||||
INSERT INTO t1(c, b, a) VALUES(200, 1, 'b');
|
||||
INSERT INTO t1(c, b, a) VALUES(200, 1, 'c');
|
||||
|
||||
INSERT INTO t1(c, b, a) VALUES(200, 2, 'e');
|
||||
INSERT INTO t1(c, b, a) VALUES(200, 2, 'f');
|
||||
|
||||
INSERT INTO t1(c, b, a) VALUES(201, 3, 'g');
|
||||
INSERT INTO t1(c, b, a) VALUES(201, 4, 'h');
|
||||
|
||||
ANALYZE;
|
||||
SELECT count(*) FROM sqlite_stat3;
|
||||
SELECT count(*) FROM t1;
|
||||
}
|
||||
} {24 297}
|
||||
|
||||
do_execsql_test 4.2 {
|
||||
SELECT neq, nlt, ndlt, sample FROM sqlite_stat3 ORDER BY rowid LIMIT 16;
|
||||
} {
|
||||
10 0 0 0
|
||||
10 10 1 1
|
||||
10 20 2 2
|
||||
10 30 3 3
|
||||
10 40 4 4
|
||||
10 50 5 5
|
||||
10 60 6 6
|
||||
10 70 7 7
|
||||
10 80 8 8
|
||||
10 90 9 9
|
||||
10 100 10 10
|
||||
10 110 11 11
|
||||
10 120 12 12
|
||||
10 130 13 13
|
||||
10 140 14 14
|
||||
10 150 15 15
|
||||
}
|
||||
|
||||
do_execsql_test 4.3 {
|
||||
SELECT neq, nlt, ndlt, sample FROM sqlite_stat3
|
||||
ORDER BY rowid DESC LIMIT 2;
|
||||
} {
|
||||
2 295 120 201
|
||||
5 290 119 200
|
||||
}
|
||||
|
||||
do_execsql_test 4.4 { SELECT count(DISTINCT c) FROM t1 WHERE c<201 } 120
|
||||
do_execsql_test 4.5 { SELECT count(DISTINCT c) FROM t1 WHERE c<200 } 119
|
||||
|
||||
reset_db
|
||||
do_test 4.7 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
CREATE TABLE t1(o,t INTEGER PRIMARY KEY);
|
||||
CREATE INDEX i1 ON t1(o);
|
||||
}
|
||||
for {set i 0} {$i<10000} {incr i [expr (($i<1000)?1:10)]} {
|
||||
execsql { INSERT INTO t1 VALUES('x', $i) }
|
||||
}
|
||||
execsql {
|
||||
COMMIT;
|
||||
ANALYZE;
|
||||
SELECT count(*) FROM sqlite_stat3;
|
||||
}
|
||||
} {1}
|
||||
do_execsql_test 4.8 {
|
||||
SELECT sample FROM sqlite_stat3;
|
||||
} {x}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# The following would cause a crash at one point.
|
||||
#
|
||||
reset_db
|
||||
do_execsql_test 5.1 {
|
||||
PRAGMA encoding = 'utf-16';
|
||||
CREATE TABLE t0(v);
|
||||
ANALYZE;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# This was also crashing (corrupt sqlite_stat3 table).
|
||||
#
|
||||
reset_db
|
||||
do_execsql_test 6.1 {
|
||||
CREATE TABLE t1(a, b);
|
||||
CREATE INDEX i1 ON t1(a);
|
||||
CREATE INDEX i2 ON t1(b);
|
||||
INSERT INTO t1 VALUES(1, 1);
|
||||
INSERT INTO t1 VALUES(2, 2);
|
||||
INSERT INTO t1 VALUES(3, 3);
|
||||
INSERT INTO t1 VALUES(4, 4);
|
||||
INSERT INTO t1 VALUES(5, 5);
|
||||
ANALYZE;
|
||||
PRAGMA writable_schema = 1;
|
||||
CREATE TEMP TABLE x1 AS
|
||||
SELECT tbl,idx,neq,nlt,ndlt,sample FROM sqlite_stat3
|
||||
ORDER BY (rowid%5), rowid;
|
||||
DELETE FROM sqlite_stat3;
|
||||
INSERT INTO sqlite_stat3 SELECT * FROM x1;
|
||||
PRAGMA writable_schema = 0;
|
||||
ANALYZE sqlite_master;
|
||||
}
|
||||
do_execsql_test 6.2 {
|
||||
SELECT * FROM t1 WHERE a = 'abc';
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# The following tests experiment with adding corrupted records to the
|
||||
# 'sample' column of the sqlite_stat3 table.
|
||||
#
|
||||
reset_db
|
||||
sqlite3_db_config_lookaside db 0 0 0
|
||||
|
||||
do_execsql_test 7.1 {
|
||||
CREATE TABLE t1(a, b);
|
||||
CREATE INDEX i1 ON t1(a, b);
|
||||
INSERT INTO t1 VALUES(1, 1);
|
||||
INSERT INTO t1 VALUES(2, 2);
|
||||
INSERT INTO t1 VALUES(3, 3);
|
||||
INSERT INTO t1 VALUES(4, 4);
|
||||
INSERT INTO t1 VALUES(5, 5);
|
||||
ANALYZE;
|
||||
UPDATE sqlite_stat3 SET sample = X'' WHERE rowid = 1;
|
||||
ANALYZE sqlite_master;
|
||||
}
|
||||
|
||||
do_execsql_test 7.2 {
|
||||
UPDATE sqlite_stat3 SET sample = X'FFFF';
|
||||
ANALYZE sqlite_master;
|
||||
SELECT * FROM t1 WHERE a = 1;
|
||||
} {1 1}
|
||||
|
||||
do_execsql_test 7.3 {
|
||||
ANALYZE;
|
||||
UPDATE sqlite_stat3 SET neq = '0 0 0';
|
||||
ANALYZE sqlite_master;
|
||||
SELECT * FROM t1 WHERE a = 1;
|
||||
} {1 1}
|
||||
|
||||
do_execsql_test 7.4 {
|
||||
ANALYZE;
|
||||
UPDATE sqlite_stat3 SET ndlt = '0 0 0';
|
||||
ANALYZE sqlite_master;
|
||||
SELECT * FROM t1 WHERE a = 3;
|
||||
} {3 3}
|
||||
|
||||
do_execsql_test 7.5 {
|
||||
ANALYZE;
|
||||
UPDATE sqlite_stat3 SET nlt = '0 0 0';
|
||||
ANALYZE sqlite_master;
|
||||
SELECT * FROM t1 WHERE a = 5;
|
||||
} {5 5}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
reset_db
|
||||
do_execsql_test 8.1 {
|
||||
CREATE TABLE t1(x TEXT);
|
||||
CREATE INDEX i1 ON t1(x);
|
||||
INSERT INTO t1 VALUES('1');
|
||||
INSERT INTO t1 VALUES('2');
|
||||
INSERT INTO t1 VALUES('3');
|
||||
INSERT INTO t1 VALUES('4');
|
||||
ANALYZE;
|
||||
}
|
||||
do_execsql_test 8.2 {
|
||||
SELECT * FROM t1 WHERE x = 3;
|
||||
} {3}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
reset_db
|
||||
do_execsql_test 9.1 {
|
||||
CREATE TABLE t1(a, b, c, d, e);
|
||||
CREATE INDEX i1 ON t1(a, b, c, d);
|
||||
CREATE INDEX i2 ON t1(e);
|
||||
}
|
||||
do_test 9.2 {
|
||||
execsql BEGIN;
|
||||
for {set i 0} {$i < 100} {incr i} {
|
||||
execsql "INSERT INTO t1 VALUES('x', 'y', 'z', $i, [expr $i/2])"
|
||||
}
|
||||
for {set i 0} {$i < 20} {incr i} {
|
||||
execsql "INSERT INTO t1 VALUES('x', 'y', 'z', 101, $i)"
|
||||
}
|
||||
for {set i 102} {$i < 200} {incr i} {
|
||||
execsql "INSERT INTO t1 VALUES('x', 'y', 'z', $i, [expr $i/2])"
|
||||
}
|
||||
execsql COMMIT
|
||||
execsql ANALYZE
|
||||
} {}
|
||||
|
||||
do_eqp_test 9.3.1 {
|
||||
SELECT * FROM t1 WHERE a='x' AND b='y' AND c='z' AND d=101 AND e=5;
|
||||
} {/t1 USING INDEX i1/}
|
||||
do_eqp_test 9.3.2 {
|
||||
SELECT * FROM t1 WHERE a='x' AND b='y' AND c='z' AND d=99 AND e=5;
|
||||
} {/t1 USING INDEX i1/}
|
||||
|
||||
set value_d [expr 101]
|
||||
do_eqp_test 9.4.1 {
|
||||
SELECT * FROM t1 WHERE a='x' AND b='y' AND c='z' AND d=$value_d AND e=5
|
||||
} {/t1 USING INDEX i1/}
|
||||
set value_d [expr 99]
|
||||
do_eqp_test 9.4.2 {
|
||||
SELECT * FROM t1 WHERE a='x' AND b='y' AND c='z' AND d=$value_d AND e=5
|
||||
} {/t1 USING INDEX i1/}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Check that the planner takes stat3 data into account when considering
|
||||
# "IS NULL" and "IS NOT NULL" constraints.
|
||||
#
|
||||
do_execsql_test 10.1.1 {
|
||||
DROP TABLE IF EXISTS t3;
|
||||
CREATE TABLE t3(a, b);
|
||||
CREATE INDEX t3a ON t3(a);
|
||||
CREATE INDEX t3b ON t3(b);
|
||||
}
|
||||
do_test 10.1.2 {
|
||||
for {set i 1} {$i < 100} {incr i} {
|
||||
if {$i>90} { set a $i } else { set a NULL }
|
||||
set b [expr $i % 5]
|
||||
execsql "INSERT INTO t3 VALUES($a, $b)"
|
||||
}
|
||||
execsql ANALYZE
|
||||
} {}
|
||||
do_eqp_test 10.1.3 {
|
||||
SELECT * FROM t3 WHERE a IS NULL AND b = 2
|
||||
} {/t3 USING INDEX t3b/}
|
||||
do_eqp_test 10.1.4 {
|
||||
SELECT * FROM t3 WHERE a IS NOT NULL AND b = 2
|
||||
} {/t3 USING INDEX t3a/}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Check that stat3 data is used correctly with non-default collation
|
||||
# sequences.
|
||||
#
|
||||
foreach {tn schema} {
|
||||
1 {
|
||||
CREATE TABLE t4(a COLLATE nocase, b);
|
||||
CREATE INDEX t4a ON t4(a);
|
||||
CREATE INDEX t4b ON t4(b);
|
||||
}
|
||||
2 {
|
||||
CREATE TABLE t4(a, b);
|
||||
CREATE INDEX t4a ON t4(a COLLATE nocase);
|
||||
CREATE INDEX t4b ON t4(b);
|
||||
}
|
||||
} {
|
||||
drop_all_tables
|
||||
do_test 11.$tn.1 { execsql $schema } {}
|
||||
|
||||
do_test 11.$tn.2 {
|
||||
for {set i 0} {$i < 100} {incr i} {
|
||||
if { ($i % 10)==0 } { set a ABC } else { set a DEF }
|
||||
set b [expr $i % 5]
|
||||
execsql { INSERT INTO t4 VALUES($a, $b) }
|
||||
}
|
||||
execsql ANALYZE
|
||||
} {}
|
||||
|
||||
do_eqp_test 11.$tn.3 {
|
||||
SELECT * FROM t4 WHERE a = 'def' AND b = 3;
|
||||
} {/t4 USING INDEX t4b/}
|
||||
|
||||
if {$tn==1} {
|
||||
set sql "SELECT * FROM t4 WHERE a = 'abc' AND b = 3;"
|
||||
do_eqp_test 11.$tn.4 $sql {/t4 USING INDEX t4a/}
|
||||
} else {
|
||||
|
||||
set sql "SELECT * FROM t4 WHERE a = 'abc' COLLATE nocase AND b = 3;"
|
||||
do_eqp_test 11.$tn.5 $sql {/t4 USING INDEX t4a/}
|
||||
|
||||
set sql "SELECT * FROM t4 WHERE a COLLATE nocase = 'abc' AND b = 3;"
|
||||
do_eqp_test 11.$tn.6 $sql {/t4 USING INDEX t4a/}
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test that nothing untoward happens if the stat3 table contains entries
|
||||
# for indexes that do not exist. Or NULL values in the idx column.
|
||||
# Or NULL values in any of the other columns.
|
||||
#
|
||||
drop_all_tables
|
||||
do_execsql_test 15.1 {
|
||||
CREATE TABLE x1(a, b, UNIQUE(a, b));
|
||||
INSERT INTO x1 VALUES(1, 2);
|
||||
INSERT INTO x1 VALUES(3, 4);
|
||||
INSERT INTO x1 VALUES(5, 6);
|
||||
ANALYZE;
|
||||
INSERT INTO sqlite_stat3 VALUES(NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
}
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
do_execsql_test 15.2 { SELECT * FROM x1 } {1 2 3 4 5 6}
|
||||
|
||||
do_execsql_test 15.3 {
|
||||
INSERT INTO sqlite_stat3 VALUES(42, 42, 42, 42, 42, 42);
|
||||
}
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
do_execsql_test 15.4 { SELECT * FROM x1 } {1 2 3 4 5 6}
|
||||
|
||||
do_execsql_test 15.5 {
|
||||
UPDATE sqlite_stat1 SET stat = NULL;
|
||||
}
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
do_execsql_test 15.6 { SELECT * FROM x1 } {1 2 3 4 5 6}
|
||||
|
||||
do_execsql_test 15.7 {
|
||||
ANALYZE;
|
||||
UPDATE sqlite_stat1 SET tbl = 'no such tbl';
|
||||
}
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
do_execsql_test 15.8 { SELECT * FROM x1 } {1 2 3 4 5 6}
|
||||
|
||||
do_execsql_test 15.9 {
|
||||
ANALYZE;
|
||||
UPDATE sqlite_stat3 SET neq = NULL, nlt=NULL, ndlt=NULL;
|
||||
}
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
do_execsql_test 15.10 { SELECT * FROM x1 } {1 2 3 4 5 6}
|
||||
|
||||
# This is just for coverage....
|
||||
do_execsql_test 15.11 {
|
||||
ANALYZE;
|
||||
UPDATE sqlite_stat1 SET stat = stat || ' unordered';
|
||||
}
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
do_execsql_test 15.12 { SELECT * FROM x1 } {1 2 3 4 5 6}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test that allocations used for sqlite_stat3 samples are included in
|
||||
# the quantity returned by SQLITE_DBSTATUS_SCHEMA_USED.
|
||||
#
|
||||
set one [string repeat x 1000]
|
||||
set two [string repeat x 2000]
|
||||
do_test 16.1 {
|
||||
reset_db
|
||||
execsql {
|
||||
CREATE TABLE t1(a, UNIQUE(a));
|
||||
INSERT INTO t1 VALUES($one);
|
||||
ANALYZE;
|
||||
}
|
||||
set nByte [lindex [sqlite3_db_status db SCHEMA_USED 0] 1]
|
||||
|
||||
reset_db
|
||||
execsql {
|
||||
CREATE TABLE t1(a, UNIQUE(a));
|
||||
INSERT INTO t1 VALUES($two);
|
||||
ANALYZE;
|
||||
}
|
||||
set nByte2 [lindex [sqlite3_db_status db SCHEMA_USED 0] 1]
|
||||
|
||||
expr {$nByte2 > $nByte+950 && $nByte2 < $nByte+1050}
|
||||
} {1}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test that stat3 data may be used with partial indexes.
|
||||
#
|
||||
do_test 17.1 {
|
||||
reset_db
|
||||
execsql {
|
||||
CREATE TABLE t1(a, b, c, d);
|
||||
CREATE INDEX i1 ON t1(a, b) WHERE d IS NOT NULL;
|
||||
INSERT INTO t1 VALUES(-1, -1, -1, NULL);
|
||||
INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1;
|
||||
INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1;
|
||||
INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1;
|
||||
INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1;
|
||||
INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1;
|
||||
INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1;
|
||||
}
|
||||
|
||||
for {set i 0} {$i < 32} {incr i} {
|
||||
execsql { INSERT INTO t1 VALUES($i%2, $b, $i/2, 'abc') }
|
||||
}
|
||||
execsql {ANALYZE main.t1}
|
||||
} {}
|
||||
|
||||
do_catchsql_test 17.1.2 {
|
||||
ANALYZE temp.t1;
|
||||
} {1 {no such table: temp.t1}}
|
||||
|
||||
do_eqp_test 17.2 {
|
||||
SELECT * FROM t1 WHERE d IS NOT NULL AND a=0;
|
||||
} {/USING INDEX i1/}
|
||||
do_eqp_test 17.3 {
|
||||
SELECT * FROM t1 WHERE d IS NOT NULL AND a=0;
|
||||
} {/USING INDEX i1/}
|
||||
|
||||
do_execsql_test 17.4 {
|
||||
CREATE INDEX i2 ON t1(c) WHERE d IS NOT NULL;
|
||||
ANALYZE main.i2;
|
||||
}
|
||||
do_eqp_test 17.5 {
|
||||
SELECT * FROM t1 WHERE d IS NOT NULL AND a=0;
|
||||
} {/USING INDEX i1/}
|
||||
do_eqp_test 17.6 {
|
||||
SELECT * FROM t1 WHERE d IS NOT NULL AND a=0 AND b=0 AND c=10;
|
||||
} {/USING INDEX i2/}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
do_test 18.1 {
|
||||
reset_db
|
||||
execsql {
|
||||
CREATE TABLE t1(a, b);
|
||||
CREATE INDEX i1 ON t1(a, b);
|
||||
}
|
||||
for {set i 0} {$i < 9} {incr i} {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
INSERT INTO t1 VALUES($i, 0);
|
||||
}
|
||||
}
|
||||
execsql ANALYZE
|
||||
execsql { SELECT count(*) FROM sqlite_stat3 }
|
||||
} {9}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# For coverage.
|
||||
#
|
||||
ifcapable view {
|
||||
do_test 19.1 {
|
||||
reset_db
|
||||
execsql {
|
||||
CREATE TABLE t1(x, y);
|
||||
CREATE INDEX i1 ON t1(x, y);
|
||||
CREATE VIEW v1 AS SELECT * FROM t1;
|
||||
ANALYZE;
|
||||
}
|
||||
} {}
|
||||
}
|
||||
ifcapable auth {
|
||||
proc authproc {op args} {
|
||||
if {$op == "SQLITE_ANALYZE"} { return "SQLITE_DENY" }
|
||||
return "SQLITE_OK"
|
||||
}
|
||||
do_test 19.2 {
|
||||
reset_db
|
||||
db auth authproc
|
||||
execsql {
|
||||
CREATE TABLE t1(x, y);
|
||||
CREATE VIEW v1 AS SELECT * FROM t1;
|
||||
}
|
||||
catchsql ANALYZE
|
||||
} {1 {not authorized}}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
reset_db
|
||||
proc r {args} { expr rand() }
|
||||
db func r r
|
||||
db func lrange lrange
|
||||
do_test 20.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a,b,c,d);
|
||||
CREATE INDEX i1 ON t1(a,b,c,d);
|
||||
}
|
||||
for {set i 0} {$i < 16} {incr i} {
|
||||
execsql {
|
||||
INSERT INTO t1 VALUES($i, r(), r(), r());
|
||||
INSERT INTO t1 VALUES($i, $i, r(), r());
|
||||
INSERT INTO t1 VALUES($i, $i, $i, r());
|
||||
INSERT INTO t1 VALUES($i, $i, $i, $i);
|
||||
INSERT INTO t1 VALUES($i, $i, $i, $i);
|
||||
INSERT INTO t1 VALUES($i, $i, $i, r());
|
||||
INSERT INTO t1 VALUES($i, $i, r(), r());
|
||||
INSERT INTO t1 VALUES($i, r(), r(), r());
|
||||
}
|
||||
}
|
||||
} {}
|
||||
do_execsql_test 20.2 { ANALYZE }
|
||||
for {set i 0} {$i<16} {incr i} {
|
||||
set val $i
|
||||
do_execsql_test 20.3.$i {
|
||||
SELECT count(*) FROM sqlite_stat3 WHERE sample=$val
|
||||
} {1}
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
+1
-1
@@ -57,6 +57,6 @@ do_test 1.3 {
|
||||
} $str
|
||||
|
||||
db close
|
||||
file delete test.db
|
||||
delete_file test.db
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -528,4 +528,23 @@ if {0==[sqlite3 -has-codec]} {
|
||||
} {1}
|
||||
}
|
||||
}
|
||||
|
||||
# Verify that multiple calls to date functions with 'now' return the
|
||||
# same answer.
|
||||
#
|
||||
proc sleeper {} {after 100}
|
||||
do_test date-15.1 {
|
||||
db func sleeper sleeper
|
||||
db eval {
|
||||
SELECT c - a FROM (SELECT julianday('now') AS a,
|
||||
sleeper(), julianday('now') AS c);
|
||||
}
|
||||
} {0.0}
|
||||
do_test date-15.2 {
|
||||
db eval {
|
||||
SELECT a==b FROM (SELECT current_timestamp AS a,
|
||||
sleeper(), current_timestamp AS b);
|
||||
}
|
||||
} {1}
|
||||
|
||||
finish_test
|
||||
|
||||
+21
-21
@@ -33,11 +33,11 @@ set testprefix eqp
|
||||
proc det {args} { uplevel do_eqp_test $args }
|
||||
|
||||
do_execsql_test 1.1 {
|
||||
CREATE TABLE t1(a, b);
|
||||
CREATE TABLE t1(a INT, b INT, ex TEXT);
|
||||
CREATE INDEX i1 ON t1(a);
|
||||
CREATE INDEX i2 ON t1(b);
|
||||
CREATE TABLE t2(a, b);
|
||||
CREATE TABLE t3(a, b);
|
||||
CREATE TABLE t2(a INT, b INT, ex TEXT);
|
||||
CREATE TABLE t3(a INT, b INT, ex TEXT);
|
||||
}
|
||||
|
||||
do_eqp_test 1.2 {
|
||||
@@ -122,9 +122,9 @@ do_eqp_test 1.11 {
|
||||
#
|
||||
drop_all_tables
|
||||
do_execsql_test 2.1 {
|
||||
CREATE TABLE t1(x, y);
|
||||
CREATE TABLE t1(x INT, y INT, ex TEXT);
|
||||
|
||||
CREATE TABLE t2(x, y);
|
||||
CREATE TABLE t2(x INT, y INT, ex TEXT);
|
||||
CREATE INDEX t2i1 ON t2(x);
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ drop_all_tables
|
||||
# FROM t1 WHERE a=1;
|
||||
# 0|0|0|SCAN TABLE t1
|
||||
#
|
||||
do_execsql_test 5.1.0 { CREATE TABLE t1(a, b) }
|
||||
do_execsql_test 5.1.0 { CREATE TABLE t1(a INT, b INT, ex TEXT) }
|
||||
det 5.1.1 "SELECT a, b FROM t1 WHERE a=1" {
|
||||
0 0 0 {SCAN TABLE t1}
|
||||
}
|
||||
@@ -402,8 +402,8 @@ det 5.3.1 "SELECT a, b FROM t1 WHERE a=1" {
|
||||
# 0|0|0|SEARCH TABLE t1 USING COVERING INDEX i2 (a=? AND b>?)
|
||||
# 0|1|1|SCAN TABLE t2
|
||||
#
|
||||
do_execsql_test 5.4.0 {CREATE TABLE t2(c, d)}
|
||||
det 5.4.1 "SELECT t1.*, t2.* FROM t1, t2 WHERE t1.a=1 AND t1.b>2" {
|
||||
do_execsql_test 5.4.0 {CREATE TABLE t2(c INT, d INT, ex TEXT)}
|
||||
det 5.4.1 "SELECT t1.a, t2.c FROM t1, t2 WHERE t1.a=1 AND t1.b>2" {
|
||||
0 0 0 {SEARCH TABLE t1 USING COVERING INDEX i2 (a=? AND b>?)}
|
||||
0 1 1 {SCAN TABLE t2}
|
||||
}
|
||||
@@ -413,7 +413,7 @@ det 5.4.1 "SELECT t1.*, t2.* FROM t1, t2 WHERE t1.a=1 AND t1.b>2" {
|
||||
# 0|0|1|SEARCH TABLE t1 USING COVERING INDEX i2 (a=? AND b>?)
|
||||
# 0|1|0|SCAN TABLE t2
|
||||
#
|
||||
det 5.5 "SELECT t1.*, t2.* FROM t2, t1 WHERE t1.a=1 AND t1.b>2" {
|
||||
det 5.5 "SELECT t1.a, t2.c FROM t2, t1 WHERE t1.a=1 AND t1.b>2" {
|
||||
0 0 1 {SEARCH TABLE t1 USING COVERING INDEX i2 (a=? AND b>?)}
|
||||
0 1 0 {SCAN TABLE t2}
|
||||
}
|
||||
@@ -424,7 +424,7 @@ det 5.5 "SELECT t1.*, t2.* FROM t2, t1 WHERE t1.a=1 AND t1.b>2" {
|
||||
# 0|0|0|SEARCH TABLE t1 USING INDEX i3 (b=?)
|
||||
#
|
||||
do_execsql_test 5.5.0 {CREATE INDEX i3 ON t1(b)}
|
||||
det 5.6.1 "SELECT * FROM t1 WHERE a=1 OR b=2" {
|
||||
det 5.6.1 "SELECT a, b FROM t1 WHERE a=1 OR b=2" {
|
||||
0 0 0 {SEARCH TABLE t1 USING COVERING INDEX i2 (a=?)}
|
||||
0 0 0 {SEARCH TABLE t1 USING INDEX i3 (b=?)}
|
||||
}
|
||||
@@ -485,7 +485,7 @@ det 5.10 {
|
||||
# 0|0|0|SEARCH TABLE t2 USING INDEX i4 (c=?)
|
||||
# 0|1|1|SCAN TABLE t1
|
||||
#
|
||||
det 5.11 "SELECT * FROM (SELECT * FROM t2 WHERE c=1), t1" {
|
||||
det 5.11 "SELECT a, b FROM (SELECT * FROM t2 WHERE c=1), t1" {
|
||||
0 0 0 {SEARCH TABLE t2 USING INDEX i4 (c=?)}
|
||||
0 1 1 {SCAN TABLE t1 USING COVERING INDEX i2}
|
||||
}
|
||||
@@ -496,7 +496,7 @@ det 5.11 "SELECT * FROM (SELECT * FROM t2 WHERE c=1), t1" {
|
||||
# 2|0|0|SCAN TABLE t2
|
||||
# 0|0|0|COMPOUND SUBQUERIES 1 AND 2 USING TEMP B-TREE (UNION)
|
||||
#
|
||||
det 5.12 "SELECT a FROM t1 UNION SELECT c FROM t2" {
|
||||
det 5.12 "SELECT a,b FROM t1 UNION SELECT c, 99 FROM t2" {
|
||||
1 0 0 {SCAN TABLE t1 USING COVERING INDEX i2}
|
||||
2 0 0 {SCAN TABLE t2 USING COVERING INDEX i4}
|
||||
0 0 0 {COMPOUND SUBQUERIES 1 AND 2 USING TEMP B-TREE (UNION)}
|
||||
@@ -509,7 +509,7 @@ det 5.12 "SELECT a FROM t1 UNION SELECT c FROM t2" {
|
||||
# 0|0|0|COMPOUND SUBQUERIES 1 AND 2 (EXCEPT)
|
||||
#
|
||||
det 5.13 "SELECT a FROM t1 EXCEPT SELECT d FROM t2 ORDER BY 1" {
|
||||
1 0 0 {SCAN TABLE t1 USING COVERING INDEX i2}
|
||||
1 0 0 {SCAN TABLE t1 USING COVERING INDEX i1}
|
||||
2 0 0 {SCAN TABLE t2}
|
||||
2 0 0 {USE TEMP B-TREE FOR ORDER BY}
|
||||
0 0 0 {COMPOUND SUBQUERIES 1 AND 2 (EXCEPT)}
|
||||
@@ -548,7 +548,7 @@ proc do_peqp_test {tn sql res} {
|
||||
}
|
||||
|
||||
do_peqp_test 6.1 {
|
||||
SELECT a FROM t1 EXCEPT SELECT d FROM t2 ORDER BY 1
|
||||
SELECT a, b FROM t1 EXCEPT SELECT d, 99 FROM t2 ORDER BY 1
|
||||
} [string trimleft {
|
||||
1 0 0 SCAN TABLE t1 USING COVERING INDEX i2
|
||||
2 0 0 SCAN TABLE t2
|
||||
@@ -563,8 +563,8 @@ do_peqp_test 6.1 {
|
||||
drop_all_tables
|
||||
|
||||
do_execsql_test 7.0 {
|
||||
CREATE TABLE t1(a, b);
|
||||
CREATE TABLE t2(a, b);
|
||||
CREATE TABLE t1(a INT, b INT, ex CHAR(100));
|
||||
CREATE TABLE t2(a INT, b INT, ex CHAR(100));
|
||||
CREATE INDEX i1 ON t2(a);
|
||||
}
|
||||
|
||||
@@ -577,12 +577,12 @@ det 7.2 "SELECT count(*) FROM t2" {
|
||||
}
|
||||
|
||||
do_execsql_test 7.3 {
|
||||
INSERT INTO t1 VALUES(1, 2);
|
||||
INSERT INTO t1 VALUES(3, 4);
|
||||
INSERT INTO t1(a,b) VALUES(1, 2);
|
||||
INSERT INTO t1(a,b) VALUES(3, 4);
|
||||
|
||||
INSERT INTO t2 VALUES(1, 2);
|
||||
INSERT INTO t2 VALUES(3, 4);
|
||||
INSERT INTO t2 VALUES(5, 6);
|
||||
INSERT INTO t2(a,b) VALUES(1, 2);
|
||||
INSERT INTO t2(a,b) VALUES(3, 4);
|
||||
INSERT INTO t2(a,b) VALUES(5, 6);
|
||||
|
||||
ANALYZE;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
# 2001 September 15
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library.
|
||||
#
|
||||
# This file implements tests for foreign keys.
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
set testprefix fkey7
|
||||
|
||||
ifcapable {!foreignkey} {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
do_execsql_test 1.1 {
|
||||
PRAGMA foreign_keys = 1;
|
||||
|
||||
CREATE TABLE s1(a PRIMARY KEY, b);
|
||||
CREATE TABLE par(a, b REFERENCES s1, c UNIQUE, PRIMARY KEY(a));
|
||||
|
||||
CREATE TABLE c1(a, b REFERENCES par);
|
||||
CREATE TABLE c2(a, b REFERENCES par);
|
||||
CREATE TABLE c3(a, b REFERENCES par(c));
|
||||
}
|
||||
|
||||
proc auth {op tbl args} {
|
||||
if {$op == "SQLITE_READ"} { set ::tbls($tbl) 1 }
|
||||
return "SQLITE_OK"
|
||||
}
|
||||
db auth auth
|
||||
db cache size 0
|
||||
proc do_tblsread_test {tn sql tbllist} {
|
||||
array unset ::tbls
|
||||
uplevel [list execsql $sql]
|
||||
uplevel [list do_test $tn {lsort [array names ::tbls]} $tbllist]
|
||||
}
|
||||
|
||||
do_tblsread_test 1.2 { UPDATE par SET b=? WHERE a=? } {par s1}
|
||||
do_tblsread_test 1.3 { UPDATE par SET a=? WHERE b=? } {c1 c2 par}
|
||||
do_tblsread_test 1.4 { UPDATE par SET c=? WHERE b=? } {c3 par}
|
||||
do_tblsread_test 1.5 { UPDATE par SET a=?,b=?,c=? WHERE b=? } {c1 c2 c3 par s1}
|
||||
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,84 @@
|
||||
# 2010 October 23
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# This file contains a very simple test to show that the deferred tokens
|
||||
# optimization is doing something.
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
source $testdir/malloc_common.tcl
|
||||
ifcapable !fts3||!fts4_deferred {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
set testprefix fts3defer3
|
||||
|
||||
set nDoclist 3204
|
||||
set nDoc 800
|
||||
|
||||
# Set up a database that contains 800 rows. Each row contains the document
|
||||
# "b b", except for the row with docid=200, which contains "a b". Hence
|
||||
# token "b" is extremely common and token "a" is not.
|
||||
#
|
||||
do_test 1.1 {
|
||||
execsql {
|
||||
CREATE VIRTUAL TABLE t1 USING fts4;
|
||||
BEGIN;
|
||||
}
|
||||
for {set i 1} {$i <= $nDoc} {incr i} {
|
||||
set document "b b"
|
||||
if {$i==200} { set document "a b" }
|
||||
execsql { INSERT INTO t1 (docid, content) VALUES($i, $document) }
|
||||
}
|
||||
execsql COMMIT
|
||||
} {}
|
||||
|
||||
# Check that the db contains two doclists. A small one for "a" and a
|
||||
# larger one for "b".
|
||||
#
|
||||
do_execsql_test 1.2 {
|
||||
SELECT blockid, length(block) FROM t1_segments;
|
||||
} [list 1 8 2 $nDoclist]
|
||||
|
||||
# Query for 'a b'. Although this test doesn't prove so, token "b" will
|
||||
# be deferred because of the very large associated doclist.
|
||||
#
|
||||
do_execsql_test 1.3 {
|
||||
SELECT docid, content FROM t1 WHERE t1 MATCH 'a b';
|
||||
} {200 {a b}}
|
||||
|
||||
# Zero out the doclist for token "b" within the database file. Now the
|
||||
# only queries that use token "b" that will work are those that defer
|
||||
# it. Any query that tries to use the doclist belonging to token "b"
|
||||
# will fail.
|
||||
#
|
||||
do_test 1.4 {
|
||||
set fd [db incrblob t1_segments block 2]
|
||||
puts -nonewline $fd [string repeat "\00" $nDoclist]
|
||||
close $fd
|
||||
} {}
|
||||
|
||||
# The first two queries succeed, as they defer token "b". The last one
|
||||
# fails, as it tries to load the corrupt doclist.
|
||||
#
|
||||
do_execsql_test 1.5 {
|
||||
SELECT docid, content FROM t1 WHERE t1 MATCH 'a b';
|
||||
} {200 {a b}}
|
||||
do_execsql_test 1.6 {
|
||||
SELECT count(*) FROM t1 WHERE t1 MATCH 'a b';
|
||||
} {1}
|
||||
do_catchsql_test 1.7 {
|
||||
SELECT count(*) FROM t1 WHERE t1 MATCH 'b';
|
||||
} {1 {database disk image is malformed}}
|
||||
|
||||
|
||||
finish_test
|
||||
+62
-1
@@ -16,6 +16,7 @@
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
set testprefix fts3snippet
|
||||
|
||||
# If SQLITE_ENABLE_FTS3 is not defined, omit this file.
|
||||
ifcapable !fts3 { finish_test ; return }
|
||||
@@ -138,7 +139,7 @@ foreach {DO_MALLOC_TEST enc} {
|
||||
|
||||
# Set variable $T to the test name prefix for this iteration of the loop.
|
||||
#
|
||||
set T "fts3snippet-$enc"
|
||||
set T "fts3snippet-1.$enc"
|
||||
|
||||
##########################################################################
|
||||
# Test the offset function.
|
||||
@@ -459,5 +460,65 @@ foreach {DO_MALLOC_TEST enc} {
|
||||
} {0 blob}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test an interaction between the snippet() function and OR clauses.
|
||||
#
|
||||
do_execsql_test 2.1 {
|
||||
CREATE VIRTUAL TABLE t2 USING fts4;
|
||||
INSERT INTO t2 VALUES('one two three four five');
|
||||
INSERT INTO t2 VALUES('two three four five one');
|
||||
INSERT INTO t2 VALUES('three four five one two');
|
||||
INSERT INTO t2 VALUES('four five one two three');
|
||||
INSERT INTO t2 VALUES('five one two three four');
|
||||
}
|
||||
|
||||
do_execsql_test 2.2 {
|
||||
SELECT snippet(t2, '[', ']') FROM t2 WHERE t2 MATCH 'one OR (four AND six)'
|
||||
} {
|
||||
{[one] two three [four] five}
|
||||
{two three [four] five [one]}
|
||||
{three [four] five [one] two}
|
||||
{[four] five [one] two three}
|
||||
{five [one] two three [four]}
|
||||
}
|
||||
|
||||
do_execsql_test 2.3 {
|
||||
SELECT snippet(t2, '[', ']') FROM t2
|
||||
WHERE t2 MATCH 'one OR (four AND six)'
|
||||
ORDER BY docid DESC
|
||||
} {
|
||||
{five [one] two three [four]}
|
||||
{[four] five [one] two three}
|
||||
{three [four] five [one] two}
|
||||
{two three [four] five [one]}
|
||||
{[one] two three [four] five}
|
||||
}
|
||||
|
||||
do_execsql_test 2.4 {
|
||||
INSERT INTO t2 VALUES('six');
|
||||
}
|
||||
|
||||
do_execsql_test 2.5 {
|
||||
SELECT snippet(t2, '[', ']') FROM t2 WHERE t2 MATCH 'one OR (four AND six)'
|
||||
} {
|
||||
{[one] two three [four] five}
|
||||
{two three [four] five [one]}
|
||||
{three [four] five [one] two}
|
||||
{[four] five [one] two three}
|
||||
{five [one] two three [four]}
|
||||
}
|
||||
|
||||
do_execsql_test 2.6 {
|
||||
SELECT snippet(t2, '[', ']') FROM t2
|
||||
WHERE t2 MATCH 'one OR (four AND six)'
|
||||
ORDER BY docid DESC
|
||||
} {
|
||||
{five [one] two three [four]}
|
||||
{[four] five [one] two three}
|
||||
{three [four] five [one] two}
|
||||
{two three [four] five [one]}
|
||||
{[one] two three [four] five}
|
||||
}
|
||||
|
||||
set sqlite_fts3_enable_parentheses 0
|
||||
finish_test
|
||||
|
||||
+7
-1545
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,116 @@
|
||||
# 2012 March 26
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#*************************************************************************
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
source $testdir/fts3_common.tcl
|
||||
set ::testprefix fts4docid
|
||||
|
||||
# If SQLITE_ENABLE_FTS3 is defined, omit this file.
|
||||
ifcapable !fts3 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
# Initialize a table with pseudo-randomly generated data.
|
||||
#
|
||||
do_execsql_test 1.0 { CREATE VIRTUAL TABLE t1 USING fts4; }
|
||||
do_test 1.1 {
|
||||
foreach {docid content} {
|
||||
0 {F N K B T I K V B A} 1 {D M J E S P H E L O}
|
||||
2 {W U T Q T Q T L H G} 3 {D W H M B R S Z B K}
|
||||
4 {F Q I N P Q J L Z D} 5 {J O Q E Y A O E L B}
|
||||
6 {O V R A C R K C Y H} 7 {Z J H T Q Q O R A G}
|
||||
8 {L K J W G D Y W B M} 9 {K E Y I A Q R Q T S}
|
||||
10 {N P H Y Z M R T I C} 11 {E X H O I S E S Z F}
|
||||
12 {B Y Q T J X C L L J} 13 {Q D C U U A Q E Z U}
|
||||
14 {S I T C J R X S J M} 15 {M X M K E X L H Q Y}
|
||||
16 {O W E I C H U Y S Y} 17 {P V V E M T H C C S}
|
||||
18 {L Y A M I E N M X O} 19 {S Y R U L S Q Y F P}
|
||||
20 {U J S T T J J S V X} 21 {T E I W P O V A A P}
|
||||
22 {W D K H D H F G O J} 23 {T X Y P G M J U I L}
|
||||
24 {F V X E B C N B K W} 25 {E B A Y N N T Z I C}
|
||||
26 {G E E B C P U D H G} 27 {J D J K N S B Q T M}
|
||||
28 {Q T G M D O D Y V G} 29 {P X W I W V P W Z G}
|
||||
} {
|
||||
execsql { INSERT INTO t1(docid, content) VALUES($docid, $content) }
|
||||
}
|
||||
} {}
|
||||
|
||||
# Quick test regarding affinites and the docid/rowid column.
|
||||
do_execsql_test 2.1.1 { SELECT docid FROM t1 WHERE docid = 5 } {5}
|
||||
do_execsql_test 2.1.2 { SELECT docid FROM t1 WHERE docid = '5' } {5}
|
||||
do_execsql_test 2.1.3 { SELECT docid FROM t1 WHERE docid = +5 } {5}
|
||||
do_execsql_test 2.1.4 { SELECT docid FROM t1 WHERE docid = +'5' } {5}
|
||||
do_execsql_test 2.1.5 { SELECT docid FROM t1 WHERE docid < 5 } {0 1 2 3 4}
|
||||
do_execsql_test 2.1.6 { SELECT docid FROM t1 WHERE docid < '5' } {0 1 2 3 4}
|
||||
|
||||
do_execsql_test 2.2.1 { SELECT rowid FROM t1 WHERE rowid = 5 } {5}
|
||||
do_execsql_test 2.2.2 { SELECT rowid FROM t1 WHERE rowid = '5' } {5}
|
||||
do_execsql_test 2.2.3 { SELECT rowid FROM t1 WHERE rowid = +5 } {5}
|
||||
do_execsql_test 2.2.4 { SELECT rowid FROM t1 WHERE rowid = +'5' } {5}
|
||||
do_execsql_test 2.2.5 { SELECT rowid FROM t1 WHERE rowid < 5 } {0 1 2 3 4}
|
||||
do_execsql_test 2.2.6 { SELECT rowid FROM t1 WHERE rowid < '5' } {0 1 2 3 4}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Now test a bunch of full-text queries featuring range constraints on
|
||||
# the docid field. Each query is run so that the range constraint:
|
||||
#
|
||||
# * is on the docid field,
|
||||
# * is on the docid field with a unary +,
|
||||
# * is on the rowid field,
|
||||
# * is on the rowid field with a unary +.
|
||||
#
|
||||
# Queries are run with both "ORDER BY docid DESC" and "ORDER BY docid ASC"
|
||||
# clauses.
|
||||
#
|
||||
foreach {tn where result} {
|
||||
1 {WHERE t1 MATCH 'O' AND xxx < 17} {1 5 6 7 11 16}
|
||||
2 {WHERE t1 MATCH 'O' AND xxx < 4123456789123456} {1 5 6 7 11 16 18 21 22 28}
|
||||
3 {WHERE t1 MATCH 'O' AND xxx < 1} {}
|
||||
4 {WHERE t1 MATCH 'O' AND xxx < -4123456789123456} {}
|
||||
|
||||
5 {WHERE t1 MATCH 'O' AND xxx > 17} {18 21 22 28}
|
||||
6 {WHERE t1 MATCH 'O' AND xxx > 4123456789123456} {}
|
||||
7 {WHERE t1 MATCH 'O' AND xxx > 1} {5 6 7 11 16 18 21 22 28}
|
||||
8 {WHERE t1 MATCH 'O' AND xxx > -4123456789123456} {1 5 6 7 11 16 18 21 22 28}
|
||||
|
||||
9 {WHERE t1 MATCH '"Q T"' AND xxx < 27} {2 9 12}
|
||||
10 {WHERE t1 MATCH '"Q T"' AND xxx <= 27} {2 9 12 27}
|
||||
11 {WHERE t1 MATCH '"Q T"' AND xxx > 27} {28}
|
||||
12 {WHERE t1 MATCH '"Q T"' AND xxx >= 27} {27 28}
|
||||
} {
|
||||
foreach {tn2 ref order} {
|
||||
1 docid "ORDER BY docid ASC"
|
||||
2 +docid "ORDER BY docid ASC"
|
||||
3 rowid "ORDER BY docid ASC"
|
||||
4 +rowid "ORDER BY docid ASC"
|
||||
|
||||
5 docid "ORDER BY docid DESC"
|
||||
6 +docid "ORDER BY docid DESC"
|
||||
7 rowid "ORDER BY docid DESC"
|
||||
8 +rowid "ORDER BY docid DESC"
|
||||
} {
|
||||
set w [string map "xxx $ref" $where]
|
||||
set q "SELECT docid FROM t1 $w $order"
|
||||
|
||||
if {$tn2<5} {
|
||||
set r [lsort -integer -increasing $result]
|
||||
} else {
|
||||
set r [lsort -integer -decreasing $result]
|
||||
}
|
||||
|
||||
do_execsql_test 3.$tn.$tn2 $q $r
|
||||
}
|
||||
}
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,53 @@
|
||||
# 2012 March 26
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#*************************************************************************
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
source $testdir/fts3_common.tcl
|
||||
set ::testprefix fts4incr
|
||||
|
||||
# If SQLITE_ENABLE_FTS3 is defined, omit this file.
|
||||
ifcapable !fts3 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
# Create the fts_kjv_genesis procedure which fills and FTS3/4 table
|
||||
# with the complete text of the Book of Genesis.
|
||||
#
|
||||
source $testdir/genesis.tcl
|
||||
|
||||
do_test 1.0 {
|
||||
execsql { CREATE VIRTUAL TABLE t1 USING fts4(words) }
|
||||
fts_kjv_genesis
|
||||
} {}
|
||||
|
||||
do_execsql_test 1.1 {
|
||||
SELECT min(docid), max(docid) FROM t1;
|
||||
} {1001001 1050026}
|
||||
|
||||
foreach {tn q res} {
|
||||
1 { SELECT count(*) FROM t1 WHERE t1 MATCH 'and' AND docid < 1010000} 224
|
||||
2 { SELECT count(*) FROM t1 WHERE t1 MATCH '"in the"' AND docid < 1010000} 47
|
||||
3 { SELECT count(*) FROM t1 WHERE t1 MATCH '"And God"' AND docid < 1010000} 33
|
||||
4 { SELECT count(*) FROM t1 WHERE t1
|
||||
MATCH '"land of canaan"' AND docid < 1030000 } 7
|
||||
} {
|
||||
foreach s {0 1} {
|
||||
execsql "INSERT INTO t1(t1) VALUES('test-no-incr-doclist=$s')"
|
||||
do_execsql_test 2.$tn.$s $q $res
|
||||
set t($s) [lindex [time [list execsql $q] 100] 0]
|
||||
}
|
||||
puts "with optimization: $t(0) without: $t(1)"
|
||||
}
|
||||
|
||||
finish_test
|
||||
@@ -438,4 +438,121 @@ do_execsql_test 8.2.3 {
|
||||
SELECT rowid FROM t4 WHERE t4 MATCH 'a';
|
||||
} {2 4}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
foreach {tn sql} {
|
||||
1 {
|
||||
CREATE VIRTUAL TABLE t5 USING fts4(tokenize=unicode61 [tokenchars= .]);
|
||||
CREATE VIRTUAL TABLE t6 USING fts4(
|
||||
tokenize=unicode61 [tokenchars=="] "tokenchars=[]");
|
||||
CREATE VIRTUAL TABLE t7 USING fts4(tokenize=unicode61 [separators=x\xC4]);
|
||||
}
|
||||
2 {
|
||||
CREATE VIRTUAL TABLE t5 USING fts4(tokenize=unicode61 "tokenchars= .");
|
||||
CREATE VIRTUAL TABLE t6 USING fts4(tokenize=unicode61 "tokenchars=[=""]");
|
||||
CREATE VIRTUAL TABLE t7 USING fts4(tokenize=unicode61 "separators=x\xC4");
|
||||
}
|
||||
3 {
|
||||
CREATE VIRTUAL TABLE t5 USING fts4(tokenize=unicode61 'tokenchars= .');
|
||||
CREATE VIRTUAL TABLE t6 USING fts4(tokenize=unicode61 'tokenchars=="[]');
|
||||
CREATE VIRTUAL TABLE t7 USING fts4(tokenize=unicode61 'separators=x\xC4');
|
||||
}
|
||||
4 {
|
||||
CREATE VIRTUAL TABLE t5 USING fts4(tokenize=unicode61 `tokenchars= .`);
|
||||
CREATE VIRTUAL TABLE t6 USING fts4(tokenize=unicode61 `tokenchars=[="]`);
|
||||
CREATE VIRTUAL TABLE t7 USING fts4(tokenize=unicode61 `separators=x\xC4`);
|
||||
}
|
||||
} {
|
||||
do_execsql_test 9.$tn.0 {
|
||||
DROP TABLE IF EXISTS t5;
|
||||
DROP TABLE IF EXISTS t5aux;
|
||||
DROP TABLE IF EXISTS t6;
|
||||
DROP TABLE IF EXISTS t6aux;
|
||||
DROP TABLE IF EXISTS t7;
|
||||
DROP TABLE IF EXISTS t7aux;
|
||||
}
|
||||
do_execsql_test 9.$tn.1 $sql
|
||||
|
||||
do_execsql_test 9.$tn.2 {
|
||||
CREATE VIRTUAL TABLE t5aux USING fts4aux(t5);
|
||||
INSERT INTO t5 VALUES('one two three/four.five.six');
|
||||
SELECT * FROM t5aux;
|
||||
} {
|
||||
four.five.six * 1 1 four.five.six 0 1 1
|
||||
{one two three} * 1 1 {one two three} 0 1 1
|
||||
}
|
||||
|
||||
do_execsql_test 9.$tn.3 {
|
||||
CREATE VIRTUAL TABLE t6aux USING fts4aux(t6);
|
||||
INSERT INTO t6 VALUES('alpha=beta"gamma/delta[epsilon]zeta');
|
||||
SELECT * FROM t6aux;
|
||||
} {
|
||||
{alpha=beta"gamma} * 1 1 {alpha=beta"gamma} 0 1 1
|
||||
{delta[epsilon]zeta} * 1 1 {delta[epsilon]zeta} 0 1 1
|
||||
}
|
||||
|
||||
do_execsql_test 9.$tn.4 {
|
||||
CREATE VIRTUAL TABLE t7aux USING fts4aux(t7);
|
||||
INSERT INTO t7 VALUES('alephxbeth\xC4gimel');
|
||||
SELECT * FROM t7aux;
|
||||
} {
|
||||
aleph * 1 1 aleph 0 1 1
|
||||
beth * 1 1 beth 0 1 1
|
||||
gimel * 1 1 gimel 0 1 1
|
||||
}
|
||||
}
|
||||
|
||||
# Check that multiple options are handled correctly.
|
||||
#
|
||||
do_execsql_test 10.1 {
|
||||
DROP TABLE IF EXISTS t1;
|
||||
CREATE VIRTUAL TABLE t1 USING fts4(tokenize=unicode61
|
||||
"tokenchars=xyz" "tokenchars=.=" "separators=.=" "separators=xy"
|
||||
"separators=a" "separators=a" "tokenchars=a" "tokenchars=a"
|
||||
);
|
||||
|
||||
INSERT INTO t1 VALUES('oneatwoxthreeyfour');
|
||||
INSERT INTO t1 VALUES('a.single=word');
|
||||
CREATE VIRTUAL TABLE t1aux USING fts4aux(t1);
|
||||
SELECT * FROM t1aux;
|
||||
} {
|
||||
.single=word * 1 1 .single=word 0 1 1
|
||||
four * 1 1 four 0 1 1
|
||||
one * 1 1 one 0 1 1
|
||||
three * 1 1 three 0 1 1
|
||||
two * 1 1 two 0 1 1
|
||||
}
|
||||
|
||||
# Test that case folding happens after tokenization, not before.
|
||||
#
|
||||
do_execsql_test 10.2 {
|
||||
DROP TABLE IF EXISTS t2;
|
||||
CREATE VIRTUAL TABLE t2 USING fts4(tokenize=unicode61 "separators=aB");
|
||||
INSERT INTO t2 VALUES('oneatwoBthree');
|
||||
INSERT INTO t2 VALUES('onebtwoAthree');
|
||||
CREATE VIRTUAL TABLE t2aux USING fts4aux(t2);
|
||||
SELECT * FROM t2aux;
|
||||
} {
|
||||
one * 1 1 one 0 1 1
|
||||
onebtwoathree * 1 1 onebtwoathree 0 1 1
|
||||
three * 1 1 three 0 1 1
|
||||
two * 1 1 two 0 1 1
|
||||
}
|
||||
|
||||
# Test that the tokenchars and separators options work with the
|
||||
# fts3tokenize table.
|
||||
#
|
||||
do_execsql_test 11.1 {
|
||||
CREATE VIRTUAL TABLE ft1 USING fts3tokenize(
|
||||
"unicode61", "tokenchars=@.", "separators=1234567890"
|
||||
);
|
||||
SELECT token FROM ft1 WHERE input = 'berlin@street123sydney.road';
|
||||
} {
|
||||
berlin@street sydney.road
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+1560
File diff suppressed because it is too large
Load Diff
@@ -37,6 +37,13 @@ do_test index6-1.1 {
|
||||
}
|
||||
} {14 20 ok}
|
||||
|
||||
# Make sure the count(*) optimization works correctly with
|
||||
# partial indices. Ticket [a5c8ed66cae16243be6] 2013-10-03.
|
||||
#
|
||||
do_execsql_test index6-1.1.1 {
|
||||
SELECT count(*) FROM t1;
|
||||
} {20}
|
||||
|
||||
# Error conditions during parsing...
|
||||
#
|
||||
do_test index6-1.2 {
|
||||
|
||||
@@ -97,6 +97,24 @@ do_faultsim_test 6.2 -faults oom* -body {
|
||||
} -test {
|
||||
faultsim_test_result [list 0 {1 2}]
|
||||
}
|
||||
ifcapable stat3 {
|
||||
do_test 6.3-prep {
|
||||
execsql {
|
||||
PRAGMA writable_schema = 1;
|
||||
CREATE TABLE sqlite_stat4 AS
|
||||
SELECT tbl, idx, neq, nlt, ndlt, sqlite_record(sample) AS sample
|
||||
FROM sqlite_stat3;
|
||||
}
|
||||
} {}
|
||||
do_faultsim_test 6.3 -faults oom* -body {
|
||||
execsql {
|
||||
ANALYZE sqlite_master;
|
||||
SELECT rowid FROM t1 WHERE a='abc' AND b<'y';
|
||||
}
|
||||
} -test {
|
||||
faultsim_test_result [list 0 {1 2}]
|
||||
}
|
||||
}
|
||||
|
||||
# Ensure that no file descriptors were leaked.
|
||||
do_test malloc-99.X {
|
||||
|
||||
@@ -311,6 +311,14 @@ test_suite "coverage-pager" -description {
|
||||
walfault.test walbak.test journal2.test tkt-9d68c883.test
|
||||
}
|
||||
|
||||
test_suite "coverage-analyze" -description {
|
||||
Coverage tests for file analyze.c.
|
||||
} -files {
|
||||
analyze3.test analyze4.test analyze5.test analyze6.test
|
||||
analyze7.test analyze8.test analyze9.test analyzeA.test
|
||||
analyze.test analyzeB.test mallocA.test
|
||||
}
|
||||
|
||||
|
||||
lappend ::testsuitelist xxx
|
||||
#-------------------------------------------------------------------------
|
||||
@@ -501,7 +509,7 @@ test_suite "utf16" -description {
|
||||
} -files {
|
||||
alter.test alter3.test
|
||||
analyze.test analyze3.test analyze4.test analyze5.test analyze6.test
|
||||
analyze7.test analyze8.test analyze9.test analyzeA.test
|
||||
analyze7.test analyze8.test analyze9.test analyzeA.test analyzeB.test
|
||||
auth.test bind.test blob.test capi2.test capi3.test collate1.test
|
||||
collate2.test collate3.test collate4.test collate5.test collate6.test
|
||||
conflict.test date.test delete.test expr.test fkey1.test func.test
|
||||
|
||||
+3
-3
@@ -574,7 +574,7 @@ ifcapable {foreignkey} {
|
||||
execsql {
|
||||
pragma index_list(t3);
|
||||
}
|
||||
} {0 sqlite_autoindex_t3_1 1}
|
||||
} {/0 sqlite_autoindex_t3_1 1 \d+/}
|
||||
}
|
||||
ifcapable {!foreignkey} {
|
||||
execsql {CREATE TABLE t3(a,b UNIQUE)}
|
||||
@@ -647,7 +647,7 @@ do_test pragma-7.1.1 {
|
||||
execsql {
|
||||
pragma index_list(t3);
|
||||
}
|
||||
} {0 t3i1 0 1 sqlite_autoindex_t3_1 1}
|
||||
} {/0 t3i1 0 \d+ 1 sqlite_autoindex_t3_1 1 \d+/}
|
||||
do_test pragma-7.1.2 {
|
||||
execsql {
|
||||
pragma index_list(t3_bogus);
|
||||
@@ -1661,7 +1661,7 @@ do_test 23.3 {
|
||||
CREATE INDEX i3 ON t1(d,b,c);
|
||||
}
|
||||
db2 eval {PRAGMA index_list(t1)}
|
||||
} {0 i3 0 1 i2 0 2 i1 0}
|
||||
} {/0 i3 0 \d+ 1 i2 0 \d+ 2 i1 0 \d+/}
|
||||
do_test 23.4 {
|
||||
db eval {
|
||||
ALTER TABLE t1 ADD COLUMN e;
|
||||
|
||||
+1
-1
@@ -361,7 +361,7 @@ foreach file [glob -nocomplain quota-test-A*] {
|
||||
do_test quota-4.4.1 {
|
||||
set ::quota {}
|
||||
sqlite3_quota_set $::quotagroup 10000 quota_callback
|
||||
file delete -force ./quota-test-A1.db ./quota-test-A2.db
|
||||
forcedelete ./quota-test-A1.db ./quota-test-A2.db
|
||||
sqlite3 db ./quota-test-A1.db
|
||||
db eval {
|
||||
CREATE TABLE t1(x);
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ db close
|
||||
sqlite3_quota_initialize "" 1
|
||||
|
||||
foreach dir {quota2a/x1 quota2a/x2 quota2a quota2b quota2c} {
|
||||
file delete -force $dir
|
||||
forcedelete $dir
|
||||
}
|
||||
foreach dir {quota2a quota2a/x1 quota2a/x2 quota2b quota2c} {
|
||||
file mkdir $dir
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
set testprefix shared3
|
||||
db close
|
||||
|
||||
ifcapable !shared_cache {
|
||||
@@ -103,5 +104,39 @@ db1 close
|
||||
db2 close
|
||||
db3 close
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# At one point this was causing a faulty assert to fail.
|
||||
#
|
||||
forcedelete test.db
|
||||
sqlite3 db test.db
|
||||
sqlite3 db2 test.db
|
||||
do_execsql_test 3.1 {
|
||||
PRAGMA auto_vacuum = 2;
|
||||
CREATE TABLE t1(x, y);
|
||||
INSERT INTO t1 VALUES(randomblob(500), randomblob(500));
|
||||
INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
|
||||
INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
|
||||
INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
|
||||
INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
|
||||
INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
|
||||
INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
|
||||
INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM t1;
|
||||
}
|
||||
do_test 3.2 {
|
||||
execsql { SELECT count(*) FROM sqlite_master } db2
|
||||
} {1}
|
||||
do_execsql_test 3.3 {
|
||||
BEGIN;
|
||||
DELETE FROM t1 WHERE 1;
|
||||
PRAGMA incremental_vacuum;
|
||||
} {}
|
||||
do_test 3.4 {
|
||||
execsql { SELECT count(*) FROM sqlite_master } db2
|
||||
} {1}
|
||||
do_test 3.5 {
|
||||
execsql { COMMIT }
|
||||
} {}
|
||||
|
||||
sqlite3_enable_shared_cache $::enable_shared_cache
|
||||
finish_test
|
||||
|
||||
|
||||
+29
-1
@@ -13,6 +13,7 @@
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
set testprefix sharedlock
|
||||
db close
|
||||
|
||||
ifcapable !shared_cache {
|
||||
@@ -47,8 +48,35 @@ do_test sharedlock-1.2 {
|
||||
set res
|
||||
} {1 one 2 two 3 three}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test that a write-lock is taken on a table when its entire contents
|
||||
# are deleted using the OP_Clear optimization.
|
||||
#
|
||||
foreach {tn delete_sql} {
|
||||
1 { DELETE FROM t2 WHERE 1 }
|
||||
2 { DELETE FROM t2 }
|
||||
} {
|
||||
do_execsql_test 2.1 {
|
||||
DROP TABLE IF EXISTS t2;
|
||||
CREATE TABLE t2(x, y);
|
||||
INSERT INTO t2 VALUES(1, 2);
|
||||
INSERT INTO t2 VALUES(3, 4);
|
||||
}
|
||||
|
||||
do_test 2.2 { execsql { SELECT * FROM t2 } db2 } {1 2 3 4}
|
||||
|
||||
do_execsql_test 2.3 " BEGIN; $delete_sql; "
|
||||
|
||||
do_test 2.4 {
|
||||
catchsql { SELECT * FROM t2 } db2
|
||||
} {1 {database table is locked: t2}}
|
||||
|
||||
do_execsql_test 2.5 COMMIT
|
||||
}
|
||||
|
||||
|
||||
db close
|
||||
db2 close
|
||||
|
||||
sqlite3_enable_shared_cache $::enable_shared_cache
|
||||
finish_test
|
||||
|
||||
+13
-1
@@ -536,7 +536,7 @@ do_test shell1-3.19.1 {
|
||||
catchcmd "test.db" ".read"
|
||||
} {1 {Error: unknown command or invalid arguments: "read". Enter ".help" for help}}
|
||||
do_test shell1-3.19.2 {
|
||||
file delete -force FOO
|
||||
forcedelete FOO
|
||||
catchcmd "test.db" ".read FOO"
|
||||
} {1 {Error: cannot open "FOO"}}
|
||||
do_test shell1-3.19.3 {
|
||||
@@ -722,7 +722,11 @@ do_test shell1-3-31.1 {
|
||||
# Test the output of the ".dump" command
|
||||
#
|
||||
do_test shell1-4.1 {
|
||||
db close
|
||||
forcedelete test.db
|
||||
sqlite3 db test.db
|
||||
db eval {
|
||||
PRAGMA encoding=UTF16;
|
||||
CREATE TABLE t1(x);
|
||||
INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
|
||||
}
|
||||
@@ -752,6 +756,14 @@ INSERT INTO t1 VALUES(X'807f');}}
|
||||
# Test the output of ".mode tcl"
|
||||
#
|
||||
do_test shell1-4.3 {
|
||||
db close
|
||||
forcedelete test.db
|
||||
sqlite3 db test.db
|
||||
db eval {
|
||||
PRAGMA encoding=UTF8;
|
||||
CREATE TABLE t1(x);
|
||||
INSERT INTO t1 VALUES(null), (''), (1), (2.25), ('hello'), (x'807f');
|
||||
}
|
||||
catchcmd test.db ".mode tcl\nselect * from t1;"
|
||||
} {0 {""
|
||||
""
|
||||
|
||||
+7
-7
@@ -42,7 +42,7 @@ sqlite3 db test.db
|
||||
# Reported on mailing list by Ken Zalewski.
|
||||
# Ticket [aeff892c57].
|
||||
do_test shell2-1.1.1 {
|
||||
file delete -force foo.db
|
||||
forcedelete foo.db
|
||||
set rc [ catchcmd "-batch foo.db" "CREATE TABLE t1(a);" ]
|
||||
set fexist [file exist foo.db]
|
||||
list $rc $fexist
|
||||
@@ -81,7 +81,7 @@ do_test shell2-1.3 {
|
||||
# Test with echo off
|
||||
# NB. whitespace is important
|
||||
do_test shell2-1.4.1 {
|
||||
file delete -force foo.db
|
||||
forcedelete foo.db
|
||||
catchcmd "foo.db" {CREATE TABLE foo(a);
|
||||
INSERT INTO foo(a) VALUES(1);
|
||||
SELECT * FROM foo;}
|
||||
@@ -90,7 +90,7 @@ SELECT * FROM foo;}
|
||||
# Test with echo on using command line option
|
||||
# NB. whitespace is important
|
||||
do_test shell2-1.4.2 {
|
||||
file delete -force foo.db
|
||||
forcedelete foo.db
|
||||
catchcmd "-echo foo.db" {CREATE TABLE foo(a);
|
||||
INSERT INTO foo(a) VALUES(1);
|
||||
SELECT * FROM foo;}
|
||||
@@ -102,7 +102,7 @@ SELECT * FROM foo;
|
||||
# Test with echo on using dot command
|
||||
# NB. whitespace is important
|
||||
do_test shell2-1.4.3 {
|
||||
file delete -force foo.db
|
||||
forcedelete foo.db
|
||||
catchcmd "foo.db" {.echo ON
|
||||
CREATE TABLE foo(a);
|
||||
INSERT INTO foo(a) VALUES(1);
|
||||
@@ -116,7 +116,7 @@ SELECT * FROM foo;
|
||||
# turning off mid- processing.
|
||||
# NB. whitespace is important
|
||||
do_test shell2-1.4.4 {
|
||||
file delete -force foo.db
|
||||
forcedelete foo.db
|
||||
catchcmd "foo.db" {.echo ON
|
||||
CREATE TABLE foo(a);
|
||||
.echo OFF
|
||||
@@ -130,7 +130,7 @@ SELECT * FROM foo;}
|
||||
# multiple commands per line.
|
||||
# NB. whitespace is important
|
||||
do_test shell2-1.4.5 {
|
||||
file delete -force foo.db
|
||||
forcedelete foo.db
|
||||
catchcmd "foo.db" {.echo ON
|
||||
CREATE TABLE foo1(a);
|
||||
INSERT INTO foo1(a) VALUES(1);
|
||||
@@ -161,7 +161,7 @@ SELECT * FROM foo2;
|
||||
# multiple commands per line.
|
||||
# NB. whitespace is important
|
||||
do_test shell2-1.4.6 {
|
||||
file delete -force foo.db
|
||||
forcedelete foo.db
|
||||
catchcmd "foo.db" {.echo ON
|
||||
.headers ON
|
||||
CREATE TABLE foo1(a);
|
||||
|
||||
+2
-2
@@ -40,7 +40,7 @@ sqlite3 db test.db
|
||||
|
||||
# Run SQL statement from command line
|
||||
do_test shell3-1.1 {
|
||||
file delete -force foo.db
|
||||
forcedelete foo.db
|
||||
set rc [ catchcmd "foo.db \"CREATE TABLE t1(a);\"" ]
|
||||
set fexist [file exist foo.db]
|
||||
list $rc $fexist
|
||||
@@ -70,7 +70,7 @@ do_test shell3-1.7 {
|
||||
|
||||
# Run SQL file from command line
|
||||
do_test shell3-2.1 {
|
||||
file delete -force foo.db
|
||||
forcedelete foo.db
|
||||
set rc [ catchcmd "foo.db" "CREATE TABLE t1(a);" ]
|
||||
set fexist [file exist foo.db]
|
||||
list $rc $fexist
|
||||
|
||||
+5
-5
@@ -32,7 +32,6 @@ if {![file executable $CLI]} {
|
||||
}
|
||||
db close
|
||||
forcedelete test.db test.db-journal test.db-wal
|
||||
sqlite3 db test.db
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Test cases shell5-1.*: Basic handling of the .import and .separator commands.
|
||||
@@ -81,14 +80,14 @@ do_test shell5-1.3.2 {
|
||||
|
||||
# import file doesn't exist
|
||||
do_test shell5-1.4.1 {
|
||||
file delete -force FOO
|
||||
forcedelete FOO
|
||||
set res [catchcmd "test.db" {CREATE TABLE t1(a, b);
|
||||
.import FOO t1}]
|
||||
} {1 {Error: cannot open "FOO"}}
|
||||
|
||||
# empty import file
|
||||
do_test shell5-1.4.2 {
|
||||
file delete -force shell5.csv
|
||||
forcedelete shell5.csv
|
||||
set in [open shell5.csv w]
|
||||
close $in
|
||||
set res [catchcmd "test.db" {.import shell5.csv t1
|
||||
@@ -231,7 +230,7 @@ SELECT COUNT(*) FROM t3;}]
|
||||
# Inport from a pipe. (Unix only, as it requires "awk")
|
||||
if {$tcl_platform(platform)=="unix"} {
|
||||
do_test shell5-1.8 {
|
||||
file delete -force test.db
|
||||
forcedelete test.db
|
||||
catchcmd test.db {.mode csv
|
||||
.import "|awk 'END{print \"x,y\";for(i=1;i<=5;i++){print i \",this is \" i}}'" t1
|
||||
SELECT * FROM t1;}
|
||||
@@ -245,6 +244,7 @@ SELECT * FROM t1;}
|
||||
# Import columns containing quoted strings
|
||||
do_test shell5-1.9 {
|
||||
set out [open shell5.csv w]
|
||||
fconfigure $out -translation lf
|
||||
puts $out {1,"",11}
|
||||
puts $out {2,"x",22}
|
||||
puts $out {3,"""",33}
|
||||
@@ -258,7 +258,7 @@ do_test shell5-1.9 {
|
||||
puts $out {"""",11,121}
|
||||
puts $out {"hello",12,132}
|
||||
close $out
|
||||
file delete -force test.db
|
||||
forcedelete test.db
|
||||
catchcmd test.db {.mode csv
|
||||
CREATE TABLE t1(a,b,c);
|
||||
.import shell5.csv t1
|
||||
|
||||
+20
-3
@@ -24,10 +24,27 @@ ifcapable !integrityck {
|
||||
return
|
||||
}
|
||||
|
||||
sqlite3_soft_heap_limit -1
|
||||
sqlite3_soft_heap_limit 0
|
||||
sqlite3_soft_heap_limit 5000
|
||||
do_test softheap1-1.0 {
|
||||
execsql {PRAGMA soft_heap_limit}
|
||||
} [sqlite3_soft_heap_limit -1]
|
||||
do_test softheap1-1.1 {
|
||||
execsql {PRAGMA soft_heap_limit=123456; PRAGMA soft_heap_limit;}
|
||||
} {123456 123456}
|
||||
do_test softheap1-1.2 {
|
||||
sqlite3_soft_heap_limit -1
|
||||
} {123456}
|
||||
do_test softheap1-1.3 {
|
||||
execsql {PRAGMA soft_heap_limit(-1); PRAGMA soft_heap_limit;}
|
||||
} {123456 123456}
|
||||
do_test softheap1-1.4 {
|
||||
execsql {PRAGMA soft_heap_limit(0); PRAGMA soft_heap_limit;}
|
||||
} {0 0}
|
||||
|
||||
sqlite3_soft_heap_limit 5000
|
||||
do_test softheap1-2.0 {
|
||||
execsql {PRAGMA soft_heap_limit}
|
||||
} {5000}
|
||||
do_test softheap1-2.1 {
|
||||
execsql {
|
||||
PRAGMA auto_vacuum=1;
|
||||
CREATE TABLE t1(x);
|
||||
|
||||
@@ -95,6 +95,9 @@ do_test 1.10 {
|
||||
do_execsql_test 1.11 {
|
||||
SELECT next_char('re','vocab','w');
|
||||
} {a}
|
||||
do_execsql_test 1.11sub {
|
||||
SELECT next_char('re','(SELECT w AS x FROM vocab)','x');
|
||||
} {a}
|
||||
do_execsql_test 1.12 {
|
||||
SELECT next_char('r','vocab','w');
|
||||
} {ae}
|
||||
|
||||
+1
-1
@@ -245,7 +245,7 @@ do_test subquery-2.5.3.2 {
|
||||
EXPLAIN QUERY PLAN
|
||||
SELECT * FROM t4 WHERE x IN (SELECT a FROM t3);
|
||||
}
|
||||
} {/SCAN TABLE t4 /}
|
||||
} {~/t4i/}
|
||||
do_test subquery-2.5.4 {
|
||||
execsql {
|
||||
DROP TABLE t3;
|
||||
|
||||
@@ -18,23 +18,23 @@ source $testdir/tester.tcl
|
||||
|
||||
do_test tkt-78e04-1.0 {
|
||||
execsql {
|
||||
CREATE TABLE ""("" UNIQUE);
|
||||
CREATE TABLE ""("" UNIQUE, x CHAR(100));
|
||||
CREATE TABLE t2(x);
|
||||
INSERT INTO "" VALUES(1);
|
||||
INSERT INTO ""("") VALUES(1);
|
||||
INSERT INTO t2 VALUES(2);
|
||||
SELECT * FROM "", t2;
|
||||
}
|
||||
} {1 2}
|
||||
} {1 {} 2}
|
||||
do_test tkt-78e04-1.1 {
|
||||
catchsql {
|
||||
INSERT INTO "" VALUES(1);
|
||||
INSERT INTO ""("") VALUES(1);
|
||||
}
|
||||
} {1 {column is not unique}}
|
||||
do_test tkt-78e04-1.2 {
|
||||
execsql {
|
||||
PRAGMA table_info("");
|
||||
}
|
||||
} {0 {} {} 0 {} 0}
|
||||
} {0 {} {} 0 {} 0 1 x CHAR(100) 0 {} 0}
|
||||
do_test tkt-78e04-1.3 {
|
||||
execsql {
|
||||
CREATE INDEX i1 ON ""("" COLLATE nocase);
|
||||
@@ -42,7 +42,7 @@ do_test tkt-78e04-1.3 {
|
||||
} {}
|
||||
do_test tkt-78e04-1.4 {
|
||||
execsql {
|
||||
EXPLAIN QUERY PLAN SELECT * FROM "" WHERE "" LIKE 'abc%';
|
||||
EXPLAIN QUERY PLAN SELECT "" FROM "" WHERE "" LIKE 'abc%';
|
||||
}
|
||||
} {0 0 0 {SCAN TABLE USING COVERING INDEX i1}}
|
||||
do_test tkt-78e04-1.5 {
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
# 2013-09-05
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# TPC-H test queries.
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
set testprefix tpch01
|
||||
|
||||
do_execsql_test tpch01-1.0 {
|
||||
CREATE TABLE NATION ( N_NATIONKEY INTEGER NOT NULL,
|
||||
N_NAME CHAR(25) NOT NULL,
|
||||
N_REGIONKEY INTEGER NOT NULL,
|
||||
N_COMMENT VARCHAR(152));
|
||||
CREATE TABLE REGION ( R_REGIONKEY INTEGER NOT NULL,
|
||||
R_NAME CHAR(25) NOT NULL,
|
||||
R_COMMENT VARCHAR(152));
|
||||
CREATE TABLE PART ( P_PARTKEY INTEGER NOT NULL,
|
||||
P_NAME VARCHAR(55) NOT NULL,
|
||||
P_MFGR CHAR(25) NOT NULL,
|
||||
P_BRAND CHAR(10) NOT NULL,
|
||||
P_TYPE VARCHAR(25) NOT NULL,
|
||||
P_SIZE INTEGER NOT NULL,
|
||||
P_CONTAINER CHAR(10) NOT NULL,
|
||||
P_RETAILPRICE DECIMAL(15,2) NOT NULL,
|
||||
P_COMMENT VARCHAR(23) NOT NULL );
|
||||
CREATE TABLE SUPPLIER ( S_SUPPKEY INTEGER NOT NULL,
|
||||
S_NAME CHAR(25) NOT NULL,
|
||||
S_ADDRESS VARCHAR(40) NOT NULL,
|
||||
S_NATIONKEY INTEGER NOT NULL,
|
||||
S_PHONE CHAR(15) NOT NULL,
|
||||
S_ACCTBAL DECIMAL(15,2) NOT NULL,
|
||||
S_COMMENT VARCHAR(101) NOT NULL);
|
||||
CREATE TABLE PARTSUPP ( PS_PARTKEY INTEGER NOT NULL,
|
||||
PS_SUPPKEY INTEGER NOT NULL,
|
||||
PS_AVAILQTY INTEGER NOT NULL,
|
||||
PS_SUPPLYCOST DECIMAL(15,2) NOT NULL,
|
||||
PS_COMMENT VARCHAR(199) NOT NULL );
|
||||
CREATE TABLE CUSTOMER ( C_CUSTKEY INTEGER NOT NULL,
|
||||
C_NAME VARCHAR(25) NOT NULL,
|
||||
C_ADDRESS VARCHAR(40) NOT NULL,
|
||||
C_NATIONKEY INTEGER NOT NULL,
|
||||
C_PHONE CHAR(15) NOT NULL,
|
||||
C_ACCTBAL DECIMAL(15,2) NOT NULL,
|
||||
C_MKTSEGMENT CHAR(10) NOT NULL,
|
||||
C_COMMENT VARCHAR(117) NOT NULL);
|
||||
CREATE TABLE ORDERS ( O_ORDERKEY INTEGER NOT NULL,
|
||||
O_CUSTKEY INTEGER NOT NULL,
|
||||
O_ORDERSTATUS CHAR(1) NOT NULL,
|
||||
O_TOTALPRICE DECIMAL(15,2) NOT NULL,
|
||||
O_ORDERDATE DATE NOT NULL,
|
||||
O_ORDERPRIORITY CHAR(15) NOT NULL,
|
||||
O_CLERK CHAR(15) NOT NULL,
|
||||
O_SHIPPRIORITY INTEGER NOT NULL,
|
||||
O_COMMENT VARCHAR(79) NOT NULL);
|
||||
CREATE TABLE LINEITEM ( L_ORDERKEY INTEGER NOT NULL,
|
||||
L_PARTKEY INTEGER NOT NULL,
|
||||
L_SUPPKEY INTEGER NOT NULL,
|
||||
L_LINENUMBER INTEGER NOT NULL,
|
||||
L_QUANTITY DECIMAL(15,2) NOT NULL,
|
||||
L_EXTENDEDPRICE DECIMAL(15,2) NOT NULL,
|
||||
L_DISCOUNT DECIMAL(15,2) NOT NULL,
|
||||
L_TAX DECIMAL(15,2) NOT NULL,
|
||||
L_RETURNFLAG CHAR(1) NOT NULL,
|
||||
L_LINESTATUS CHAR(1) NOT NULL,
|
||||
L_SHIPDATE DATE NOT NULL,
|
||||
L_COMMITDATE DATE NOT NULL,
|
||||
L_RECEIPTDATE DATE NOT NULL,
|
||||
L_SHIPINSTRUCT CHAR(25) NOT NULL,
|
||||
L_SHIPMODE CHAR(10) NOT NULL,
|
||||
L_COMMENT VARCHAR(44) NOT NULL);
|
||||
CREATE INDEX npki on nation(N_NATIONKEY);
|
||||
CREATE INDEX rpki on region(R_REGIONKEY);
|
||||
CREATE INDEX ppki on part(P_PARTKEY);
|
||||
CREATE INDEX spki on supplier(S_SUPPKEY);
|
||||
CREATE INDEX pspki on partsupp(PS_PARTKEY, PS_SUPPKEY);
|
||||
CREATE INDEX cpki on customer(C_CUSTKEY);
|
||||
CREATE INDEX opki on orders(O_ORDERKEY);
|
||||
CREATE INDEX lpki on lineitem(L_ORDERKEY, L_LINENUMBER);
|
||||
CREATE INDEX nrki on nation(n_regionkey);
|
||||
CREATE INDEX snki on supplier(s_nationkey);
|
||||
CREATE INDEX cnki on customer(c_nationkey);
|
||||
CREATE INDEX ocki on orders(O_CUSTKEY);
|
||||
CREATE INDEX odi on orders(O_ORDERDATE);
|
||||
CREATE INDEX lpki2 on lineitem(L_PARTKEY);
|
||||
CREATE INDEX lski on lineitem(L_SUPPKEY);
|
||||
CREATE INDEX lsdi on lineitem(L_SHIPDATE);
|
||||
CREATE INDEX lcdi on lineitem(L_COMMITDATE);
|
||||
CREATE INDEX lrdi on lineitem(L_RECEIPTDATE);
|
||||
CREATE INDEX bootleg_nni on nation(N_NAME);
|
||||
CREATE INDEX bootleg_psi on part(p_size);
|
||||
CREATE INDEX bootleg_pti on part(p_type);
|
||||
ANALYZE sqlite_master;
|
||||
INSERT INTO sqlite_stat1 VALUES('LINEITEM','lrdi','600572 236');
|
||||
INSERT INTO sqlite_stat1 VALUES('LINEITEM','lcdi','600572 244');
|
||||
INSERT INTO sqlite_stat1 VALUES('LINEITEM','lsdi','600572 238');
|
||||
INSERT INTO sqlite_stat1 VALUES('LINEITEM','lski','600572 601');
|
||||
INSERT INTO sqlite_stat1 VALUES('LINEITEM','lpki2','600572 31');
|
||||
INSERT INTO sqlite_stat1 VALUES('LINEITEM','lpki','600572 5 1');
|
||||
INSERT INTO sqlite_stat1 VALUES('ORDERS','odi','150000 63');
|
||||
INSERT INTO sqlite_stat1 VALUES('ORDERS','ocki','150000 15');
|
||||
INSERT INTO sqlite_stat1 VALUES('ORDERS','opki','150000 1');
|
||||
INSERT INTO sqlite_stat1 VALUES('CUSTOMER','cnki','15000 600');
|
||||
INSERT INTO sqlite_stat1 VALUES('CUSTOMER','cpki','15000 1');
|
||||
INSERT INTO sqlite_stat1 VALUES('PARTSUPP','pspki','80000 4 1');
|
||||
INSERT INTO sqlite_stat1 VALUES('SUPPLIER','snki','1000 40');
|
||||
INSERT INTO sqlite_stat1 VALUES('SUPPLIER','spki','1000 1');
|
||||
INSERT INTO sqlite_stat1 VALUES('PART','bootleg_pti','20000 134');
|
||||
INSERT INTO sqlite_stat1 VALUES('PART','bootleg_psi','20000 400');
|
||||
INSERT INTO sqlite_stat1 VALUES('PART','ppki','20000 1');
|
||||
INSERT INTO sqlite_stat1 VALUES('REGION','rpki','5 1');
|
||||
INSERT INTO sqlite_stat1 VALUES('NATION','bootleg_nni','25 1');
|
||||
INSERT INTO sqlite_stat1 VALUES('NATION','nrki','25 5');
|
||||
INSERT INTO sqlite_stat1 VALUES('NATION','npki','25 1');
|
||||
ANALYZE sqlite_master;
|
||||
} {}
|
||||
|
||||
do_test tpch01-1.1 {
|
||||
unset -nocomplain ::eqpres
|
||||
set ::eqpres [db eval {EXPLAIN QUERY PLAN
|
||||
select
|
||||
o_year,
|
||||
sum(case
|
||||
when nation = 'EGYPT' then volume
|
||||
else 0
|
||||
end) / sum(volume) as mkt_share
|
||||
from
|
||||
(
|
||||
select
|
||||
strftime('%Y', o_orderdate) as o_year,
|
||||
l_extendedprice * (1 - l_discount) as volume,
|
||||
n2.n_name as nation
|
||||
from
|
||||
part,
|
||||
supplier,
|
||||
lineitem,
|
||||
orders,
|
||||
customer,
|
||||
nation n1,
|
||||
nation n2,
|
||||
region
|
||||
where
|
||||
p_partkey = l_partkey
|
||||
and s_suppkey = l_suppkey
|
||||
and l_orderkey = o_orderkey
|
||||
and o_custkey = c_custkey
|
||||
and c_nationkey = n1.n_nationkey
|
||||
and n1.n_regionkey = r_regionkey
|
||||
and r_name = 'MIDDLE EAST'
|
||||
and s_nationkey = n2.n_nationkey
|
||||
and o_orderdate between '1995-01-01' and '1996-12-31'
|
||||
and p_type = 'LARGE PLATED STEEL'
|
||||
) as all_nations
|
||||
group by
|
||||
o_year
|
||||
order by
|
||||
o_year;}]
|
||||
set ::eqpres
|
||||
} {/0 0 0 {SEARCH TABLE part USING INDEX bootleg_pti .P_TYPE=..} 0 1 2 {SEARCH TABLE lineitem USING INDEX lpki2 .L_PARTKEY=..}.*/}
|
||||
do_test tpch01-1.1b {
|
||||
set ::eqpres
|
||||
} {/.* customer .* nation AS n1 .* nation AS n2 .*/}
|
||||
|
||||
do_eqp_test tpch01-1.2 {
|
||||
select
|
||||
c_custkey, c_name, sum(l_extendedprice * (1 - l_discount)) as revenue,
|
||||
c_acctbal, n_name, c_address, c_phone, c_comment
|
||||
from
|
||||
customer, orders, lineitem, nation
|
||||
where
|
||||
c_custkey = o_custkey and l_orderkey = o_orderkey
|
||||
and o_orderdate >= '1994-08-01' and o_orderdate < date('1994-08-01', '+3 month')
|
||||
and l_returnflag = 'R' and c_nationkey = n_nationkey
|
||||
group by
|
||||
c_custkey, c_name, c_acctbal, c_phone, n_name, c_address, c_comment
|
||||
order by
|
||||
revenue desc;
|
||||
} {0 0 1 {SEARCH TABLE orders USING INDEX odi (O_ORDERDATE>? AND O_ORDERDATE<?)} 0 1 0 {SEARCH TABLE customer USING INDEX cpki (C_CUSTKEY=?)} 0 2 3 {SEARCH TABLE nation USING INDEX npki (N_NATIONKEY=?)} 0 3 2 {SEARCH TABLE lineitem USING INDEX lpki (L_ORDERKEY=?)} 0 0 0 {USE TEMP B-TREE FOR GROUP BY} 0 0 0 {USE TEMP B-TREE FOR ORDER BY}}
|
||||
@@ -0,0 +1,112 @@
|
||||
# 2009 December 29
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice', here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# This file tests the effects of SQL variable references embedded in
|
||||
# triggers. If the user attempts to create such a trigger, it is an
|
||||
# error. However, if an existing trigger definition is read from
|
||||
# the sqlite_master table, the variable reference always evaluates
|
||||
# to NULL.
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
ifcapable {!trigger} {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
set testprefix triggerE
|
||||
|
||||
do_execsql_test 1.0 {
|
||||
CREATE TABLE t1(a, b);
|
||||
CREATE TABLE t2(c, d);
|
||||
CREATE TABLE t3(e, f);
|
||||
}
|
||||
|
||||
# forcedelete test.db2
|
||||
# do_execsql_test 1.1 {
|
||||
# ATTACH 'test.db2' AS aux;
|
||||
# CREATE TABLE aux.t4(x);
|
||||
# INSERT INTO aux.t4 VALUES(5);
|
||||
#
|
||||
# CREATE TRIGGER tr1 AFTER INSERT ON t1 WHEN new.a IN (SELECT x FROM aux.t4)
|
||||
# BEGIN
|
||||
# SELECT 1;
|
||||
# END;
|
||||
# }
|
||||
# do_execsql_test 1.2 { INSERT INTO t1 VALUES(1,1); }
|
||||
# do_execsql_test 1.3 { INSERT INTO t1 VALUES(5,5); }
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Attempt to create various triggers that use bound variables.
|
||||
#
|
||||
set errmsg "trigger cannot use variables"
|
||||
foreach {tn defn} {
|
||||
1 { AFTER INSERT ON t1 WHEN new.a = ? BEGIN SELECT 1; END; }
|
||||
2 { BEFORE DELETE ON t1 BEGIN SELECT ?; END; }
|
||||
3 { BEFORE DELETE ON t1 BEGIN SELECT * FROM (SELECT * FROM (SELECT ?)); END; }
|
||||
5 { BEFORE DELETE ON t1 BEGIN SELECT * FROM t2 GROUP BY ?; END; }
|
||||
6 { BEFORE DELETE ON t1 BEGIN SELECT * FROM t2 LIMIT ?; END; }
|
||||
7 { BEFORE DELETE ON t1 BEGIN SELECT * FROM t2 ORDER BY ?; END; }
|
||||
8 { BEFORE UPDATE ON t1 BEGIN UPDATE t2 SET c = ?; END; }
|
||||
9 { BEFORE UPDATE ON t1 BEGIN UPDATE t2 SET c = 1 WHERE d = ?; END; }
|
||||
} {
|
||||
catchsql {drop trigger tr1}
|
||||
do_catchsql_test 1.1.$tn "CREATE TRIGGER tr1 $defn" [list 1 $errmsg]
|
||||
do_catchsql_test 1.2.$tn "CREATE TEMP TRIGGER tr1 $defn" [list 1 $errmsg]
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# Test that variable references within trigger definitions loaded from
|
||||
# the sqlite_master table are automatically converted to NULL.
|
||||
#
|
||||
do_execsql_test 2.1 {
|
||||
PRAGMA writable_schema = 1;
|
||||
INSERT INTO sqlite_master VALUES('trigger', 'tr1', 't1', 0,
|
||||
'CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
|
||||
INSERT INTO t2 VALUES(?1, ?2);
|
||||
END'
|
||||
);
|
||||
|
||||
INSERT INTO sqlite_master VALUES('trigger', 'tr2', 't3', 0,
|
||||
'CREATE TRIGGER tr2 AFTER INSERT ON t3 WHEN ?1 IS NULL BEGIN
|
||||
UPDATE t2 SET c=d WHERE c IS ?2;
|
||||
END'
|
||||
);
|
||||
}
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
|
||||
do_execsql_test 2.2.1 {
|
||||
INSERT INTO t1 VALUES(1, 2);
|
||||
SELECT * FROM t2;
|
||||
} {{} {}}
|
||||
do_test 2.2.2 {
|
||||
set one 3
|
||||
execsql {
|
||||
DELETE FROM t2;
|
||||
INSERT INTO t1 VALUES($one, ?1);
|
||||
SELECT * FROM t2;
|
||||
}
|
||||
} {{} {}}
|
||||
do_execsql_test 2.2.3 { SELECT * FROM t1 } {1 2 3 3}
|
||||
|
||||
do_execsql_test 2.3 {
|
||||
DELETE FROM t2;
|
||||
INSERT INTO t2 VALUES('x', 'y');
|
||||
INSERT INTO t2 VALUES(NULL, 'z');
|
||||
INSERT INTO t3 VALUES(1, 2);
|
||||
SELECT * FROM t3;
|
||||
SELECT * FROM t2;
|
||||
} {1 2 x y z z}
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
+32
-3
@@ -1125,9 +1125,9 @@ do_test where-13.12 {
|
||||
if {[permutation] != "no_optimization"} {
|
||||
do_test where-14.1 {
|
||||
execsql {
|
||||
CREATE TABLE t8(a INTEGER PRIMARY KEY, b TEXT UNIQUE);
|
||||
INSERT INTO t8 VALUES(1,'one');
|
||||
INSERT INTO t8 VALUES(4,'four');
|
||||
CREATE TABLE t8(a INTEGER PRIMARY KEY, b TEXT UNIQUE, c CHAR(100));
|
||||
INSERT INTO t8(a,b) VALUES(1,'one');
|
||||
INSERT INTO t8(a,b) VALUES(4,'four');
|
||||
}
|
||||
cksort {
|
||||
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.a, y.b
|
||||
@@ -1304,4 +1304,33 @@ do_test where-17.5 {
|
||||
}
|
||||
} {42 1 43 1}
|
||||
|
||||
# Ticket [be84e357c035d068135f20bcfe82761bbf95006b] 2013-09-03
|
||||
# Segfault during query involving LEFT JOIN column in the ORDER BY clause.
|
||||
#
|
||||
do_execsql_test where-18.1 {
|
||||
CREATE TABLE t181(a);
|
||||
CREATE TABLE t182(b,c);
|
||||
INSERT INTO t181 VALUES(1);
|
||||
SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY c IS NULL;
|
||||
} {1}
|
||||
do_execsql_test where-18.2 {
|
||||
SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY +c;
|
||||
} {1}
|
||||
do_execsql_test where-18.3 {
|
||||
SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY c;
|
||||
} {1}
|
||||
do_execsql_test where-18.4 {
|
||||
INSERT INTO t181 VALUES(1),(1),(1),(1);
|
||||
SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY +c;
|
||||
} {1}
|
||||
do_execsql_test where-18.5 {
|
||||
INSERT INTO t181 VALUES(2);
|
||||
SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY c IS NULL, +a;
|
||||
} {1 2}
|
||||
do_execsql_test where-18.6 {
|
||||
INSERT INTO t181 VALUES(2);
|
||||
SELECT DISTINCT a FROM t181 LEFT JOIN t182 ON a=b ORDER BY +a, +c IS NULL;
|
||||
} {1 2}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
+22
-19
@@ -314,9 +314,9 @@ if {[permutation] != "no_optimization"} {
|
||||
#
|
||||
do_test where2-6.7 {
|
||||
execsql {
|
||||
CREATE TABLE t2249a(a TEXT UNIQUE);
|
||||
CREATE TABLE t2249a(a TEXT UNIQUE, x CHAR(100));
|
||||
CREATE TABLE t2249b(b INTEGER);
|
||||
INSERT INTO t2249a VALUES('0123');
|
||||
INSERT INTO t2249a(a) VALUES('0123');
|
||||
INSERT INTO t2249b VALUES(123);
|
||||
}
|
||||
queryplan {
|
||||
@@ -324,7 +324,7 @@ do_test where2-6.7 {
|
||||
-- will attempt to convert to NUMERIC before the comparison.
|
||||
-- They will thus compare equal.
|
||||
--
|
||||
SELECT * FROM t2249b CROSS JOIN t2249a WHERE a=b;
|
||||
SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE a=b;
|
||||
}
|
||||
} {123 0123 nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
|
||||
do_test where2-6.9 {
|
||||
@@ -332,13 +332,13 @@ do_test where2-6.9 {
|
||||
-- The + operator removes affinity from the rhs. No conversions
|
||||
-- occur and the comparison is false. The result is an empty set.
|
||||
--
|
||||
SELECT * FROM t2249b CROSS JOIN t2249a WHERE a=+b;
|
||||
SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE a=+b;
|
||||
}
|
||||
} {nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
|
||||
do_test where2-6.9.2 {
|
||||
# The same thing but with the expression flipped around.
|
||||
queryplan {
|
||||
SELECT * FROM t2249b CROSS JOIN t2249a WHERE +b=a
|
||||
SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE +b=a
|
||||
}
|
||||
} {nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
|
||||
do_test where2-6.10 {
|
||||
@@ -346,32 +346,32 @@ do_test where2-6.10 {
|
||||
-- Use + on both sides of the comparison to disable indices
|
||||
-- completely. Make sure we get the same result.
|
||||
--
|
||||
SELECT * FROM t2249b CROSS JOIN t2249a WHERE +a=+b;
|
||||
SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE +a=+b;
|
||||
}
|
||||
} {nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
|
||||
do_test where2-6.11 {
|
||||
# This will not attempt the OR optimization because of the a=b
|
||||
# comparison.
|
||||
queryplan {
|
||||
SELECT * FROM t2249b CROSS JOIN t2249a WHERE a=b OR a='hello';
|
||||
SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE a=b OR a='hello';
|
||||
}
|
||||
} {123 0123 nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
|
||||
do_test where2-6.11.2 {
|
||||
# Permutations of the expression terms.
|
||||
queryplan {
|
||||
SELECT * FROM t2249b CROSS JOIN t2249a WHERE b=a OR a='hello';
|
||||
SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE b=a OR a='hello';
|
||||
}
|
||||
} {123 0123 nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
|
||||
do_test where2-6.11.3 {
|
||||
# Permutations of the expression terms.
|
||||
queryplan {
|
||||
SELECT * FROM t2249b CROSS JOIN t2249a WHERE 'hello'=a OR b=a;
|
||||
SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE 'hello'=a OR b=a;
|
||||
}
|
||||
} {123 0123 nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
|
||||
do_test where2-6.11.4 {
|
||||
# Permutations of the expression terms.
|
||||
queryplan {
|
||||
SELECT * FROM t2249b CROSS JOIN t2249a WHERE a='hello' OR b=a;
|
||||
SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE a='hello' OR b=a;
|
||||
}
|
||||
} {123 0123 nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
|
||||
ifcapable explain&&subquery {
|
||||
@@ -385,7 +385,7 @@ ifcapable explain&&subquery {
|
||||
# the OR optimization to be used again. The result is now an empty
|
||||
# set, the same as in where2-6.9.
|
||||
queryplan {
|
||||
SELECT * FROM t2249b CROSS JOIN t2249a WHERE a=+b OR a='hello';
|
||||
SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE a=+b OR a='hello';
|
||||
}
|
||||
} {nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
|
||||
do_test where2-6.12.2 {
|
||||
@@ -393,7 +393,7 @@ ifcapable explain&&subquery {
|
||||
# the OR optimization to be used again. The result is now an empty
|
||||
# set, the same as in where2-6.9.
|
||||
queryplan {
|
||||
SELECT * FROM t2249b CROSS JOIN t2249a WHERE a='hello' OR +b=a;
|
||||
SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE a='hello' OR +b=a;
|
||||
}
|
||||
} {nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
|
||||
do_test where2-6.12.3 {
|
||||
@@ -401,14 +401,14 @@ ifcapable explain&&subquery {
|
||||
# the OR optimization to be used again. The result is now an empty
|
||||
# set, the same as in where2-6.9.
|
||||
queryplan {
|
||||
SELECT * FROM t2249b CROSS JOIN t2249a WHERE +b=a OR a='hello';
|
||||
SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE +b=a OR a='hello';
|
||||
}
|
||||
} {nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
|
||||
do_test where2-6.13 {
|
||||
# The addition of +a on the second term disabled the OR optimization.
|
||||
# But we should still get the same empty-set result as in where2-6.9.
|
||||
queryplan {
|
||||
SELECT * FROM t2249b CROSS JOIN t2249a WHERE a=+b OR +a='hello';
|
||||
SELECT b,a FROM t2249b CROSS JOIN t2249a WHERE a=+b OR +a='hello';
|
||||
}
|
||||
} {nosort t2249b * t2249a sqlite_autoindex_t2249a_1}
|
||||
}
|
||||
@@ -417,7 +417,7 @@ ifcapable explain&&subquery {
|
||||
# to make sure the OR optimizer can recognize them all.
|
||||
do_test where2-6.20 {
|
||||
queryplan {
|
||||
SELECT * FROM t2249a x CROSS JOIN t2249a y WHERE x.a=y.a
|
||||
SELECT x.a, y.a FROM t2249a x CROSS JOIN t2249a y WHERE x.a=y.a
|
||||
}
|
||||
} {0123 0123 nosort x sqlite_autoindex_t2249a_1 y sqlite_autoindex_t2249a_1}
|
||||
ifcapable explain&&subquery {
|
||||
@@ -428,17 +428,20 @@ ifcapable explain&&subquery {
|
||||
#
|
||||
do_test where2-6.21 {
|
||||
queryplan {
|
||||
SELECT * FROM t2249a x CROSS JOIN t2249a y WHERE x.a=y.a OR y.a='hello'
|
||||
SELECT x.a,y.a FROM t2249a x CROSS JOIN t2249a y
|
||||
WHERE x.a=y.a OR y.a='hello'
|
||||
}
|
||||
} {0123 0123 nosort x sqlite_autoindex_t2249a_1 y sqlite_autoindex_t2249a_1}
|
||||
do_test where2-6.22 {
|
||||
queryplan {
|
||||
SELECT * FROM t2249a x CROSS JOIN t2249a y WHERE y.a=x.a OR y.a='hello'
|
||||
SELECT x.a,y.a FROM t2249a x CROSS JOIN t2249a y
|
||||
WHERE y.a=x.a OR y.a='hello'
|
||||
}
|
||||
} {0123 0123 nosort x sqlite_autoindex_t2249a_1 y sqlite_autoindex_t2249a_1}
|
||||
do_test where2-6.23 {
|
||||
queryplan {
|
||||
SELECT * FROM t2249a x CROSS JOIN t2249a y WHERE y.a='hello' OR x.a=y.a
|
||||
SELECT x.a,y.a FROM t2249a x CROSS JOIN t2249a y
|
||||
WHERE y.a='hello' OR x.a=y.a
|
||||
}
|
||||
} {0123 0123 nosort x sqlite_autoindex_t2249a_1 y sqlite_autoindex_t2249a_1}
|
||||
}
|
||||
@@ -703,7 +706,7 @@ do_test where2-11.4 {
|
||||
# the OR clause scores slightly better on an inner loop.
|
||||
if {[permutation] != "no_optimization"} {
|
||||
do_execsql_test where2-12.1 {
|
||||
CREATE TABLE t12(x INTEGER PRIMARY KEY, y);
|
||||
CREATE TABLE t12(x INTEGER PRIMARY KEY, y INT, z CHAR(100));
|
||||
CREATE INDEX t12y ON t12(y);
|
||||
EXPLAIN QUERY PLAN
|
||||
SELECT a.x, b.x
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
# 2013-09-05
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# Test cases for query planning decisions and the unlikely() and
|
||||
# likelihood() functions.
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
do_execsql_test whereG-1.0 {
|
||||
CREATE TABLE composer(
|
||||
cid INTEGER PRIMARY KEY,
|
||||
cname TEXT
|
||||
);
|
||||
CREATE TABLE album(
|
||||
aid INTEGER PRIMARY KEY,
|
||||
aname TEXT
|
||||
);
|
||||
CREATE TABLE track(
|
||||
tid INTEGER PRIMARY KEY,
|
||||
cid INTEGER REFERENCES composer,
|
||||
aid INTEGER REFERENCES album,
|
||||
title TEXT
|
||||
);
|
||||
CREATE INDEX track_i1 ON track(cid);
|
||||
CREATE INDEX track_i2 ON track(aid);
|
||||
INSERT INTO composer VALUES(1, 'W. A. Mozart');
|
||||
INSERT INTO composer VALUES(2, 'Beethoven');
|
||||
INSERT INTO composer VALUES(3, 'Thomas Tallis');
|
||||
INSERT INTO composer VALUES(4, 'Joseph Hayden');
|
||||
INSERT INTO composer VALUES(5, 'Thomas Weelkes');
|
||||
INSERT INTO composer VALUES(6, 'J. S. Bach');
|
||||
INSERT INTO composer VALUES(7, 'Orlando Gibbons');
|
||||
INSERT INTO composer VALUES(8, 'Josquin des Prés');
|
||||
INSERT INTO composer VALUES(9, 'Byrd');
|
||||
INSERT INTO composer VALUES(10, 'Francis Poulenc');
|
||||
INSERT INTO composer VALUES(11, 'Mendelsshon');
|
||||
INSERT INTO composer VALUES(12, 'Zoltán Kodály');
|
||||
INSERT INTO composer VALUES(13, 'Handel');
|
||||
INSERT INTO album VALUES(100, 'Kodály: Missa Brevis');
|
||||
INSERT INTO album VALUES(101, 'Messiah');
|
||||
INSERT INTO album VALUES(102, 'Missa Brevis in D-, K.65');
|
||||
INSERT INTO album VALUES(103, 'The complete English anthems');
|
||||
INSERT INTO album VALUES(104, 'Mass in B Minor, BWV 232');
|
||||
INSERT INTO track VALUES(10005, 12, 100, 'Sanctus');
|
||||
INSERT INTO track VALUES(10007, 12, 100, 'Agnus Dei');
|
||||
INSERT INTO track VALUES(10115, 13, 101, 'Surely He Hath Borne Our Griefs');
|
||||
INSERT INTO track VALUES(10129, 13, 101, 'Since By Man Came Death');
|
||||
INSERT INTO track VALUES(10206, 1, 102, 'Agnus Dei');
|
||||
INSERT INTO track VALUES(10301, 3, 103, 'If Ye Love Me');
|
||||
INSERT INTO track VALUES(10402, 6, 104, 'Domine Deus');
|
||||
INSERT INTO track VALUES(10403, 6, 104, 'Qui tollis');
|
||||
} {}
|
||||
do_eqp_test whereG-1.1 {
|
||||
SELECT DISTINCT aname
|
||||
FROM album, composer, track
|
||||
WHERE unlikely(cname LIKE '%bach%')
|
||||
AND composer.cid=track.cid
|
||||
AND album.aid=track.aid;
|
||||
} {/.*composer.*track.*album.*/}
|
||||
do_execsql_test whereG-1.2 {
|
||||
SELECT DISTINCT aname
|
||||
FROM album, composer, track
|
||||
WHERE unlikely(cname LIKE '%bach%')
|
||||
AND composer.cid=track.cid
|
||||
AND album.aid=track.aid;
|
||||
} {{Mass in B Minor, BWV 232}}
|
||||
|
||||
do_eqp_test whereG-1.3 {
|
||||
SELECT DISTINCT aname
|
||||
FROM album, composer, track
|
||||
WHERE likelihood(cname LIKE '%bach%', 0.5)
|
||||
AND composer.cid=track.cid
|
||||
AND album.aid=track.aid;
|
||||
} {/.*track.*composer.*album.*/}
|
||||
do_execsql_test whereG-1.4 {
|
||||
SELECT DISTINCT aname
|
||||
FROM album, composer, track
|
||||
WHERE likelihood(cname LIKE '%bach%', 0.5)
|
||||
AND composer.cid=track.cid
|
||||
AND album.aid=track.aid;
|
||||
} {{Mass in B Minor, BWV 232}}
|
||||
|
||||
do_eqp_test whereG-1.5 {
|
||||
SELECT DISTINCT aname
|
||||
FROM album, composer, track
|
||||
WHERE cname LIKE '%bach%'
|
||||
AND composer.cid=track.cid
|
||||
AND album.aid=track.aid;
|
||||
} {/.*track.*composer.*album.*/}
|
||||
do_execsql_test whereG-1.6 {
|
||||
SELECT DISTINCT aname
|
||||
FROM album, composer, track
|
||||
WHERE cname LIKE '%bach%'
|
||||
AND composer.cid=track.cid
|
||||
AND album.aid=track.aid;
|
||||
} {{Mass in B Minor, BWV 232}}
|
||||
|
||||
do_eqp_test whereG-1.7 {
|
||||
SELECT DISTINCT aname
|
||||
FROM album, composer, track
|
||||
WHERE cname LIKE '%bach%'
|
||||
AND unlikely(composer.cid=track.cid)
|
||||
AND unlikely(album.aid=track.aid);
|
||||
} {/.*track.*composer.*album.*/}
|
||||
do_execsql_test whereG-1.8 {
|
||||
SELECT DISTINCT aname
|
||||
FROM album, composer, track
|
||||
WHERE cname LIKE '%bach%'
|
||||
AND unlikely(composer.cid=track.cid)
|
||||
AND unlikely(album.aid=track.aid);
|
||||
} {{Mass in B Minor, BWV 232}}
|
||||
|
||||
do_test whereG-2.1 {
|
||||
catchsql {
|
||||
SELECT DISTINCT aname
|
||||
FROM album, composer, track
|
||||
WHERE likelihood(cname LIKE '%bach%', -0.01)
|
||||
AND composer.cid=track.cid
|
||||
AND album.aid=track.aid;
|
||||
}
|
||||
} {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}}
|
||||
do_test whereG-2.2 {
|
||||
catchsql {
|
||||
SELECT DISTINCT aname
|
||||
FROM album, composer, track
|
||||
WHERE likelihood(cname LIKE '%bach%', 1.01)
|
||||
AND composer.cid=track.cid
|
||||
AND album.aid=track.aid;
|
||||
}
|
||||
} {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}}
|
||||
do_test whereG-2.3 {
|
||||
catchsql {
|
||||
SELECT DISTINCT aname
|
||||
FROM album, composer, track
|
||||
WHERE likelihood(cname LIKE '%bach%', track.cid)
|
||||
AND composer.cid=track.cid
|
||||
AND album.aid=track.aid;
|
||||
}
|
||||
} {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}}
|
||||
|
||||
# Commuting a term of the WHERE clause should not change the query plan
|
||||
#
|
||||
do_execsql_test whereG-3.0 {
|
||||
CREATE TABLE a(a1 PRIMARY KEY, a2);
|
||||
CREATE TABLE b(b1 PRIMARY KEY, b2);
|
||||
} {}
|
||||
do_eqp_test whereG-3.1 {
|
||||
SELECT * FROM a, b WHERE b1=a1 AND a2=5;
|
||||
} {/.*SCAN TABLE a.*SEARCH TABLE b USING INDEX .*b_1 .b1=..*/}
|
||||
do_eqp_test whereG-3.2 {
|
||||
SELECT * FROM a, b WHERE a1=b1 AND a2=5;
|
||||
} {/.*SCAN TABLE a.*SEARCH TABLE b USING INDEX .*b_1 .b1=..*/}
|
||||
do_eqp_test whereG-3.3 {
|
||||
SELECT * FROM a, b WHERE a2=5 AND b1=a1;
|
||||
} {/.*SCAN TABLE a.*SEARCH TABLE b USING INDEX .*b_1 .b1=..*/}
|
||||
do_eqp_test whereG-3.4 {
|
||||
SELECT * FROM a, b WHERE a2=5 AND a1=b1;
|
||||
} {/.*SCAN TABLE a.*SEARCH TABLE b USING INDEX .*b_1 .b1=..*/}
|
||||
|
||||
|
||||
finish_test
|
||||
+16
-3
@@ -203,8 +203,8 @@ SET TOOLPATH=%gawk.exe_PATH%;%tclsh85.exe_PATH%
|
||||
%_VECHO% ToolPath = '%TOOLPATH%'
|
||||
|
||||
REM
|
||||
REM NOTE: Check for MSVC 2012 because the Windows SDK directory handling is
|
||||
REM slightly different for that version.
|
||||
REM NOTE: Check for MSVC 2012/2013 because the Windows SDK directory handling
|
||||
REM is slightly different for those versions.
|
||||
REM
|
||||
IF "%VisualStudioVersion%" == "11.0" (
|
||||
REM
|
||||
@@ -214,6 +214,14 @@ IF "%VisualStudioVersion%" == "11.0" (
|
||||
IF NOT DEFINED NSDKLIBPATH (
|
||||
SET SET_NSDKLIBPATH=1
|
||||
)
|
||||
) ELSE IF "%VisualStudioVersion%" == "12.0" (
|
||||
REM
|
||||
REM NOTE: If the Windows SDK library path has already been set, do not set
|
||||
REM it to something else later on.
|
||||
REM
|
||||
IF NOT DEFINED NSDKLIBPATH (
|
||||
SET SET_NSDKLIBPATH=1
|
||||
)
|
||||
) ELSE (
|
||||
CALL :fn_UnsetVariable SET_NSDKLIBPATH
|
||||
)
|
||||
@@ -351,7 +359,12 @@ FOR %%P IN (%PLATFORMS%) DO (
|
||||
CALL :fn_AppendVariable NSDKLIBPATH \lib\x86
|
||||
) ELSE IF DEFINED WindowsSdkDir (
|
||||
CALL :fn_CopyVariable WindowsSdkDir NSDKLIBPATH
|
||||
CALL :fn_AppendVariable NSDKLIBPATH \lib\win8\um\x86
|
||||
|
||||
IF "%VisualStudioVersion%" == "12.0" (
|
||||
CALL :fn_AppendVariable NSDKLIBPATH \lib\winv6.3\um\x86
|
||||
) ELSE (
|
||||
CALL :fn_AppendVariable NSDKLIBPATH \lib\win8\um\x86
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
** 2013-10-01
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
**
|
||||
** This program implements a high-speed version of the VACUUM command.
|
||||
** It repacks an SQLite database to remove as much unused space as
|
||||
** possible and to relocate content sequentially in the file.
|
||||
**
|
||||
** This program runs faster and uses less temporary disk space than the
|
||||
** built-in VACUUM command. On the other hand, this program has a number
|
||||
** of important restrictions relative to the built-in VACUUM command.
|
||||
**
|
||||
** (1) The caller must ensure that no other processes are accessing the
|
||||
** database file while the vacuum is taking place. The usual SQLite
|
||||
** file locking is insufficient for this. The caller must use
|
||||
** external means to make sure only this one routine is reading and
|
||||
** writing the database.
|
||||
**
|
||||
** (2) Database reconfiguration such as page size or auto_vacuum changes
|
||||
** are not supported by this utility.
|
||||
**
|
||||
** (3) The database file might be renamed if a power loss or crash
|
||||
** occurs at just the wrong moment. Recovery must be prepared to
|
||||
** to deal with the possibly changed filename.
|
||||
**
|
||||
** This program is intended as a *Demonstration Only*. The intent of this
|
||||
** program is to provide example code that application developers can use
|
||||
** when creating similar functionality in their applications.
|
||||
**
|
||||
** To compile this program:
|
||||
**
|
||||
** cc fast_vacuum.c sqlite3.c
|
||||
**
|
||||
** Add whatever linker options are required. (Example: "-ldl -lpthread").
|
||||
** Then to run the program:
|
||||
**
|
||||
** ./a.out file-to-vacuum
|
||||
**
|
||||
*/
|
||||
#include "sqlite3.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
** Finalize a prepared statement. If an error has occurred, print the
|
||||
** error message and exit.
|
||||
*/
|
||||
static void vacuumFinalize(sqlite3_stmt *pStmt){
|
||||
sqlite3 *db = sqlite3_db_handle(pStmt);
|
||||
int rc = sqlite3_finalize(pStmt);
|
||||
if( rc ){
|
||||
fprintf(stderr, "finalize error: %s\n", sqlite3_errmsg(db));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Execute zSql on database db. The SQL text is printed to standard
|
||||
** output. If an error occurs, print an error message and exit the
|
||||
** process.
|
||||
*/
|
||||
static void execSql(sqlite3 *db, const char *zSql){
|
||||
sqlite3_stmt *pStmt;
|
||||
if( !zSql ){
|
||||
fprintf(stderr, "out of memory!\n");
|
||||
exit(1);
|
||||
}
|
||||
printf("%s;\n", zSql);
|
||||
if( SQLITE_OK!=sqlite3_prepare(db, zSql, -1, &pStmt, 0) ){
|
||||
fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
|
||||
exit(1);
|
||||
}
|
||||
sqlite3_step(pStmt);
|
||||
vacuumFinalize(pStmt);
|
||||
}
|
||||
|
||||
/*
|
||||
** Execute zSql on database db. The zSql statement returns exactly
|
||||
** one column. Execute this return value as SQL on the same database.
|
||||
**
|
||||
** The zSql statement is printed on standard output prior to being
|
||||
** run. If any errors occur, an error is printed and the process
|
||||
** exits.
|
||||
*/
|
||||
static void execExecSql(sqlite3 *db, const char *zSql){
|
||||
sqlite3_stmt *pStmt;
|
||||
int rc;
|
||||
|
||||
printf("%s;\n", zSql);
|
||||
rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
|
||||
if( rc!=SQLITE_OK ){
|
||||
fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
|
||||
exit(1);
|
||||
}
|
||||
while( SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
execSql(db, (char*)sqlite3_column_text(pStmt, 0));
|
||||
}
|
||||
vacuumFinalize(pStmt);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv){
|
||||
sqlite3 *db; /* Connection to the database file */
|
||||
int rc; /* Return code from SQLite interface calls */
|
||||
sqlite3_uint64 r; /* A random number */
|
||||
const char *zDbToVacuum; /* Database to be vacuumed */
|
||||
char *zBackupDb; /* Backup copy of the original database */
|
||||
char *zTempDb; /* Temporary database */
|
||||
char *zSql; /* An SQL statement */
|
||||
|
||||
if( argc!=2 ){
|
||||
fprintf(stderr, "Usage: %s DATABASE\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Identify the database file to be vacuumed and open it.
|
||||
*/
|
||||
zDbToVacuum = argv[1];
|
||||
printf("-- open database file \"%s\"\n", zDbToVacuum);
|
||||
rc = sqlite3_open(zDbToVacuum, &db);
|
||||
if( rc ){
|
||||
fprintf(stderr, "%s: %s\n", zDbToVacuum, sqlite3_errstr(rc));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Create names for two other files. zTempDb will be a new database
|
||||
** into which we construct a vacuumed copy of zDbToVacuum. zBackupDb
|
||||
** will be a new name for zDbToVacuum after it is vacuumed.
|
||||
*/
|
||||
sqlite3_randomness(sizeof(r), &r);
|
||||
zTempDb = sqlite3_mprintf("%s-vacuum-%016llx", zDbToVacuum, r);
|
||||
zBackupDb = sqlite3_mprintf("%s-backup-%016llx", zDbToVacuum, r);
|
||||
|
||||
/* Attach the zTempDb database to the database connection.
|
||||
*/
|
||||
zSql = sqlite3_mprintf("ATTACH '%q' AS vacuum_db;", zTempDb);
|
||||
execSql(db, zSql);
|
||||
sqlite3_free(zSql);
|
||||
|
||||
/* TODO:
|
||||
** Set the page_size and auto_vacuum mode for zTempDb here, if desired.
|
||||
*/
|
||||
|
||||
/* The vacuum will occur inside of a transaction. Set writable_schema
|
||||
** to ON so that we can directly update the sqlite_master table in the
|
||||
** zTempDb database.
|
||||
*/
|
||||
execSql(db, "PRAGMA writable_schema=ON");
|
||||
execSql(db, "BEGIN");
|
||||
|
||||
|
||||
/* Query the schema of the main database. Create a mirror schema
|
||||
** in the temporary database.
|
||||
*/
|
||||
execExecSql(db,
|
||||
"SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14) "
|
||||
" FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence'"
|
||||
" AND rootpage>0"
|
||||
);
|
||||
execExecSql(db,
|
||||
"SELECT 'CREATE INDEX vacuum_db.' || substr(sql,14)"
|
||||
" FROM sqlite_master WHERE sql LIKE 'CREATE INDEX %'"
|
||||
);
|
||||
execExecSql(db,
|
||||
"SELECT 'CREATE UNIQUE INDEX vacuum_db.' || substr(sql,21) "
|
||||
" FROM sqlite_master WHERE sql LIKE 'CREATE UNIQUE INDEX %'"
|
||||
);
|
||||
|
||||
/* Loop through the tables in the main database. For each, do
|
||||
** an "INSERT INTO vacuum_db.xxx SELECT * FROM main.xxx;" to copy
|
||||
** the contents to the temporary database.
|
||||
*/
|
||||
execExecSql(db,
|
||||
"SELECT 'INSERT INTO vacuum_db.' || quote(name) "
|
||||
"|| ' SELECT * FROM main.' || quote(name) "
|
||||
"FROM main.sqlite_master "
|
||||
"WHERE type = 'table' AND name!='sqlite_sequence' "
|
||||
" AND rootpage>0"
|
||||
);
|
||||
|
||||
/* Copy over the sequence table
|
||||
*/
|
||||
execExecSql(db,
|
||||
"SELECT 'DELETE FROM vacuum_db.' || quote(name) "
|
||||
"FROM vacuum_db.sqlite_master WHERE name='sqlite_sequence'"
|
||||
);
|
||||
execExecSql(db,
|
||||
"SELECT 'INSERT INTO vacuum_db.' || quote(name) "
|
||||
"|| ' SELECT * FROM main.' || quote(name) "
|
||||
"FROM vacuum_db.sqlite_master WHERE name=='sqlite_sequence'"
|
||||
);
|
||||
|
||||
/* Copy the triggers, views, and virtual tables from the main database
|
||||
** over to the temporary database. None of these objects has any
|
||||
** associated storage, so all we have to do is copy their entries
|
||||
** from the SQLITE_MASTER table.
|
||||
*/
|
||||
execSql(db,
|
||||
"INSERT INTO vacuum_db.sqlite_master "
|
||||
" SELECT type, name, tbl_name, rootpage, sql"
|
||||
" FROM main.sqlite_master"
|
||||
" WHERE type='view' OR type='trigger'"
|
||||
" OR (type='table' AND rootpage=0)"
|
||||
);
|
||||
|
||||
/* Commit the transaction and close the database
|
||||
*/
|
||||
execSql(db, "COMMIT");
|
||||
printf("-- close database\n");
|
||||
sqlite3_close(db);
|
||||
|
||||
|
||||
/* At this point, zDbToVacuum is unchanged. zTempDb contains a
|
||||
** vacuumed copy of zDbToVacuum. Rearrange filenames so that
|
||||
** zTempDb becomes thenew zDbToVacuum.
|
||||
*/
|
||||
printf("-- rename \"%s\" to \"%s\"\n", zDbToVacuum, zBackupDb);
|
||||
rename(zDbToVacuum, zBackupDb);
|
||||
printf("-- rename \"%s\" to \"%s\"\n", zTempDb, zDbToVacuum);
|
||||
rename(zTempDb, zDbToVacuum);
|
||||
|
||||
/* Release allocated memory */
|
||||
sqlite3_free(zTempDb);
|
||||
sqlite3_free(zBackupDb);
|
||||
return 0;
|
||||
}
|
||||
+19
-19
@@ -3391,7 +3391,7 @@ void print_stack_union(
|
||||
int maxdtlength; /* Maximum length of any ".datatype" field. */
|
||||
char *stddt; /* Standardized name for a datatype */
|
||||
int i,j; /* Loop counters */
|
||||
int hash; /* For hashing the name of a type */
|
||||
unsigned hash; /* For hashing the name of a type */
|
||||
const char *name; /* Name of the parser */
|
||||
|
||||
/* Allocate and initialize types[] and allocate stddt[] */
|
||||
@@ -4234,10 +4234,10 @@ int SetUnion(char *s1, char *s2)
|
||||
** Code for processing tables in the LEMON parser generator.
|
||||
*/
|
||||
|
||||
PRIVATE int strhash(const char *x)
|
||||
PRIVATE unsigned strhash(const char *x)
|
||||
{
|
||||
int h = 0;
|
||||
while( *x) h = h*13 + *(x++);
|
||||
unsigned h = 0;
|
||||
while( *x ) h = h*13 + *(x++);
|
||||
return h;
|
||||
}
|
||||
|
||||
@@ -4309,8 +4309,8 @@ void Strsafe_init(){
|
||||
int Strsafe_insert(const char *data)
|
||||
{
|
||||
x1node *np;
|
||||
int h;
|
||||
int ph;
|
||||
unsigned h;
|
||||
unsigned ph;
|
||||
|
||||
if( x1a==0 ) return 0;
|
||||
ph = strhash(data);
|
||||
@@ -4364,7 +4364,7 @@ int Strsafe_insert(const char *data)
|
||||
** if no such key. */
|
||||
const char *Strsafe_find(const char *key)
|
||||
{
|
||||
int h;
|
||||
unsigned h;
|
||||
x1node *np;
|
||||
|
||||
if( x1a==0 ) return 0;
|
||||
@@ -4475,8 +4475,8 @@ void Symbol_init(){
|
||||
int Symbol_insert(struct symbol *data, const char *key)
|
||||
{
|
||||
x2node *np;
|
||||
int h;
|
||||
int ph;
|
||||
unsigned h;
|
||||
unsigned ph;
|
||||
|
||||
if( x2a==0 ) return 0;
|
||||
ph = strhash(key);
|
||||
@@ -4532,7 +4532,7 @@ int Symbol_insert(struct symbol *data, const char *key)
|
||||
** if no such key. */
|
||||
struct symbol *Symbol_find(const char *key)
|
||||
{
|
||||
int h;
|
||||
unsigned h;
|
||||
x2node *np;
|
||||
|
||||
if( x2a==0 ) return 0;
|
||||
@@ -4606,9 +4606,9 @@ PRIVATE int statecmp(struct config *a, struct config *b)
|
||||
}
|
||||
|
||||
/* Hash a state */
|
||||
PRIVATE int statehash(struct config *a)
|
||||
PRIVATE unsigned statehash(struct config *a)
|
||||
{
|
||||
int h=0;
|
||||
unsigned h=0;
|
||||
while( a ){
|
||||
h = h*571 + a->rp->index*37 + a->dot;
|
||||
a = a->bp;
|
||||
@@ -4674,8 +4674,8 @@ void State_init(){
|
||||
int State_insert(struct state *data, struct config *key)
|
||||
{
|
||||
x3node *np;
|
||||
int h;
|
||||
int ph;
|
||||
unsigned h;
|
||||
unsigned ph;
|
||||
|
||||
if( x3a==0 ) return 0;
|
||||
ph = statehash(key);
|
||||
@@ -4731,7 +4731,7 @@ int State_insert(struct state *data, struct config *key)
|
||||
** if no such key. */
|
||||
struct state *State_find(struct config *key)
|
||||
{
|
||||
int h;
|
||||
unsigned h;
|
||||
x3node *np;
|
||||
|
||||
if( x3a==0 ) return 0;
|
||||
@@ -4761,9 +4761,9 @@ struct state **State_arrayof()
|
||||
}
|
||||
|
||||
/* Hash a configuration */
|
||||
PRIVATE int confighash(struct config *a)
|
||||
PRIVATE unsigned confighash(struct config *a)
|
||||
{
|
||||
int h=0;
|
||||
unsigned h=0;
|
||||
h = h*571 + a->rp->index*37 + a->dot;
|
||||
return h;
|
||||
}
|
||||
@@ -4816,8 +4816,8 @@ void Configtable_init(){
|
||||
int Configtable_insert(struct config *data)
|
||||
{
|
||||
x4node *np;
|
||||
int h;
|
||||
int ph;
|
||||
unsigned h;
|
||||
unsigned ph;
|
||||
|
||||
if( x4a==0 ) return 0;
|
||||
ph = confighash(data);
|
||||
|
||||
@@ -10,39 +10,42 @@
|
||||
**
|
||||
*************************************************************************
|
||||
** This file contains a simple command-line utility for converting from
|
||||
** integers and WhereCost values and back again and for doing simple
|
||||
** arithmetic operations (multiple and add) on WhereCost values.
|
||||
** integers and LogEst values and back again and for doing simple
|
||||
** arithmetic operations (multiple and add) on LogEst values.
|
||||
**
|
||||
** Usage:
|
||||
**
|
||||
** ./wherecosttest ARGS
|
||||
** ./LogEst ARGS
|
||||
**
|
||||
** Arguments:
|
||||
**
|
||||
** 'x' Multiple the top two elements of the stack
|
||||
** '+' Add the top two elements of the stack
|
||||
** NUM Convert NUM from integer to WhereCost and push onto the stack
|
||||
** ^NUM Interpret NUM as a WhereCost and push onto stack.
|
||||
** NUM Convert NUM from integer to LogEst and push onto the stack
|
||||
** ^NUM Interpret NUM as a LogEst and push onto stack.
|
||||
**
|
||||
** Examples:
|
||||
**
|
||||
** To convert 123 from WhereCost to integer:
|
||||
** To convert 123 from LogEst to integer:
|
||||
**
|
||||
** ./wherecosttest ^123
|
||||
** ./LogEst ^123
|
||||
**
|
||||
** To convert 123456 from integer to WhereCost:
|
||||
** To convert 123456 from integer to LogEst:
|
||||
**
|
||||
** ./wherecosttest 123456
|
||||
** ./LogEst 123456
|
||||
**
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include "sqlite3.h"
|
||||
|
||||
typedef unsigned short int WhereCost; /* 10 times log2() */
|
||||
typedef short int LogEst; /* 10 times log2() */
|
||||
|
||||
WhereCost whereCostMultiply(WhereCost a, WhereCost b){ return a+b; }
|
||||
WhereCost whereCostAdd(WhereCost a, WhereCost b){
|
||||
LogEst logEstMultiply(LogEst a, LogEst b){ return a+b; }
|
||||
LogEst logEstAdd(LogEst a, LogEst b){
|
||||
static const unsigned char x[] = {
|
||||
10, 10, /* 0,1 */
|
||||
9, 9, /* 2,3 */
|
||||
@@ -54,14 +57,14 @@ WhereCost whereCostAdd(WhereCost a, WhereCost b){
|
||||
3, 3, 3, 3, 3, 3, /* 19-24 */
|
||||
2, 2, 2, 2, 2, 2, 2, /* 25-31 */
|
||||
};
|
||||
if( a<b ){ WhereCost t = a; a = b; b = t; }
|
||||
if( a<b ){ LogEst t = a; a = b; b = t; }
|
||||
if( a>b+49 ) return a;
|
||||
if( a>b+31 ) return a+1;
|
||||
return a+x[a-b];
|
||||
}
|
||||
WhereCost whereCostFromInteger(int x){
|
||||
static WhereCost a[] = { 0, 2, 3, 5, 6, 7, 8, 9 };
|
||||
WhereCost y = 40;
|
||||
LogEst logEstFromInteger(sqlite3_uint64 x){
|
||||
static LogEst a[] = { 0, 2, 3, 5, 6, 7, 8, 9 };
|
||||
LogEst y = 40;
|
||||
if( x<8 ){
|
||||
if( x<2 ) return 0;
|
||||
while( x<8 ){ y -= 10; x <<= 1; }
|
||||
@@ -71,8 +74,8 @@ WhereCost whereCostFromInteger(int x){
|
||||
}
|
||||
return a[x&7] + y - 10;
|
||||
}
|
||||
static unsigned long int whereCostToInt(WhereCost x){
|
||||
unsigned long int n;
|
||||
static sqlite3_uint64 logEstToInt(LogEst x){
|
||||
sqlite3_uint64 n;
|
||||
if( x<10 ) return 1;
|
||||
n = x%10;
|
||||
x /= 10;
|
||||
@@ -81,31 +84,58 @@ static unsigned long int whereCostToInt(WhereCost x){
|
||||
if( x>=3 ) return (n+8)<<(x-3);
|
||||
return (n+8)>>(3-x);
|
||||
}
|
||||
static LogEst logEstFromDouble(double x){
|
||||
sqlite3_uint64 a;
|
||||
LogEst e;
|
||||
assert( sizeof(x)==8 && sizeof(a)==8 );
|
||||
if( x<=0.0 ) return -32768;
|
||||
if( x<1.0 ) return -logEstFromDouble(1/x);
|
||||
if( x<1024.0 ) return logEstFromInteger((sqlite3_uint64)(1024.0*x)) - 100;
|
||||
if( x<=2000000000.0 ) return logEstFromInteger((sqlite3_uint64)x);
|
||||
memcpy(&a, &x, 8);
|
||||
e = (a>>52) - 1022;
|
||||
return e*10;
|
||||
}
|
||||
|
||||
int isFloat(const char *z){
|
||||
while( z[0] ){
|
||||
if( z[0]=='.' || z[0]=='E' || z[0]=='e' ) return 1;
|
||||
z++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
int i;
|
||||
int n = 0;
|
||||
WhereCost a[100];
|
||||
LogEst a[100];
|
||||
for(i=1; i<argc; i++){
|
||||
const char *z = argv[i];
|
||||
if( z[0]=='+' ){
|
||||
if( n>=2 ){
|
||||
a[n-2] = whereCostAdd(a[n-2],a[n-1]);
|
||||
a[n-2] = logEstAdd(a[n-2],a[n-1]);
|
||||
n--;
|
||||
}
|
||||
}else if( z[0]=='x' ){
|
||||
if( n>=2 ){
|
||||
a[n-2] = whereCostMultiply(a[n-2],a[n-1]);
|
||||
a[n-2] = logEstMultiply(a[n-2],a[n-1]);
|
||||
n--;
|
||||
}
|
||||
}else if( z[0]=='^' ){
|
||||
a[n++] = atoi(z+1);
|
||||
}else if( isFloat(z) ){
|
||||
a[n++] = logEstFromDouble(atof(z));
|
||||
}else{
|
||||
a[n++] = whereCostFromInteger(atoi(z));
|
||||
a[n++] = logEstFromInteger(atoi(z));
|
||||
}
|
||||
}
|
||||
for(i=n-1; i>=0; i--){
|
||||
printf("%d (%lu)\n", a[i], whereCostToInt(a[i]));
|
||||
if( a[i]<0 ){
|
||||
printf("%d (%f)\n", a[i], 1.0/(double)logEstToInt(-a[i]));
|
||||
}else{
|
||||
sqlite3_uint64 x = logEstToInt(a[i]+100)*100/1024;
|
||||
printf("%d (%lld.%02lld)\n", a[i], x/100, x%100);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,389 @@
|
||||
#!/usr/bin/tclsh
|
||||
#
|
||||
# Run this script to generate the pragma name lookup table C code.
|
||||
#
|
||||
# To add new pragmas, first add the name and other relevant attributes
|
||||
# of the pragma to the "pragma_def" object below. Then run this script
|
||||
# to generate the C-code for the lookup table and copy/paste the output
|
||||
# of this script into the appropriate spot in the pragma.c source file.
|
||||
# Then add the extra "case PragTyp_XXXXX:" and subsequent code for the
|
||||
# new pragma.
|
||||
#
|
||||
|
||||
set pragma_def {
|
||||
NAME: full_column_names
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_FullColNames
|
||||
|
||||
NAME: short_column_names
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_ShortColNames
|
||||
|
||||
NAME: count_changes
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_CountRows
|
||||
|
||||
NAME: empty_result_callbacks
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_NullCallback
|
||||
|
||||
NAME: legacy_file_format
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_LegacyFileFmt
|
||||
|
||||
NAME: fullfsync
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_FullFSync
|
||||
|
||||
NAME: checkpoint_fullfsync
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_CkptFullFSync
|
||||
|
||||
NAME: cache_spill
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_CacheSpill
|
||||
|
||||
NAME: reverse_unordered_selects
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_ReverseOrder
|
||||
|
||||
NAME: query_only
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_QueryOnly
|
||||
|
||||
NAME: automatic_index
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_AutoIndex
|
||||
IF: !defined(SQLITE_OMIT_AUTOMATIC_INDEX)
|
||||
|
||||
NAME: sql_trace
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_SqlTrace
|
||||
IF: defined(SQLITE_DEBUG)
|
||||
|
||||
NAME: vdbe_listing
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_VdbeListing
|
||||
IF: defined(SQLITE_DEBUG)
|
||||
|
||||
NAME: vdbe_trace
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_VdbeTrace
|
||||
IF: defined(SQLITE_DEBUG)
|
||||
|
||||
NAME: vdbe_addoptrace
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_VdbeAddopTrace
|
||||
IF: defined(SQLITE_DEBUG)
|
||||
|
||||
NAME: vdbe_debug
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace
|
||||
IF: defined(SQLITE_DEBUG)
|
||||
|
||||
NAME: ignore_check_constraints
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_IgnoreChecks
|
||||
IF: !defined(SQLITE_OMIT_CHECK)
|
||||
|
||||
NAME: writable_schema
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_WriteSchema|SQLITE_RecoveryMode
|
||||
|
||||
NAME: read_uncommitted
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_ReadUncommitted
|
||||
|
||||
NAME: recursive_triggers
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_RecTriggers
|
||||
|
||||
NAME: foreign_keys
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_ForeignKeys
|
||||
IF: !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
|
||||
|
||||
NAME: defer_foreign_keys
|
||||
TYPE: FLAG
|
||||
ARG: SQLITE_DeferFKs
|
||||
IF: !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
|
||||
|
||||
NAME: default_cache_size
|
||||
FLAG: NeedSchema
|
||||
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
|
||||
|
||||
NAME: page_size
|
||||
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
|
||||
|
||||
NAME: secure_delete
|
||||
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
|
||||
|
||||
NAME: page_count
|
||||
FLAG: NeedSchema
|
||||
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
|
||||
|
||||
NAME: max_page_count
|
||||
TYPE: PAGE_COUNT
|
||||
FLAG: NeedSchema
|
||||
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
|
||||
|
||||
NAME: locking_mode
|
||||
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
|
||||
|
||||
NAME: journal_mode
|
||||
FLAG: NeedSchema
|
||||
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
|
||||
|
||||
NAME: journal_size_limit
|
||||
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
|
||||
|
||||
NAME: cache_size
|
||||
FLAG: NeedSchema
|
||||
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
|
||||
|
||||
NAME: mmap_size
|
||||
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
|
||||
|
||||
NAME: auto_vacuum
|
||||
FLAG: NeedSchema
|
||||
IF: !defined(SQLITE_OMIT_AUTOVACUUM)
|
||||
|
||||
NAME: incremental_vacuum
|
||||
FLAG: NeedSchema
|
||||
IF: !defined(SQLITE_OMIT_AUTOVACUUM)
|
||||
|
||||
NAME: temp_store
|
||||
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
|
||||
|
||||
NAME: temp_store_directory
|
||||
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
|
||||
|
||||
NAME: data_store_directory
|
||||
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
|
||||
|
||||
NAME: lock_proxy_file
|
||||
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE
|
||||
|
||||
NAME: synchronous
|
||||
FLAG: NeedSchema
|
||||
IF: !defined(SQLITE_OMIT_PAGER_PRAGMAS)
|
||||
|
||||
NAME: table_info
|
||||
FLAG: NeedSchema
|
||||
IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
|
||||
|
||||
NAME: index_info
|
||||
FLAG: NeedSchema
|
||||
IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
|
||||
|
||||
NAME: index_list
|
||||
FLAG: NeedSchema
|
||||
IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
|
||||
|
||||
NAME: database_list
|
||||
FLAG: NeedSchema
|
||||
IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
|
||||
|
||||
NAME: collation_list
|
||||
IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
|
||||
|
||||
NAME: foreign_key_list
|
||||
FLAG: NeedSchema
|
||||
IF: !defined(SQLITE_OMIT_FOREIGN_KEY)
|
||||
|
||||
NAME: foreign_key_check
|
||||
FLAG: NeedSchema
|
||||
IF: !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
|
||||
|
||||
NAME: parser_trace
|
||||
IF: defined(SQLITE_DEBUG)
|
||||
|
||||
NAME: case_sensitive_like
|
||||
|
||||
NAME: integrity_check
|
||||
FLAG: NeedSchema
|
||||
IF: !defined(SQLITE_OMIT_INTEGRITY_CHECK)
|
||||
|
||||
NAME: quick_check
|
||||
TYPE: INTEGRITY_CHECK
|
||||
FLAG: NeedSchema
|
||||
IF: !defined(SQLITE_OMIT_INTEGRITY_CHECK)
|
||||
|
||||
NAME: encoding
|
||||
IF: !defined(SQLITE_OMIT_UTF16)
|
||||
|
||||
NAME: schema_version
|
||||
TYPE: HEADER_VALUE
|
||||
IF: !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
|
||||
|
||||
NAME: user_version
|
||||
TYPE: HEADER_VALUE
|
||||
IF: !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
|
||||
|
||||
NAME: freelist_count
|
||||
TYPE: HEADER_VALUE
|
||||
IF: !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
|
||||
|
||||
NAME: application_id
|
||||
TYPE: HEADER_VALUE
|
||||
IF: !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
|
||||
|
||||
NAME: compile_options
|
||||
IF: !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
|
||||
|
||||
NAME: wal_checkpoint
|
||||
FLAG: NeedSchema
|
||||
IF: !defined(SQLITE_OMIT_WAL)
|
||||
|
||||
NAME: wal_autocheckpoint
|
||||
IF: !defined(SQLITE_OMIT_WAL)
|
||||
|
||||
NAME: shrink_memory
|
||||
|
||||
NAME: busy_timeout
|
||||
|
||||
NAME: lock_status
|
||||
IF: defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
|
||||
|
||||
NAME: key
|
||||
IF: defined(SQLITE_HAS_CODEC)
|
||||
|
||||
NAME: rekey
|
||||
IF: defined(SQLITE_HAS_CODEC)
|
||||
|
||||
NAME: hexkey
|
||||
IF: defined(SQLITE_HAS_CODEC)
|
||||
|
||||
NAME: hexrekey
|
||||
TYPE: HEXKEY
|
||||
IF: defined(SQLITE_HAS_CODEC)
|
||||
|
||||
NAME: activate_extensions
|
||||
IF: defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
|
||||
|
||||
NAME: soft_heap_limit
|
||||
}
|
||||
set name {}
|
||||
set type {}
|
||||
set if {}
|
||||
set flags {}
|
||||
set arg 0
|
||||
proc record_one {} {
|
||||
global name type if arg allbyname typebyif flags
|
||||
if {$name==""} return
|
||||
set allbyname($name) [list $type $arg $if $flags]
|
||||
set name {}
|
||||
set type {}
|
||||
set if {}
|
||||
set flags {}
|
||||
set arg 0
|
||||
}
|
||||
foreach line [split $pragma_def \n] {
|
||||
set line [string trim $line]
|
||||
if {$line==""} continue
|
||||
foreach {id val} [split $line :] break
|
||||
set val [string trim $val]
|
||||
if {$id=="NAME"} {
|
||||
record_one
|
||||
set name $val
|
||||
set type [string toupper $val]
|
||||
} elseif {$id=="TYPE"} {
|
||||
set type $val
|
||||
} elseif {$id=="ARG"} {
|
||||
set arg $val
|
||||
} elseif {$id=="IF"} {
|
||||
set if $val
|
||||
} elseif {$id=="FLAG"} {
|
||||
foreach term [split $val] {
|
||||
lappend flags $term
|
||||
set allflags($term) 1
|
||||
}
|
||||
} else {
|
||||
error "bad pragma_def line: $line"
|
||||
}
|
||||
}
|
||||
record_one
|
||||
set allnames [lsort [array names allbyname]]
|
||||
|
||||
# Generate #defines for all pragma type names. Group the pragmas that are
|
||||
# omit in default builds (defined(SQLITE_DEBUG) and defined(SQLITE_HAS_CODEC))
|
||||
# at the end.
|
||||
#
|
||||
set pnum 0
|
||||
foreach name $allnames {
|
||||
set type [lindex $allbyname($name) 0]
|
||||
if {[info exists seentype($type)]} continue
|
||||
set if [lindex $allbyname($name) 2]
|
||||
if {[regexp SQLITE_DEBUG $if] || [regexp SQLITE_HAS_CODEC $if]} continue
|
||||
set seentype($type) 1
|
||||
puts [format {#define %-35s %4d} PragTyp_$type $pnum]
|
||||
incr pnum
|
||||
}
|
||||
foreach name $allnames {
|
||||
set type [lindex $allbyname($name) 0]
|
||||
if {[info exists seentype($type)]} continue
|
||||
set if [lindex $allbyname($name) 2]
|
||||
if {[regexp SQLITE_DEBUG $if]} continue
|
||||
set seentype($type) 1
|
||||
puts [format {#define %-35s %4d} PragTyp_$type $pnum]
|
||||
incr pnum
|
||||
}
|
||||
foreach name $allnames {
|
||||
set type [lindex $allbyname($name) 0]
|
||||
if {[info exists seentype($type)]} continue
|
||||
set seentype($type) 1
|
||||
puts [format {#define %-35s %4d} PragTyp_$type $pnum]
|
||||
incr pnum
|
||||
}
|
||||
|
||||
# Generate #defines for flags
|
||||
#
|
||||
set fv 1
|
||||
foreach f [lsort [array names allflags]] {
|
||||
puts [format {#define PragFlag_%-20s 0x%02x} $f $fv]
|
||||
set fv [expr {$fv*2}]
|
||||
}
|
||||
|
||||
# Generate the lookup table
|
||||
#
|
||||
puts "static const struct sPragmaNames \173"
|
||||
puts " const char *const zName; /* Name of pragma */"
|
||||
puts " u8 ePragTyp; /* PragTyp_XXX value */"
|
||||
puts " u8 mPragFlag; /* Zero or more PragFlag_XXX values */"
|
||||
puts " u32 iArg; /* Extra argument */"
|
||||
puts "\175 aPragmaNames\[\] = \173"
|
||||
|
||||
set current_if {}
|
||||
set spacer [format { %26s } {}]
|
||||
foreach name $allnames {
|
||||
foreach {type arg if flag} $allbyname($name) break
|
||||
if {$if!=$current_if} {
|
||||
if {$current_if!=""} {puts "#endif"}
|
||||
set current_if $if
|
||||
if {$current_if!=""} {puts "#if $current_if"}
|
||||
}
|
||||
set typex [format PragTyp_%-23s $type,]
|
||||
if {$flag==""} {
|
||||
set flagx "0"
|
||||
} else {
|
||||
set flagx PragFlag_[join $flag {|PragFlag_}]
|
||||
}
|
||||
puts " \173 /* zName: */ \"$name\","
|
||||
puts " /* ePragTyp: */ PragTyp_$type,"
|
||||
puts " /* ePragFlag: */ $flagx,"
|
||||
puts " /* iArg: */ $arg \175,"
|
||||
}
|
||||
if {$current_if!=""} {puts "#endif"}
|
||||
puts "\175;"
|
||||
|
||||
# count the number of pragmas, for information purposes
|
||||
#
|
||||
set allcnt 0
|
||||
set dfltcnt 0
|
||||
foreach name $allnames {
|
||||
incr allcnt
|
||||
set if [lindex $allbyname($name) 2]
|
||||
if {[regexp {^defined} $if] || [regexp {[^!]defined} $if]} continue
|
||||
incr dfltcnt
|
||||
}
|
||||
puts "/* Number of pragmas: $dfltcnt on by default, $allcnt total. */"
|
||||
+21
-7
@@ -65,12 +65,12 @@
|
||||
# argument is optional and if present must contain the name of the directory
|
||||
# containing the root of the source tree for SQLite. The third argument is
|
||||
# optional and if present must contain the flavor the VSIX package to build.
|
||||
# Currently, the only supported package flavors are "WinRT" and "WP80". The
|
||||
# fourth argument is optional and if present must be a string containing a list
|
||||
# of platforms to include in the VSIX package. The format of the platform list
|
||||
# string is "platform1,platform2,platform3". Typically, when on Windows, this
|
||||
# script is executed using commands similar to the following from a normal
|
||||
# Windows command prompt:
|
||||
# Currently, the only supported package flavors are "WinRT", "WinRT81", and
|
||||
# "WP80". The fourth argument is optional and if present must be a string
|
||||
# containing a list of platforms to include in the VSIX package. The format
|
||||
# of the platform list string is "platform1,platform2,platform3". Typically,
|
||||
# when on Windows, this script is executed using commands similar to the
|
||||
# following from a normal Windows command prompt:
|
||||
#
|
||||
# CD /D C:\dev\sqlite\core
|
||||
# tclsh85 tool\mkvsix.tcl C:\Temp
|
||||
@@ -255,18 +255,32 @@ if {[string equal -nocase $packageFlavor WinRT]} then {
|
||||
set shortName SQLite.WinRT
|
||||
set displayName "SQLite for Windows Runtime"
|
||||
set targetPlatformIdentifier Windows
|
||||
set targetPlatformVersion v8.0
|
||||
set minVsVersion 11.0
|
||||
set extraSdkPath ""
|
||||
set extraFileListAttributes [appendArgs \
|
||||
"\r\n " {AppliesTo="WindowsAppContainer"} \
|
||||
"\r\n " {DependsOn="Microsoft.VCLibs, version=11.0"}]
|
||||
} elseif {[string equal -nocase $packageFlavor WinRT81]} then {
|
||||
set shortName SQLite.WinRT81
|
||||
set displayName "SQLite for Windows Runtime (Windows 8.1)"
|
||||
set targetPlatformIdentifier Windows
|
||||
set targetPlatformVersion v8.1
|
||||
set minVsVersion 12.0
|
||||
set extraSdkPath ""
|
||||
set extraFileListAttributes [appendArgs \
|
||||
"\r\n " {AppliesTo="WindowsAppContainer"} \
|
||||
"\r\n " {DependsOn="Microsoft.VCLibs, version=12.0"}]
|
||||
} elseif {[string equal -nocase $packageFlavor WP80]} then {
|
||||
set shortName SQLite.WP80
|
||||
set displayName "SQLite for Windows Phone"
|
||||
set targetPlatformIdentifier "Windows Phone"
|
||||
set targetPlatformVersion v8.0
|
||||
set minVsVersion 11.0
|
||||
set extraSdkPath "\\..\\$targetPlatformIdentifier"
|
||||
set extraFileListAttributes ""
|
||||
} else {
|
||||
fail "unsupported package flavor, must be \"WinRT\" or \"WP80\""
|
||||
fail "unsupported package flavor, must be \"WinRT\", \"WinRT81\", or \"WP80\""
|
||||
}
|
||||
|
||||
if {$argc >= 4} then {
|
||||
|
||||
+35
-30
@@ -199,15 +199,17 @@ foreach {name tblname} [concat sqlite_master sqlite_master [db eval $sql]] {
|
||||
# is.
|
||||
#
|
||||
set gap_cnt 0
|
||||
set pglist [db eval {
|
||||
SELECT pageno FROM temp.dbstat WHERE name = $name ORDER BY rowid
|
||||
}]
|
||||
set prev [lindex $pglist 0]
|
||||
foreach pgno [lrange $pglist 1 end] {
|
||||
if {$pgno != $prev+1} {incr gap_cnt}
|
||||
set prev $pgno
|
||||
set prev 0
|
||||
db eval {
|
||||
SELECT pageno, pagetype FROM temp.dbstat
|
||||
WHERE name=$name
|
||||
ORDER BY pageno
|
||||
} {
|
||||
if {$prev>0 && $pagetype=="leaf" && $pageno!=$prev+1} {
|
||||
incr gap_cnt
|
||||
}
|
||||
set prev $pageno
|
||||
}
|
||||
|
||||
mem eval {
|
||||
INSERT INTO space_used VALUES(
|
||||
$name,
|
||||
@@ -298,7 +300,7 @@ proc divide {num denom} {
|
||||
# Generate a subreport that covers some subset of the database.
|
||||
# the $where clause determines which subset to analyze.
|
||||
#
|
||||
proc subreport {title where} {
|
||||
proc subreport {title where showFrag} {
|
||||
global pageSize file_pgcnt compressOverhead
|
||||
|
||||
# Query the in-memory database for the sum of various statistics
|
||||
@@ -384,9 +386,9 @@ proc subreport {title where} {
|
||||
if {[info exists avg_fanout]} {
|
||||
statline {Average fanout} $avg_fanout
|
||||
}
|
||||
if {$total_pages>1} {
|
||||
set fragmentation [percent $gap_cnt [expr {$total_pages-1}] {fragmentation}]
|
||||
statline {Fragmentation} $fragmentation
|
||||
if {$showFrag && $total_pages>1} {
|
||||
set fragmentation [percent $gap_cnt [expr {$total_pages-1}]]
|
||||
statline {Non-sequential pages} $gap_cnt $fragmentation
|
||||
}
|
||||
statline {Maximum payload per entry} $mx_payload
|
||||
statline {Entries that use overflow} $ovfl_cnt $ovfl_cnt_percent
|
||||
@@ -509,8 +511,8 @@ statline {Pages on the freelist (calculated)} $free_pgcnt $free_percent
|
||||
statline {Pages of auto-vacuum overhead} $av_pgcnt $av_percent
|
||||
statline {Number of tables in the database} $ntable
|
||||
statline {Number of indices} $nindex
|
||||
statline {Number of named indices} $nmanindex
|
||||
statline {Automatically generated indices} $nautoindex
|
||||
statline {Number of defined indices} $nmanindex
|
||||
statline {Number of implied indices} $nautoindex
|
||||
if {$isCompressed} {
|
||||
statline {Size of uncompressed content in bytes} $file_bytes
|
||||
set efficiency [percent $true_file_size $file_bytes]
|
||||
@@ -563,11 +565,11 @@ if {$isCompressed} {
|
||||
# Output subreports
|
||||
#
|
||||
if {$nindex>0} {
|
||||
subreport {All tables and indices} 1
|
||||
subreport {All tables and indices} 1 0
|
||||
}
|
||||
subreport {All tables} {NOT is_index}
|
||||
subreport {All tables} {NOT is_index} 0
|
||||
if {$nindex>0} {
|
||||
subreport {All indices} {is_index}
|
||||
subreport {All indices} {is_index} 0
|
||||
}
|
||||
foreach tbl [mem eval {SELECT name FROM space_used WHERE NOT is_index
|
||||
ORDER BY name}] {
|
||||
@@ -578,17 +580,17 @@ foreach tbl [mem eval {SELECT name FROM space_used WHERE NOT is_index
|
||||
set idxlist [mem eval "SELECT name FROM space_used
|
||||
WHERE tblname='$qn' AND is_index
|
||||
ORDER BY 1"]
|
||||
subreport "Table $name and all its indices" "tblname='$qn'"
|
||||
subreport "Table $name w/o any indices" "name='$qn'"
|
||||
subreport "Table $name and all its indices" "tblname='$qn'" 0
|
||||
subreport "Table $name w/o any indices" "name='$qn'" 1
|
||||
if {[llength $idxlist]>1} {
|
||||
subreport "Indices of table $name" "tblname='$qn' AND is_index"
|
||||
subreport "Indices of table $name" "tblname='$qn' AND is_index" 0
|
||||
}
|
||||
foreach idx $idxlist {
|
||||
set qidx [quote $idx]
|
||||
subreport "Index [string toupper $idx] of table $name" "name='$qidx'"
|
||||
subreport "Index [string toupper $idx] of table $name" "name='$qidx'" 1
|
||||
}
|
||||
} else {
|
||||
subreport "Table $name" "name='$qn'"
|
||||
subreport "Table $name" "name='$qn'" 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -633,11 +635,11 @@ Number of indices
|
||||
|
||||
The total number of indices in the database.
|
||||
|
||||
Number of named indices
|
||||
Number of defined indices
|
||||
|
||||
The number of indices created using an explicit CREATE INDEX statement.
|
||||
|
||||
Automatically generated indices
|
||||
Number of implied indices
|
||||
|
||||
The number of indices used to implement PRIMARY KEY or UNIQUE constraints
|
||||
on tables.
|
||||
@@ -686,13 +688,16 @@ Average unused bytes per entry
|
||||
category on a per-entry basis. This is the number of unused bytes on
|
||||
all pages divided by the number of entries.
|
||||
|
||||
Fragmentation
|
||||
Non-sequential pages
|
||||
|
||||
The percentage of pages in the table or index that are not
|
||||
consecutive in the disk file. Many filesystems are optimized
|
||||
for sequential file access so smaller fragmentation numbers
|
||||
sometimes result in faster queries, especially for larger
|
||||
database files that do not fit in the disk cache.
|
||||
The number of pages in the table or index that are out of sequence.
|
||||
Many filesystems are optimized for sequential file access so a small
|
||||
number of non-sequential pages might result in faster queries,
|
||||
especially for larger database files that do not fit in the disk cache.
|
||||
Note that after running VACUUM, the root page of each table or index is
|
||||
at the beginning of the database file and all other pages are in a
|
||||
separate part of the database file, resulting in a single non-
|
||||
sequential page.
|
||||
|
||||
Maximum payload per entry
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user