/ Check-in [6d7d4703]
Login

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

Overview
Comment:Change the OP_SetCookie instruction to write the literal P3 value, not the value in register P3.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6d7d4703ebf3754bec74123d5ba7e861a705f90f
User & Date: drh 2016-02-01 21:48:34
Context
2016-02-02
02:04
Enhance the comment on the sqlite3_index_constraint object to bring attention to the fact than iColumn field can be negative for a rowid. check-in: d8b7b199 user: drh tags: trunk
00:59
Add the SQLITE_DBCONFIG_REQUIRE_WRITE_TXN connection setting, which if enabled requires all write operations to be enclosed within BEGIN ... COMMIT. Leaf check-in: 7453790c user: drh tags: require-write-txn
2016-02-01
21:48
Change the OP_SetCookie instruction to write the literal P3 value, not the value in register P3. check-in: 6d7d4703 user: drh tags: trunk
20:12
Improve performance of fts5 queries. check-in: 2334e882 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/alter.c.

   604    604       int r2 = sqlite3GetTempReg(pParse);
   605    605       int addr1;
   606    606       sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT);
   607    607       sqlite3VdbeUsesBtree(v, iDb);
   608    608       sqlite3VdbeAddOp2(v, OP_Integer, minFormat, r2);
   609    609       addr1 = sqlite3VdbeAddOp3(v, OP_Ge, r2, 0, r1);
   610    610       sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); VdbeCoverage(v);
   611         -    sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, r2);
          611  +    sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, minFormat);
   612    612       sqlite3VdbeJumpHere(v, addr1);
   613    613       sqlite3ReleaseTempReg(pParse, r1);
   614    614       sqlite3ReleaseTempReg(pParse, r2);
   615    615     }
   616    616   }
   617    617   
   618    618   /*

Changes to src/build.c.

   979    979       reg2 = pParse->regRoot = ++pParse->nMem;
   980    980       reg3 = ++pParse->nMem;
   981    981       sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, reg3, BTREE_FILE_FORMAT);
   982    982       sqlite3VdbeUsesBtree(v, iDb);
   983    983       addr1 = sqlite3VdbeAddOp1(v, OP_If, reg3); VdbeCoverage(v);
   984    984       fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
   985    985                     1 : SQLITE_MAX_FILE_FORMAT;
   986         -    sqlite3VdbeAddOp2(v, OP_Integer, fileFormat, reg3);
   987         -    sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, reg3);
   988         -    sqlite3VdbeAddOp2(v, OP_Integer, ENC(db), reg3);
   989         -    sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_TEXT_ENCODING, reg3);
          986  +    sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, fileFormat);
          987  +    sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_TEXT_ENCODING, ENC(db));
   990    988       sqlite3VdbeJumpHere(v, addr1);
   991    989   
   992    990       /* This just creates a place-holder record in the sqlite_master table.
   993    991       ** The record created does not contain anything yet.  It will be replaced
   994    992       ** by the real entry in code generated at sqlite3EndTable().
   995    993       **
   996    994       ** The rowid for the new entry is left in register pParse->regRowid.
................................................................................
  1467   1465   ** This plan is not completely bullet-proof.  It is possible for
  1468   1466   ** the schema to change multiple times and for the cookie to be
  1469   1467   ** set back to prior value.  But schema changes are infrequent
  1470   1468   ** and the probability of hitting the same cookie value is only
  1471   1469   ** 1 chance in 2^32.  So we're safe enough.
  1472   1470   */
  1473   1471   void sqlite3ChangeCookie(Parse *pParse, int iDb){
  1474         -  int r1 = sqlite3GetTempReg(pParse);
  1475   1472     sqlite3 *db = pParse->db;
  1476   1473     Vdbe *v = pParse->pVdbe;
  1477   1474     assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
  1478         -  sqlite3VdbeAddOp2(v, OP_Integer, db->aDb[iDb].pSchema->schema_cookie+1, r1);
  1479         -  sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_SCHEMA_VERSION, r1);
  1480         -  sqlite3ReleaseTempReg(pParse, r1);
         1475  +  sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_SCHEMA_VERSION, 
         1476  +                    db->aDb[iDb].pSchema->schema_cookie+1);
  1481   1477   }
  1482   1478   
  1483   1479   /*
  1484   1480   ** Measure the number of characters needed to output the given
  1485   1481   ** identifier.  The number returned includes any quotes used
  1486   1482   ** but does not include the null terminator.
  1487   1483   **

Changes to src/pragma.c.

   440    440         if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
   441    441         aOp[0].p1 = iDb;
   442    442         aOp[1].p1 = iDb;
   443    443         aOp[6].p1 = SQLITE_DEFAULT_CACHE_SIZE;
   444    444       }else{
   445    445         int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
   446    446         sqlite3BeginWriteOperation(pParse, 0, iDb);
   447         -      sqlite3VdbeAddOp2(v, OP_Integer, size, 1);
   448         -      sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, 1);
          447  +      sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_DEFAULT_CACHE_SIZE, size);
   449    448         assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
   450    449         pDb->pSchema->cache_size = size;
   451    450         sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
   452    451       }
   453    452       break;
   454    453     }
   455    454   #endif /* !SQLITE_OMIT_PAGER_PRAGMAS && !SQLITE_OMIT_DEPRECATED */
................................................................................
   679    678           */
   680    679           static const int iLn = VDBE_OFFSET_LINENO(2);
   681    680           static const VdbeOpList setMeta6[] = {
   682    681             { OP_Transaction,    0,         1,                 0},    /* 0 */
   683    682             { OP_ReadCookie,     0,         1,         BTREE_LARGEST_ROOT_PAGE},
   684    683             { OP_If,             1,         0,                 0},    /* 2 */
   685    684             { OP_Halt,           SQLITE_OK, OE_Abort,          0},    /* 3 */
   686         -          { OP_Integer,        0,         1,                 0},    /* 4 */
   687         -          { OP_SetCookie,      0,         BTREE_INCR_VACUUM, 1},    /* 5 */
          685  +          { OP_SetCookie,      0,         BTREE_INCR_VACUUM, 0},    /* 4 */
   688    686           };
   689    687           VdbeOp *aOp;
   690    688           int iAddr = sqlite3VdbeCurrentAddr(v);
   691    689           sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(setMeta6));
   692    690           aOp = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6, iLn);
   693    691           if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
   694    692           aOp[0].p1 = iDb;
   695    693           aOp[1].p1 = iDb;
   696    694           aOp[2].p2 = iAddr+4;
   697         -        aOp[4].p1 = eAuto - 1;
   698         -        aOp[5].p1 = iDb;
          695  +        aOp[4].p1 = iDb;
          696  +        aOp[4].p3 = eAuto - 1;
   699    697           sqlite3VdbeUsesBtree(v, iDb);
   700    698         }
   701    699       }
   702    700       break;
   703    701     }
   704    702   #endif
   705    703   
................................................................................
  1724   1722     case PragTyp_HEADER_VALUE: {
  1725   1723       int iCookie = pPragma->iArg;  /* Which cookie to read or write */
  1726   1724       sqlite3VdbeUsesBtree(v, iDb);
  1727   1725       if( zRight && (pPragma->mPragFlag & PragFlag_ReadOnly)==0 ){
  1728   1726         /* Write the specified cookie value */
  1729   1727         static const VdbeOpList setCookie[] = {
  1730   1728           { OP_Transaction,    0,  1,  0},    /* 0 */
  1731         -        { OP_Integer,        0,  1,  0},    /* 1 */
  1732         -        { OP_SetCookie,      0,  0,  1},    /* 2 */
         1729  +        { OP_SetCookie,      0,  0,  0},    /* 1 */
  1733   1730         };
  1734   1731         VdbeOp *aOp;
  1735   1732         sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(setCookie));
  1736   1733         aOp = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0);
  1737   1734         if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
  1738   1735         aOp[0].p1 = iDb;
  1739         -      aOp[1].p1 = sqlite3Atoi(zRight);
  1740         -      aOp[2].p1 = iDb;
  1741         -      aOp[2].p2 = iCookie;
         1736  +      aOp[1].p1 = iDb;
         1737  +      aOp[1].p2 = iCookie;
         1738  +      aOp[1].p3 = sqlite3Atoi(zRight);
  1742   1739       }else{
  1743   1740         /* Read the specified cookie value */
  1744   1741         static const VdbeOpList readCookie[] = {
  1745   1742           { OP_Transaction,     0,  0,  0},    /* 0 */
  1746   1743           { OP_ReadCookie,      0,  1,  0},    /* 1 */
  1747   1744           { OP_ResultRow,       1,  1,  0}
  1748   1745         };

Changes to src/vdbe.c.

  3209   3209     pOut = out2Prerelease(p, pOp);
  3210   3210     pOut->u.i = iMeta;
  3211   3211     break;
  3212   3212   }
  3213   3213   
  3214   3214   /* Opcode: SetCookie P1 P2 P3 * *
  3215   3215   **
  3216         -** Write the content of register P3 (interpreted as an integer)
  3217         -** into cookie number P2 of database P1.  P2==1 is the schema version.  
  3218         -** P2==2 is the database format. P2==3 is the recommended pager cache 
         3216  +** Write the integer value P3 into cookie number P2 of database P1.
         3217  +** P2==1 is the schema version.  P2==2 is the database format.
         3218  +** P2==3 is the recommended pager cache 
  3219   3219   ** size, and so forth.  P1==0 is the main database file and P1==1 is the 
  3220   3220   ** database file used to store temporary tables.
  3221   3221   **
  3222   3222   ** A transaction must be started before executing this opcode.
  3223   3223   */
  3224         -case OP_SetCookie: {       /* in3 */
         3224  +case OP_SetCookie: {
  3225   3225     Db *pDb;
  3226   3226     assert( pOp->p2<SQLITE_N_BTREE_META );
  3227   3227     assert( pOp->p1>=0 && pOp->p1<db->nDb );
  3228   3228     assert( DbMaskTest(p->btreeMask, pOp->p1) );
  3229   3229     assert( p->readOnly==0 );
  3230   3230     pDb = &db->aDb[pOp->p1];
  3231   3231     assert( pDb->pBt!=0 );
  3232   3232     assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
  3233         -  pIn3 = &aMem[pOp->p3];
  3234         -  sqlite3VdbeMemIntegerify(pIn3);
  3235   3233     /* See note about index shifting on OP_ReadCookie */
  3236         -  rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, (int)pIn3->u.i);
         3234  +  rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, pOp->p3);
  3237   3235     if( pOp->p2==BTREE_SCHEMA_VERSION ){
  3238   3236       /* When the schema cookie changes, record the new cookie internally */
  3239         -    pDb->pSchema->schema_cookie = (int)pIn3->u.i;
         3237  +    pDb->pSchema->schema_cookie = pOp->p3;
  3240   3238       db->flags |= SQLITE_InternChanges;
  3241   3239     }else if( pOp->p2==BTREE_FILE_FORMAT ){
  3242   3240       /* Record changes in the file format */
  3243         -    pDb->pSchema->file_format = (u8)pIn3->u.i;
         3241  +    pDb->pSchema->file_format = pOp->p3;
  3244   3242     }
  3245   3243     if( pOp->p1==1 ){
  3246   3244       /* Invalidate all prepared statements whenever the TEMP database
  3247   3245       ** schema is changed.  Ticket #1644 */
  3248   3246       sqlite3ExpirePreparedStatements(db);
  3249   3247       p->expired = 0;
  3250   3248     }