/ Check-in [5c663804]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Give the sqlite3 object a pointer to the current Parse so that if an OOM occurs, it can automatically set the Parse.rc value to SQLITE_NOMEM. This avoids a frequent extra test of db.mallocFailed in the innermost parser loop.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 5c6638040b3017c6be016441422d965a3ca00dd6ae1f78cadc0b54562978f64e
User & Date: drh 2019-02-08 14:55:30
Context
2019-02-08
15:59
Change the sqlite3VdbeMemGrow() routine so that it no longer guarantees a minimum size of 32 bytes. That minimum is no longer required, and without the extra check for the minimum size, the routine runs faster. check-in: 5c499da8 user: drh tags: trunk
14:55
Give the sqlite3 object a pointer to the current Parse so that if an OOM occurs, it can automatically set the Parse.rc value to SQLITE_NOMEM. This avoids a frequent extra test of db.mallocFailed in the innermost parser loop. check-in: 5c663804 user: drh tags: trunk
04:15
Do not do the optimization that attempts to pull expression values from an index on that expression when processing a multi-index OR (see check-in [a47efb7c8520a0111]) because the expression transformations that are applied become invalid when the processing moves off of the current index and on to the next index. Fix for ticket [4e8e4857d32d401f]. check-in: 440a7cda user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/malloc.c.

   657    657   void sqlite3OomFault(sqlite3 *db){
   658    658     if( db->mallocFailed==0 && db->bBenignMalloc==0 ){
   659    659       db->mallocFailed = 1;
   660    660       if( db->nVdbeExec>0 ){
   661    661         db->u1.isInterrupted = 1;
   662    662       }
   663    663       db->lookaside.bDisable++;
          664  +    if( db->pParse ){
          665  +      db->pParse->rc = SQLITE_NOMEM_BKPT;
          666  +    }
   664    667     }
   665    668   }
   666    669   
   667    670   /*
   668    671   ** This routine reactivates the memory allocator and clears the
   669    672   ** db->mallocFailed flag as necessary.
   670    673   **

Changes to src/sqliteInt.h.

  1427   1427   #endif
  1428   1428     void *pCommitArg;                 /* Argument to xCommitCallback() */
  1429   1429     int (*xCommitCallback)(void*);    /* Invoked at every commit. */
  1430   1430     void *pRollbackArg;               /* Argument to xRollbackCallback() */
  1431   1431     void (*xRollbackCallback)(void*); /* Invoked at every commit. */
  1432   1432     void *pUpdateArg;
  1433   1433     void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64);
         1434  +  Parse *pParse;                /* Current parse */
  1434   1435   #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
  1435   1436     void *pPreUpdateArg;          /* First argument to xPreUpdateCallback */
  1436   1437     void (*xPreUpdateCallback)(   /* Registered using sqlite3_preupdate_hook() */
  1437   1438       void*,sqlite3*,int,char const*,char const*,sqlite3_int64,sqlite3_int64
  1438   1439     );
  1439   1440     PreUpdate *pPreUpdate;        /* Context for active pre-update callback */
  1440   1441   #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
................................................................................
  3090   3091   #ifndef SQLITE_OMIT_SHARED_CACHE
  3091   3092     int nTableLock;        /* Number of locks in aTableLock */
  3092   3093     TableLock *aTableLock; /* Required table locks for shared-cache mode */
  3093   3094   #endif
  3094   3095     AutoincInfo *pAinc;  /* Information about AUTOINCREMENT counters */
  3095   3096     Parse *pToplevel;    /* Parse structure for main program (or NULL) */
  3096   3097     Table *pTriggerTab;  /* Table triggers are being coded for */
         3098  +  Parse *pParentParse; /* Parent parser if this parser is nested */
  3097   3099     int addrCrTab;       /* Address of OP_CreateBtree opcode on CREATE TABLE */
  3098   3100     u32 nQueryLoop;      /* Est number of iterations of a query (10*log2(N)) */
  3099   3101     u32 oldmask;         /* Mask of old.* columns referenced */
  3100   3102     u32 newmask;         /* Mask of new.* columns referenced */
  3101   3103     u8 eTriggerOp;       /* TK_UPDATE, TK_INSERT or TK_DELETE */
  3102   3104     u8 eOrconf;          /* Default ON CONFLICT policy for trigger steps */
  3103   3105     u8 disableTriggers;  /* True to disable triggers */

Changes to src/tokenize.c.

   556    556     int nErr = 0;                   /* Number of errors encountered */
   557    557     void *pEngine;                  /* The LEMON-generated LALR(1) parser */
   558    558     int n = 0;                      /* Length of the next token token */
   559    559     int tokenType;                  /* type of the next token */
   560    560     int lastTokenParsed = -1;       /* type of the previous token */
   561    561     sqlite3 *db = pParse->db;       /* The database connection */
   562    562     int mxSqlLen;                   /* Max length of an SQL string */
          563  +  VVA_ONLY( u8 startedWithOom = db->mallocFailed );
   563    564   #ifdef sqlite3Parser_ENGINEALWAYSONSTACK
   564    565     yyParser sEngine;    /* Space to hold the Lemon-generated Parser object */
   565    566   #endif
   566    567   
   567    568     assert( zSql!=0 );
   568    569     mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
   569    570     if( db->nVdbeActive==0 ){
................................................................................
   590    591       return SQLITE_NOMEM_BKPT;
   591    592     }
   592    593   #endif
   593    594     assert( pParse->pNewTable==0 );
   594    595     assert( pParse->pNewTrigger==0 );
   595    596     assert( pParse->nVar==0 );
   596    597     assert( pParse->pVList==0 );
          598  +  pParse->pParentParse = db->pParse;
          599  +  db->pParse = pParse;
   597    600     while( 1 ){
   598    601       n = sqlite3GetToken((u8*)zSql, &tokenType);
   599    602       mxSqlLen -= n;
   600    603       if( mxSqlLen<0 ){
   601    604         pParse->rc = SQLITE_TOOBIG;
   602    605         break;
   603    606       }
................................................................................
   646    649         }
   647    650       }
   648    651       pParse->sLastToken.z = zSql;
   649    652       pParse->sLastToken.n = n;
   650    653       sqlite3Parser(pEngine, tokenType, pParse->sLastToken);
   651    654       lastTokenParsed = tokenType;
   652    655       zSql += n;
   653         -    if( pParse->rc!=SQLITE_OK || db->mallocFailed ) break;
          656  +    assert( db->mallocFailed==0 || pParse->rc!=SQLITE_OK || startedWithOom );
          657  +    if( pParse->rc!=SQLITE_OK ) break;
   654    658     }
   655    659     assert( nErr==0 );
   656    660   #ifdef YYTRACKMAXSTACKDEPTH
   657    661     sqlite3_mutex_enter(sqlite3MallocMutex());
   658    662     sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
   659    663         sqlite3ParserStackPeak(pEngine)
   660    664     );
................................................................................
   714    718       sqlite3DbFreeNN(db, p);
   715    719     }
   716    720     while( pParse->pZombieTab ){
   717    721       Table *p = pParse->pZombieTab;
   718    722       pParse->pZombieTab = p->pNextZombie;
   719    723       sqlite3DeleteTable(db, p);
   720    724     }
          725  +  db->pParse = pParse->pParentParse;
          726  +  pParse->pParentParse = 0;
   721    727     assert( nErr==0 || pParse->rc!=SQLITE_OK );
   722    728     return nErr;
   723    729   }
   724    730   
   725    731   
   726    732   #ifdef SQLITE_ENABLE_NORMALIZE
   727    733   /*