/ Check-in [957b2ab6]
Login

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

Overview
Comment:Create and use a function especially for adding the ParseSchema opcode. This gives a small reduction in code and a small performance increase.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 957b2ab67c6185f0e1062593d237de5c434a38bf
User & Date: drh 2011-06-03 20:11:17
References
2011-06-26
23:07 New ticket [25ee8127] PRAGMA case_sensitive_like=1 fails. artifact: aab555b0 user: drh
Context
2011-06-03
21:34
Performance enhancement to the blob-literal tokenizer. check-in: 61aa2031 user: drh tags: trunk
20:11
Create and use a function especially for adding the ParseSchema opcode. This gives a small reduction in code and a small performance increase. check-in: 957b2ab6 user: drh tags: trunk
17:50
Factor an "if" out of a loop in balance_nonroot() for about a 1% performance increase. check-in: 1bd72d0c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/alter.c.

   354    354   
   355    355     /* Drop the table and index from the internal schema.  */
   356    356     sqlite3VdbeAddOp4(v, OP_DropTable, iDb, 0, 0, pTab->zName, 0);
   357    357   
   358    358     /* Reload the table, index and permanent trigger schemas. */
   359    359     zWhere = sqlite3MPrintf(pParse->db, "tbl_name=%Q", zName);
   360    360     if( !zWhere ) return;
   361         -  sqlite3VdbeAddOp4(v, OP_ParseSchema, iDb, 0, 0, zWhere, P4_DYNAMIC);
          361  +  sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere);
   362    362   
   363    363   #ifndef SQLITE_OMIT_TRIGGER
   364    364     /* Now, if the table is not stored in the temp database, reload any temp 
   365    365     ** triggers. Don't use IN(...) in case SQLITE_OMIT_SUBQUERY is defined. 
   366    366     */
   367    367     if( (zWhere=whereTempTriggers(pParse, pTab))!=0 ){
   368         -    sqlite3VdbeAddOp4(v, OP_ParseSchema, 1, 0, 0, zWhere, P4_DYNAMIC);
          368  +    sqlite3VdbeAddParseSchemaOp(v, 1, zWhere);
   369    369     }
   370    370   #endif
   371    371   }
   372    372   
   373    373   /*
   374    374   ** Parameter zName is the name of a table that is about to be altered
   375    375   ** (either with ALTER TABLE ... RENAME TO or ALTER TABLE ... ADD COLUMN).

Changes to src/build.c.

  1615   1615             pDb->zName
  1616   1616           );
  1617   1617         }
  1618   1618       }
  1619   1619   #endif
  1620   1620   
  1621   1621       /* Reparse everything to update our internal data structures */
  1622         -    sqlite3VdbeAddOp4(v, OP_ParseSchema, iDb, 0, 0,
  1623         -        sqlite3MPrintf(db, "tbl_name='%q'",p->zName), P4_DYNAMIC);
         1622  +    sqlite3VdbeAddParseSchemaOp(v, iDb,
         1623  +               sqlite3MPrintf(db, "tbl_name='%q'", p->zName));
  1624   1624     }
  1625   1625   
  1626   1626   
  1627   1627     /* Add the table to the in-memory representation of the database.
  1628   1628     */
  1629   1629     if( db->init.busy ){
  1630   1630       Table *pOld;
................................................................................
  2813   2813   
  2814   2814       /* Fill the index with data and reparse the schema. Code an OP_Expire
  2815   2815       ** to invalidate all pre-compiled statements.
  2816   2816       */
  2817   2817       if( pTblName ){
  2818   2818         sqlite3RefillIndex(pParse, pIndex, iMem);
  2819   2819         sqlite3ChangeCookie(pParse, iDb);
  2820         -      sqlite3VdbeAddOp4(v, OP_ParseSchema, iDb, 0, 0,
  2821         -         sqlite3MPrintf(db, "name='%q' AND type='index'", pIndex->zName), 
  2822         -         P4_DYNAMIC);
         2820  +      sqlite3VdbeAddParseSchemaOp(v, iDb,
         2821  +         sqlite3MPrintf(db, "name='%q' AND type='index'", pIndex->zName));
  2823   2822         sqlite3VdbeAddOp1(v, OP_Expire, 0);
  2824   2823       }
  2825   2824     }
  2826   2825   
  2827   2826     /* When adding an index to the list of indices for a table, make
  2828   2827     ** sure all indices labeled OE_Replace come after all those labeled
  2829   2828     ** OE_Ignore.  This is necessary for the correct constraint check

Changes to src/trigger.c.

   297    297       z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
   298    298       sqlite3NestedParse(pParse,
   299    299          "INSERT INTO %Q.%s VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
   300    300          db->aDb[iDb].zName, SCHEMA_TABLE(iDb), zName,
   301    301          pTrig->table, z);
   302    302       sqlite3DbFree(db, z);
   303    303       sqlite3ChangeCookie(pParse, iDb);
   304         -    sqlite3VdbeAddOp4(v, OP_ParseSchema, iDb, 0, 0, sqlite3MPrintf(
   305         -        db, "type='trigger' AND name='%q'", zName), P4_DYNAMIC
   306         -    );
          304  +    sqlite3VdbeAddParseSchemaOp(v, iDb,
          305  +        sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
   307    306     }
   308    307   
   309    308     if( db->init.busy ){
   310    309       Trigger *pLink = pTrig;
   311    310       Hash *pHash = &db->aDb[iDb].pSchema->trigHash;
   312    311       assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
   313    312       pTrig = sqlite3HashInsert(pHash, zName, sqlite3Strlen30(zName), pTrig);

Changes to src/vdbe.h.

   168    168   int sqlite3VdbeAddOp0(Vdbe*,int);
   169    169   int sqlite3VdbeAddOp1(Vdbe*,int,int);
   170    170   int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
   171    171   int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
   172    172   int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
   173    173   int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
   174    174   int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
          175  +void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
   175    176   void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
   176    177   void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
   177    178   void sqlite3VdbeChangeP3(Vdbe*, int addr, int P3);
   178    179   void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
   179    180   void sqlite3VdbeJumpHere(Vdbe*, int addr);
   180    181   void sqlite3VdbeChangeToNoop(Vdbe*, int addr, int N);
   181    182   void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N);

Changes to src/vdbeaux.c.

   152    152     pOp->opcode = (u8)op;
   153    153     pOp->p5 = 0;
   154    154     pOp->p1 = p1;
   155    155     pOp->p2 = p2;
   156    156     pOp->p3 = p3;
   157    157     pOp->p4.p = 0;
   158    158     pOp->p4type = P4_NOTUSED;
   159         -  p->expired = 0;
   160         -  if( op==OP_ParseSchema ){
   161         -    /* Any program that uses the OP_ParseSchema opcode needs to lock
   162         -    ** all btrees. */
   163         -    int j;
   164         -    for(j=0; j<p->db->nDb; j++) sqlite3VdbeUsesBtree(p, j);
   165         -  }
   166    159   #ifdef SQLITE_DEBUG
   167    160     pOp->zComment = 0;
   168    161     if( sqlite3VdbeAddopTrace ) sqlite3VdbePrintOp(0, i, &p->aOp[i]);
   169    162   #endif
   170    163   #ifdef VDBE_PROFILE
   171    164     pOp->cycles = 0;
   172    165     pOp->cnt = 0;
................................................................................
   196    189     const char *zP4,    /* The P4 operand */
   197    190     int p4type          /* P4 operand type */
   198    191   ){
   199    192     int addr = sqlite3VdbeAddOp3(p, op, p1, p2, p3);
   200    193     sqlite3VdbeChangeP4(p, addr, zP4, p4type);
   201    194     return addr;
   202    195   }
          196  +
          197  +/*
          198  +** Add an OP_ParseSchema opcode.  This routine is broken out from
          199  +** sqlite3VdbeAddOp4() since it needs to also local all btrees.
          200  +**
          201  +** The zWhere string must have been obtained from sqlite3_malloc().
          202  +** This routine will take ownership of the allocated memory.
          203  +*/
          204  +void sqlite3VdbeAddParseSchemaOp(Vdbe *p, int iDb, char *zWhere){
          205  +  int j;
          206  +  int addr = sqlite3VdbeAddOp3(p, OP_ParseSchema, iDb, 0, 0);
          207  +  sqlite3VdbeChangeP4(p, addr, zWhere, P4_DYNAMIC);
          208  +  for(j=0; j<p->db->nDb; j++) sqlite3VdbeUsesBtree(p, j);
          209  +}
   203    210   
   204    211   /*
   205    212   ** Add an opcode that includes the p4 value as an integer.
   206    213   */
   207    214   int sqlite3VdbeAddOp4Int(
   208    215     Vdbe *p,            /* Add the opcode to this VM */
   209    216     int op,             /* The new opcode */

Changes to src/vtab.c.

   379    379       );
   380    380       sqlite3DbFree(db, zStmt);
   381    381       v = sqlite3GetVdbe(pParse);
   382    382       sqlite3ChangeCookie(pParse, iDb);
   383    383   
   384    384       sqlite3VdbeAddOp2(v, OP_Expire, 0, 0);
   385    385       zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName);
   386         -    sqlite3VdbeAddOp4(v, OP_ParseSchema, iDb, 0, 0, zWhere, P4_DYNAMIC);
          386  +    sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere);
   387    387       sqlite3VdbeAddOp4(v, OP_VCreate, iDb, 0, 0, 
   388    388                            pTab->zName, sqlite3Strlen30(pTab->zName) + 1);
   389    389     }
   390    390   
   391    391     /* If we are rereading the sqlite_master table create the in-memory
   392    392     ** record of the table. The xConnect() method is not called until
   393    393     ** the first time the virtual table is used in an SQL statement. This