SQLite

Changes On Branch branch-3.39-pcache
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch branch-3.39-pcache Excluding Merge-Ins

This is equivalent to a diff from 34c6ec39 to b17a2503

2022-09-02
16:45
When an OOM occurs and sets the Parse.nErr value, also set the Parse.nErr value for all outer Parse objects. dbsqlfuzz d33f60aaa67733aa700cd69dacf8e0e23a327a29 (check-in: 073621af user: drh tags: branch-3.39)
15:53
When an OOM occurs and sets the Parse.nErr value, also set the Parse.nErr value for all outer Parse objects. dbsqlfuzz d33f60aaa67733aa700cd69dacf8e0e23a327a29 (Leaf check-in: b17a2503 user: drh tags: branch-3.39-pcache)
15:19
If sqlite3PcacheMove() moves a page on top of another, swap the two pages, moving the other back to the page number of the original. (check-in: 04eb9f97 user: drh tags: branch-3.39-pcache)
12:12
Mutex protect access to the sqlite3_test_directory and sqlite3_data_directory global variables. See forum thread 719a11e1314d1c70. (check-in: 34c6ec39 user: drh tags: branch-3.39)
11:45
Mutex protect access to the sqlite3_test_directory and sqlite3_data_directory global variables. See forum thread 719a11e1314d1c70. (check-in: 8e6ad3a3 user: drh tags: trunk)
2022-09-01
14:33
Defer deleting a transient SELECT statement associated with a flattening of one arm of a compound SELECT until after the parse has completed. (check-in: 8403c0d5 user: drh tags: branch-3.39)
2022-07-10
21:12
When an OOM occurs and sets the Parse.nErr value, also set the Parse.nErr value for all outer Parse objects. dbsqlfuzz d33f60aaa67733aa700cd69dacf8e0e23a327a29 (check-in: 9a494d25 user: drh tags: trunk)

Changes to src/malloc.c.

772
773
774
775
776
777
778

779
780




781
782
783
784
785
786
787
  if( db->mallocFailed==0 && db->bBenignMalloc==0 ){
    db->mallocFailed = 1;
    if( db->nVdbeExec>0 ){
      AtomicStore(&db->u1.isInterrupted, 1);
    }
    DisableLookaside;
    if( db->pParse ){

      sqlite3ErrorMsg(db->pParse, "out of memory");
      db->pParse->rc = SQLITE_NOMEM_BKPT;




    }
  }
  return 0;
}

/*
** This routine reactivates the memory allocator and clears the







>


>
>
>
>







772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
  if( db->mallocFailed==0 && db->bBenignMalloc==0 ){
    db->mallocFailed = 1;
    if( db->nVdbeExec>0 ){
      AtomicStore(&db->u1.isInterrupted, 1);
    }
    DisableLookaside;
    if( db->pParse ){
      Parse *pParse;
      sqlite3ErrorMsg(db->pParse, "out of memory");
      db->pParse->rc = SQLITE_NOMEM_BKPT;
      for(pParse=db->pParse->pOuterParse; pParse; pParse = pParse->pOuterParse){
        pParse->nErr++;
        pParse->rc = SQLITE_NOMEM;
      } 
    }
  }
  return 0;
}

/*
** This routine reactivates the memory allocator and clears the

Changes to src/pcache.c.

618
619
620
621
622
623
624

625
626
627
628

629







630
631
632
633
634
635
636
}

/*
** Change the page number of page p to newPgno. 
*/
void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){
  PCache *pCache = p->pCache;

  assert( p->nRef>0 );
  assert( newPgno>0 );
  assert( sqlite3PcachePageSanity(p) );
  pcacheTrace(("%p.MOVE %d -> %d\n",pCache,p->pgno,newPgno));

  sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);







  p->pgno = newPgno;
  if( (p->flags&PGHDR_DIRTY) && (p->flags&PGHDR_NEED_SYNC) ){
    pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
  }
}

/*







>




>

>
>
>
>
>
>
>







618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
}

/*
** Change the page number of page p to newPgno. 
*/
void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){
  PCache *pCache = p->pCache;
  sqlite3_pcache_page *pOther;
  assert( p->nRef>0 );
  assert( newPgno>0 );
  assert( sqlite3PcachePageSanity(p) );
  pcacheTrace(("%p.MOVE %d -> %d\n",pCache,p->pgno,newPgno));
  pOther = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, newPgno, 0);
  sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno);
  if( pOther ){
    PgHdr *pPg = (PgHdr*)pOther->pExtra;
    pPg->pgno = p->pgno;
    if( pPg->pPage==0 ){
      sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pOther, 0);
    }
  }
  p->pgno = newPgno;
  if( (p->flags&PGHDR_DIRTY) && (p->flags&PGHDR_NEED_SYNC) ){
    pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
  }
}

/*

Changes to src/pcache1.c.

1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
















1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
  sqlite3_pcache_page *pPg,
  unsigned int iOld,
  unsigned int iNew
){
  PCache1 *pCache = (PCache1 *)p;
  PgHdr1 *pPage = (PgHdr1 *)pPg;
  PgHdr1 **pp;
  unsigned int h; 
  assert( pPage->iKey==iOld );
  assert( pPage->pCache==pCache );

  pcache1EnterMutex(pCache->pGroup);

  h = iOld%pCache->nHash;
  pp = &pCache->apHash[h];
  while( (*pp)!=pPage ){
    pp = &(*pp)->pNext;
  }
  *pp = pPage->pNext;

  h = iNew%pCache->nHash;
















  pPage->iKey = iNew;
  pPage->pNext = pCache->apHash[h];
  pCache->apHash[h] = pPage;
  if( iNew>pCache->iMaxKey ){
    pCache->iMaxKey = iNew;
  }

  pcache1LeaveMutex(pCache->pGroup);
}








|





|
|





|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

|
|







1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
  sqlite3_pcache_page *pPg,
  unsigned int iOld,
  unsigned int iNew
){
  PCache1 *pCache = (PCache1 *)p;
  PgHdr1 *pPage = (PgHdr1 *)pPg;
  PgHdr1 **pp;
  unsigned int hOld, hNew; 
  assert( pPage->iKey==iOld );
  assert( pPage->pCache==pCache );

  pcache1EnterMutex(pCache->pGroup);

  hOld = iOld%pCache->nHash;
  pp = &pCache->apHash[hOld];
  while( (*pp)!=pPage ){
    pp = &(*pp)->pNext;
  }
  *pp = pPage->pNext;

  hNew = iNew%pCache->nHash;
  pp = &pCache->apHash[hNew];
  while( *pp ){
    if( (*pp)->iKey==iNew ){
      /* If there is already another pcache entry at iNew, change it to iOld,
      ** thus swapping the positions of iNew and iOld */
      PgHdr1 *pOld = *pp;
      *pp = pOld->pNext;
      pOld->pNext = pCache->apHash[hOld];
      pCache->apHash[hOld] = pOld;
      pOld->iKey = iOld;
      break;
    }else{
      pp = &(*pp)->pNext;
    }
  }

  pPage->iKey = iNew;
  pPage->pNext = pCache->apHash[hNew];
  pCache->apHash[hNew] = pPage;
  if( iNew>pCache->iMaxKey ){
    pCache->iMaxKey = iNew;
  }

  pcache1LeaveMutex(pCache->pGroup);
}