aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/analyze.c2
-rw-r--r--src/btree.c14
-rw-r--r--src/main.c4
-rw-r--r--src/test1.c10
-rw-r--r--src/vdbesort.c8
-rw-r--r--src/where.c2
6 files changed, 28 insertions, 12 deletions
diff --git a/src/analyze.c b/src/analyze.c
index 01c2f1295..e48380711 100644
--- a/src/analyze.c
+++ b/src/analyze.c
@@ -1596,7 +1596,7 @@ static void initAvgEq(Index *pIdx){
i64 nSum100 = 0; /* Number of terms contributing to sumEq */
i64 nDist100; /* Number of distinct values in index */
- if( pIdx->aiRowEst==0 || pIdx->aiRowEst[iCol+1]==0 ){
+ if( !pIdx->aiRowEst || iCol>=pIdx->nKeyCol || pIdx->aiRowEst[iCol+1]==0 ){
nRow = pFinal->anLt[iCol];
nDist100 = (i64)100 * pFinal->anDLt[iCol];
nSample--;
diff --git a/src/btree.c b/src/btree.c
index 796b44403..4283d00fd 100644
--- a/src/btree.c
+++ b/src/btree.c
@@ -6785,7 +6785,7 @@ static int balance_nonroot(
/* EVIDENCE-OF: R-28375-38319 SQLite will never request a scratch buffer
** that is more than 6 times the database page size. */
- assert( szScratch<=6*pBt->pageSize );
+ assert( szScratch<=6*(int)pBt->pageSize );
apCell = sqlite3ScratchMalloc( szScratch );
if( apCell==0 ){
rc = SQLITE_NOMEM;
@@ -6859,7 +6859,11 @@ static int balance_nonroot(
}else{
assert( leafCorrection==4 );
if( szCell[nCell]<4 ){
- /* Do not allow any cells smaller than 4 bytes. */
+ /* Do not allow any cells smaller than 4 bytes. If a smaller cell
+ ** does exist, pad it with 0x00 bytes. */
+ assert( szCell[nCell]==3 );
+ assert( apCell[nCell]==&pTemp[iSpace1-3] );
+ pTemp[iSpace1++] = 0x00;
szCell[nCell] = 4;
}
}
@@ -7094,7 +7098,11 @@ static int balance_nonroot(
** if sibling page iOld had the same page number as pNew, and if
** pCell really was a part of sibling page iOld (not a divider or
** overflow cell), we can skip updating the pointer map entries. */
- if( pNew->pgno!=aPgno[iOld] || pCell<aOld || pCell>=&aOld[usableSize] ){
+ if( iOld>=nNew
+ || pNew->pgno!=aPgno[iOld]
+ || pCell<aOld
+ || pCell>=&aOld[usableSize]
+ ){
if( !leafCorrection ){
ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc);
}
diff --git a/src/main.c b/src/main.c
index 8f850fb65..02d9ad767 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1034,11 +1034,13 @@ void sqlite3LeaveMutexAndCloseZombie(sqlite3 *db){
if( pDb->pBt ){
if( pDb->pSchema ){
/* Must clear the KeyInfo cache. See ticket [e4a18565a36884b00edf] */
+ sqlite3BtreeEnter(pDb->pBt);
for(i=sqliteHashFirst(&pDb->pSchema->idxHash); i; i=sqliteHashNext(i)){
Index *pIdx = sqliteHashData(i);
sqlite3KeyInfoUnref(pIdx->pKeyInfo);
pIdx->pKeyInfo = 0;
}
+ sqlite3BtreeLeave(pDb->pBt);
}
sqlite3BtreeClose(pDb->pBt);
pDb->pBt = 0;
@@ -2809,7 +2811,9 @@ static int openDatabase(
sqlite3Error(db, rc);
goto opendb_out;
}
+ sqlite3BtreeEnter(db->aDb[0].pBt);
db->aDb[0].pSchema = sqlite3SchemaGet(db, db->aDb[0].pBt);
+ sqlite3BtreeLeave(db->aDb[0].pBt);
db->aDb[1].pSchema = sqlite3SchemaGet(db, 0);
/* The default safety_level for the main database is 'full'; for the temp
diff --git a/src/test1.c b/src/test1.c
index 7839b3049..14ccacd86 100644
--- a/src/test1.c
+++ b/src/test1.c
@@ -5704,15 +5704,17 @@ static int test_wal_checkpoint_v2(
if( objc==4 ){
zDb = Tcl_GetString(objv[3]);
}
- if( getDbPointer(interp, Tcl_GetString(objv[1]), &db)
- || Tcl_GetIndexFromObj(interp, objv[2], aMode, "mode", 0, &eMode)
- ){
+ if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) || (
+ TCL_OK!=Tcl_GetIntFromObj(0, objv[2], &eMode)
+ && TCL_OK!=Tcl_GetIndexFromObj(interp, objv[2], aMode, "mode", 0, &eMode)
+ )){
return TCL_ERROR;
}
rc = sqlite3_wal_checkpoint_v2(db, zDb, eMode, &nLog, &nCkpt);
if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
- Tcl_SetResult(interp, (char *)sqlite3_errmsg(db), TCL_VOLATILE);
+ const char *zErrCode = sqlite3ErrName(rc);
+ Tcl_AppendResult(interp, zErrCode, " - ", (char *)sqlite3_errmsg(db), 0);
return TCL_ERROR;
}
diff --git a/src/vdbesort.c b/src/vdbesort.c
index 7c736adef..29ec40c0d 100644
--- a/src/vdbesort.c
+++ b/src/vdbesort.c
@@ -450,7 +450,9 @@ struct SorterRecord {
/* The minimum PMA size is set to this value multiplied by the database
** page size in bytes. */
-#define SORTER_MIN_WORKING 10
+#ifndef SQLITE_SORTER_PMASZ
+# define SQLITE_SORTER_PMASZ 250
+#endif
/* Maximum number of PMAs that a single MergeEngine can merge */
#define SORTER_MAX_MERGE_COUNT 16
@@ -849,9 +851,9 @@ int sqlite3VdbeSorterInit(
}
if( !sqlite3TempInMemory(db) ){
- pSorter->mnPmaSize = SORTER_MIN_WORKING * pgsz;
+ pSorter->mnPmaSize = SQLITE_SORTER_PMASZ * pgsz;
mxCache = db->aDb[0].pSchema->cache_size;
- if( mxCache<SORTER_MIN_WORKING ) mxCache = SORTER_MIN_WORKING;
+ if( mxCache<SQLITE_SORTER_PMASZ ) mxCache = SQLITE_SORTER_PMASZ;
pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_MXPMASIZE);
/* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
diff --git a/src/where.c b/src/where.c
index 8ec6018bc..ee42534f3 100644
--- a/src/where.c
+++ b/src/where.c
@@ -2948,7 +2948,7 @@ static void addScanStatus(
){
const char *zObj = 0;
WhereLoop *pLoop = pLvl->pWLoop;
- if( (pLoop->wsFlags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){
+ if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 && pLoop->u.btree.pIndex!=0 ){
zObj = pLoop->u.btree.pIndex->zName;
}else{
zObj = pSrclist->a[pLvl->iFrom].zName;