/ Check-in [d75140b8]
Login

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

Overview
Comment:Make the sqlite3DeleteTable() routine smaller and faster.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d75140b851a34a5eb66041e294e421628efbc5ba
User & Date: drh 2016-05-07 12:15:34
Context
2016-05-09
18:05
Fix the FTS5 xQueryPhrase() API function so that it recognizes column filters. check-in: 48505cde user: dan tags: trunk
2016-05-07
12:15
Make the sqlite3DeleteTable() routine smaller and faster. check-in: d75140b8 user: drh tags: trunk
12:15
Fix typo in the intpkey-17.2 test. check-in: a45fda65 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

   588    588   **
   589    589   ** The db parameter is optional.  It is needed if the Table object 
   590    590   ** contains lookaside memory.  (Table objects in the schema do not use
   591    591   ** lookaside memory, but some ephemeral Table objects do.)  Or the
   592    592   ** db parameter can be used with db->pnBytesFreed to measure the memory
   593    593   ** used by the Table object.
   594    594   */
   595         -void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
          595  +static void SQLITE_NOINLINE deleteTable(sqlite3 *db, Table *pTable){
   596    596     Index *pIndex, *pNext;
   597    597     TESTONLY( int nLookaside; ) /* Used to verify lookaside not used for schema */
   598    598   
   599         -  assert( !pTable || pTable->nRef>0 );
   600         -
   601         -  /* Do not delete the table until the reference count reaches zero. */
   602         -  if( !pTable ) return;
   603         -  if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return;
   604         -
   605    599     /* Record the number of outstanding lookaside allocations in schema Tables
   606    600     ** prior to doing any free() operations.  Since schema Tables do not use
   607    601     ** lookaside, this number should not change. */
   608    602     TESTONLY( nLookaside = (db && (pTable->tabFlags & TF_Ephemeral)==0) ?
   609    603                            db->lookaside.nOut : 0 );
   610    604   
   611    605     /* Delete all indices associated with this table. */
................................................................................
   637    631     sqlite3VtabClear(db, pTable);
   638    632   #endif
   639    633     sqlite3DbFree(db, pTable);
   640    634   
   641    635     /* Verify that no lookaside memory was used by schema tables */
   642    636     assert( nLookaside==0 || nLookaside==db->lookaside.nOut );
   643    637   }
          638  +void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
          639  +  /* Do not delete the table until the reference count reaches zero. */
          640  +  if( !pTable ) return;
          641  +  if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return;
          642  +  deleteTable(db, pTable);
          643  +}
          644  +
   644    645   
   645    646   /*
   646    647   ** Unlink the given table from the hash tables and the delete the
   647    648   ** table structure with all its indices and foreign keys.
   648    649   */
   649    650   void sqlite3UnlinkAndDeleteTable(sqlite3 *db, int iDb, const char *zTabName){
   650    651     Table *p;
................................................................................
  2217   2218         pSelTab->nCol = 0;
  2218   2219         pSelTab->aCol = 0;
  2219   2220         assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) );
  2220   2221       }else{
  2221   2222         pTable->nCol = 0;
  2222   2223         nErr++;
  2223   2224       }
  2224         -    if( pSelTab ) sqlite3DeleteTable(db, pSelTab);
         2225  +    sqlite3DeleteTable(db, pSelTab);
  2225   2226       sqlite3SelectDelete(db, pSel);
  2226   2227       db->lookaside.bDisable--;
  2227   2228     } else {
  2228   2229       nErr++;
  2229   2230     }
  2230   2231     pTable->pSchema->schemaFlags |= DB_UnresetViews;
  2231   2232   #endif /* SQLITE_OMIT_VIEW */