SQLite

Check-in [e327ef37fa]
Login

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

Overview
Comment:When calculating schema memory, use the actual allocated size of hash elements, not sizeof(HashElem). Also fix a bug in dbstatus.test.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | experimental
Files: files | file ages | folders
SHA1: e327ef37faec52ce99591266160be2ce2d577cc3
User & Date: dan 2010-07-26 15:57:02.000
Original Comment: When calculating schema memory, use the actual allocated size of hash elements, not sizeof(HashElem). Also fix a bug in dbstatus.test
Context
2010-07-26
16:24
Add support for SQLITE_DBSTATUS_SCHEMA_USED and SQLITE_DBSTATUS_STMT_USED to the trunk. (check-in: 008368b2bd user: drh tags: trunk)
15:57
When calculating schema memory, use the actual allocated size of hash elements, not sizeof(HashElem). Also fix a bug in dbstatus.test. (Closed-Leaf check-in: e327ef37fa user: dan tags: experimental)
14:47
Add virtual table test cases to dbstatus.test. (check-in: 72b84d066a user: dan tags: experimental)
Changes
Side-by-Side Diff Ignore Whitespace Patch
Changes to src/status.c.
145
146
147
148
149
150
151
152
153
154



155
156
157
158
159
160
161
162
163
164
165










166
167
168
169
170
171
172
173

174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193

194
195
196
197
198
199
200
145
146
147
148
149
150
151



152
153
154
155










156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172

173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192

193
194
195
196
197
198
199
200







-
-
-
+
+
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+







-
+



















-
+







    */
    case SQLITE_DBSTATUS_SCHEMA_USED: {
      int i;                      /* Used to iterate through schemas */
      int nByte = 0;              /* Used to accumulate return value */

      db->pnBytesFreed = &nByte;
      for(i=0; i<db->nDb; i++){
	Schema *pSchema = db->aDb[i].pSchema;
	if( pSchema ){
  	  HashElem *p;
        Schema *pSchema = db->aDb[i].pSchema;
        if( pSchema ){
            HashElem *p;

	  nByte += sizeof(HashElem) * (
	      pSchema->tblHash.count 
	    + pSchema->trigHash.count
	    + pSchema->idxHash.count
	    + pSchema->fkeyHash.count
	  );
	  nByte += sqlite3MallocSize(pSchema->tblHash.ht);
	  nByte += sqlite3MallocSize(pSchema->trigHash.ht);
	  nByte += sqlite3MallocSize(pSchema->idxHash.ht);
	  nByte += sqlite3MallocSize(pSchema->fkeyHash.ht);
          nByte += sqlite3GlobalConfig.m.xRoundup(sizeof(HashElem)) * (
              pSchema->tblHash.count 
            + pSchema->trigHash.count
            + pSchema->idxHash.count
            + pSchema->fkeyHash.count
          );
          nByte += sqlite3MallocSize(pSchema->tblHash.ht);
          nByte += sqlite3MallocSize(pSchema->trigHash.ht);
          nByte += sqlite3MallocSize(pSchema->idxHash.ht);
          nByte += sqlite3MallocSize(pSchema->fkeyHash.ht);

          for(p=sqliteHashFirst(&pSchema->trigHash); p; p=sqliteHashNext(p)){
            sqlite3DeleteTrigger(db, (Trigger*)sqliteHashData(p));
          }
          for(p=sqliteHashFirst(&pSchema->tblHash); p; p=sqliteHashNext(p)){
            sqlite3DeleteTable(db, (Table *)sqliteHashData(p));
          }
	}
        }
      }
      db->pnBytesFreed = 0;

      *pHighwater = 0;
      *pCurrent = nByte;
      break;
    }

    /*
    ** *pCurrent gets an accurate estimate of the amount of memory used
    ** to store all prepared statements.
    ** *pHighwater is set to zero.
    */
    case SQLITE_DBSTATUS_STMT_USED: {
      struct Vdbe *pVdbe;         /* Used to iterate through VMs */
      int nByte = 0;              /* Used to accumulate return value */

      db->pnBytesFreed = &nByte;
      for(pVdbe=db->pVdbe; pVdbe; pVdbe=pVdbe->pNext){
	sqlite3VdbeDeleteObject(db, pVdbe);
        sqlite3VdbeDeleteObject(db, pVdbe);
      }
      db->pnBytesFreed = 0;

      *pHighwater = 0;
      *pCurrent = nByte;

      break;
Changes to test/dbstatus.test.
287
288
289
290
291
292
293
294

295
296
297
298
299
300
301
287
288
289
290
291
292
293

294
295
296
297
298
299
300
301







-
+







    incr nAlloc1 [lookaside db]
    set nStmt1   [lindex [sqlite3_db_status db SQLITE_DBSTATUS_STMT_USED 0] 1]
    execsql $statements
  
    # Step 3.
    db cache flush
    set nAlloc2  [lindex [sqlite3_status SQLITE_STATUS_MEMORY_USED 0] 1]
    incr nAlloc3 [lookaside db]
    incr nAlloc2 [lookaside db]
    set nStmt2   [lindex [sqlite3_db_status db SQLITE_DBSTATUS_STMT_USED 0] 1]
    
    # Step 3.
    execsql $statements
    set nAlloc3  [lindex [sqlite3_status SQLITE_STATUS_MEMORY_USED 0] 1]
    incr nAlloc3 [lookaside db]
    set nStmt3   [lindex [sqlite3_db_status db SQLITE_DBSTATUS_STMT_USED 0] 1]