/ Check-in [d2c047f3]
Login

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

Overview
Comment:Add the SQLITE_NOTNULL P5 code for comparison operations - really a composite of SQLITE_NULLEQ and SQLITE_JUMPIFNULL. This flag indicates that NULL operands are not possible and raises and assert() if NULL operands are seen. Also omit an unnecessary scan of the sqlite_sequence table when writing into an AUTOINCREMENT table.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d2c047f304848e49864ed8c216b48fd671fa3916
User & Date: drh 2014-02-19 14:20:49
Context
2014-02-19
19:14
Add the VdbeCoverageNeverTaken() macro, and comments that better describe how the VDBE branch coverage measurement works. Add some tags to provide 100% VDBE branch coverage. check-in: c1e94169 user: drh tags: trunk
14:20
Add the SQLITE_NOTNULL P5 code for comparison operations - really a composite of SQLITE_NULLEQ and SQLITE_JUMPIFNULL. This flag indicates that NULL operands are not possible and raises and assert() if NULL operands are seen. Also omit an unnecessary scan of the sqlite_sequence table when writing into an AUTOINCREMENT table. check-in: d2c047f3 user: drh tags: trunk
01:31
Make sure a multi-row VALUES clause works correctly in a compound SELECT. check-in: 85b355cf user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/alter.c.

   601    601       int r1 = sqlite3GetTempReg(pParse);
   602    602       int r2 = sqlite3GetTempReg(pParse);
   603    603       int j1;
   604    604       sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT);
   605    605       sqlite3VdbeUsesBtree(v, iDb);
   606    606       sqlite3VdbeAddOp2(v, OP_Integer, minFormat, r2);
   607    607       j1 = sqlite3VdbeAddOp3(v, OP_Ge, r2, 0, r1);
   608         -    sqlite3VdbeChangeP5(v, SQLITE_NULLEQ); VdbeCoverage(v);
          608  +    sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); VdbeCoverage(v);
   609    609       sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, r2);
   610    610       sqlite3VdbeJumpHere(v, j1);
   611    611       sqlite3ReleaseTempReg(pParse, r1);
   612    612       sqlite3ReleaseTempReg(pParse, r2);
   613    613     }
   614    614   }
   615    615   

Changes to src/fkey.c.

   365    365     
   366    366         /* If the parent table is the same as the child table, and we are about
   367    367         ** to increment the constraint-counter (i.e. this is an INSERT operation),
   368    368         ** then check if the row being inserted matches itself. If so, do not
   369    369         ** increment the constraint-counter.  */
   370    370         if( pTab==pFKey->pFrom && nIncr==1 ){
   371    371           sqlite3VdbeAddOp3(v, OP_Eq, regData, iOk, regTemp); VdbeCoverage(v);
          372  +        sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
   372    373         }
   373    374     
   374    375         sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
   375    376         sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp); VdbeCoverage(v);
   376    377         sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
   377    378         sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
   378    379         sqlite3VdbeJumpHere(v, iMustBeInt);

Changes to src/insert.c.

   300    300     AutoincInfo *p;
   301    301     Vdbe *v = pParse->pVdbe;
   302    302     sqlite3 *db = pParse->db;
   303    303   
   304    304     assert( v );
   305    305     for(p = pParse->pAinc; p; p = p->pNext){
   306    306       Db *pDb = &db->aDb[p->iDb];
   307         -    int j1, j2, j3, j4, j5;
          307  +    int j1;
   308    308       int iRec;
   309    309       int memId = p->regCtr;
   310    310   
   311    311       iRec = sqlite3GetTempReg(pParse);
   312    312       assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
   313    313       sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite);
   314    314       j1 = sqlite3VdbeAddOp1(v, OP_NotNull, memId+1); VdbeCoverage(v);
   315         -    j2 = sqlite3VdbeAddOp0(v, OP_Rewind); VdbeCoverage(v);
   316         -    j3 = sqlite3VdbeAddOp3(v, OP_Column, 0, 0, iRec);
   317         -    j4 = sqlite3VdbeAddOp3(v, OP_Eq, memId-1, 0, iRec); VdbeCoverage(v);
   318         -    sqlite3VdbeAddOp2(v, OP_Next, 0, j3); VdbeCoverage(v);
   319         -    sqlite3VdbeJumpHere(v, j2);
   320    315       sqlite3VdbeAddOp2(v, OP_NewRowid, 0, memId+1);
   321         -    j5 = sqlite3VdbeAddOp0(v, OP_Goto);
   322         -    sqlite3VdbeJumpHere(v, j4);
   323         -    sqlite3VdbeAddOp2(v, OP_Rowid, 0, memId+1);
   324    316       sqlite3VdbeJumpHere(v, j1);
   325         -    sqlite3VdbeJumpHere(v, j5);
   326    317       sqlite3VdbeAddOp3(v, OP_MakeRecord, memId-1, 2, iRec);
   327    318       sqlite3VdbeAddOp3(v, OP_Insert, 0, iRec, memId+1);
   328    319       sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
   329    320       sqlite3VdbeAddOp0(v, OP_Close);
   330    321       sqlite3ReleaseTempReg(pParse, iRec);
   331    322     }
   332    323   }
................................................................................
  1271   1262       }
  1272   1263   
  1273   1264       if( isUpdate ){
  1274   1265         /* pkChng!=0 does not mean that the rowid has change, only that
  1275   1266         ** it might have changed.  Skip the conflict logic below if the rowid
  1276   1267         ** is unchanged. */
  1277   1268         sqlite3VdbeAddOp3(v, OP_Eq, regNewData, addrRowidOk, regOldData);
         1269  +      sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
  1278   1270         VdbeCoverage(v);
  1279   1271       }
  1280   1272   
  1281   1273       /* If the response to a rowid conflict is REPLACE but the response
  1282   1274       ** to some other UNIQUE constraint is FAIL or IGNORE, then we need
  1283   1275       ** to defer the running of the rowid conflict checking until after
  1284   1276       ** the UNIQUE constraints have run.
................................................................................
  1442   1434       if( isUpdate || onError==OE_Replace ){
  1443   1435         if( HasRowid(pTab) ){
  1444   1436           sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR);
  1445   1437           /* Conflict only if the rowid of the existing index entry
  1446   1438           ** is different from old-rowid */
  1447   1439           if( isUpdate ){
  1448   1440             sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData);
         1441  +          sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
  1449   1442             VdbeCoverage(v);
  1450   1443           }
  1451   1444         }else{
  1452   1445           int x;
  1453   1446           /* Extract the PRIMARY KEY from the end of the index entry and
  1454   1447           ** store it in registers regR..regR+nPk-1 */
  1455   1448           if( pIdx!=pPk ){
................................................................................
  1477   1470               x = pPk->aiColumn[i];
  1478   1471               if( i==(pPk->nKeyCol-1) ){
  1479   1472                 addrJump = addrUniqueOk;
  1480   1473                 op = OP_Eq;
  1481   1474               }
  1482   1475               sqlite3VdbeAddOp4(v, op, 
  1483   1476                   regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ
  1484         -            );  VdbeCoverage(v);
         1477  +            );
         1478  +            sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
         1479  +            VdbeCoverageIf(v, op==OP_Eq);
         1480  +            VdbeCoverageIf(v, op==OP_Ne);
  1485   1481             }
  1486   1482           }
  1487   1483         }
  1488   1484       }
  1489   1485   
  1490   1486       /* Generate code that executes if the new index entry is not unique */
  1491   1487       assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail

Changes to src/sqliteInt.h.

  1310   1310   ** affinity value. 
  1311   1311   */
  1312   1312   #define SQLITE_AFF_MASK     0x67
  1313   1313   
  1314   1314   /*
  1315   1315   ** Additional bit values that can be ORed with an affinity without
  1316   1316   ** changing the affinity.
         1317  +**
         1318  +** The SQLITE_NOTNULL flag is a combination of NULLEQ and JUMPIFNULL.
         1319  +** It causes an assert() to fire if either operand to a comparison
         1320  +** operator is NULL.  It is added to certain comparison operators to
         1321  +** prove that the operands are always NOT NULL.
  1317   1322   */
  1318   1323   #define SQLITE_JUMPIFNULL   0x08  /* jumps if either operand is NULL */
  1319   1324   #define SQLITE_STOREP2      0x10  /* Store result in reg[P2] rather than jump */
  1320   1325   #define SQLITE_NULLEQ       0x80  /* NULL=NULL */
         1326  +#define SQLITE_NOTNULL      0x88  /* Assert that operands are never NULL */
  1321   1327   
  1322   1328   /*
  1323   1329   ** An object of this type is created for each virtual table present in
  1324   1330   ** the database schema. 
  1325   1331   **
  1326   1332   ** If the database schema is shared, then there is one instance of this
  1327   1333   ** structure for each database connection (sqlite3*) that uses the shared

Changes to src/vdbe.c.

  1887   1887       if( pOp->p5 & SQLITE_NULLEQ ){
  1888   1888         /* If SQLITE_NULLEQ is set (which will only happen if the operator is
  1889   1889         ** OP_Eq or OP_Ne) then take the jump or not depending on whether
  1890   1890         ** or not both operands are null.
  1891   1891         */
  1892   1892         assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
  1893   1893         assert( (flags1 & MEM_Cleared)==0 );
         1894  +      assert( (pOp->p5 & SQLITE_JUMPIFNULL)==0 );
  1894   1895         if( (flags1&MEM_Null)!=0
  1895   1896          && (flags3&MEM_Null)!=0
  1896   1897          && (flags3&MEM_Cleared)==0
  1897   1898         ){
  1898   1899           res = 0;  /* Results are equal */
  1899   1900         }else{
  1900   1901           res = 1;  /* Results are not equal */
................................................................................
  4829   4830   ** See also: Destroy
  4830   4831   */
  4831   4832   case OP_Clear: {
  4832   4833     int nChange;
  4833   4834    
  4834   4835     nChange = 0;
  4835   4836     assert( p->readOnly==0 );
  4836         -  assert( pOp->p1!=1 );
  4837   4837     assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 );
  4838   4838     rc = sqlite3BtreeClearTable(
  4839   4839         db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
  4840   4840     );
  4841   4841     if( pOp->p3 ){
  4842   4842       p->nChange += nChange;
  4843   4843       if( pOp->p3>0 ){