SQLite

Check-in [0b485a571c]
Login

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

Overview
Comment:Fix the column cache invalidation logic in the code for ROWID uniqueness constraint checking in the INSERT command. This fixes ticket [c2432ef9089ee73bd].
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0b485a571c805a5bc431a231a196ff6034342c6548d92b09c52814dd57c89c75
User & Date: drh 2018-06-11 18:06:48.831
Context
2018-06-11
19:47
Fix various --enable and --disable options on the top-level configure script. (check-in: 6fd7e8ceb9 user: drh tags: trunk)
18:06
Fix the column cache invalidation logic in the code for ROWID uniqueness constraint checking in the INSERT command. This fixes ticket [c2432ef9089ee73bd]. (check-in: 0b485a571c user: drh tags: trunk)
17:35
Add the OP_SetTabCol and OP_VerifyTabCol opcodes, only when compiling with SQLITE_DEBUG, to do run-time verification of the column cache. (check-in: b37614a367 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/insert.c.
1529
1530
1531
1532
1533
1534
1535

1536
1537
1538
1539
1540
1541
1542

    /* Check to see if the new rowid already exists in the table.  Skip
    ** the following conflict logic if it does not. */
    VdbeNoopComment((v, "uniqueness check for ROWID"));
    sqlite3VdbeVerifyAbortable(v, onError);
    sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, addrRowidOk, regNewData);
    VdbeCoverage(v);


    switch( onError ){
      default: {
        onError = OE_Abort;
        /* Fall thru into the next case */
      }
      case OE_Rollback:







>







1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543

    /* Check to see if the new rowid already exists in the table.  Skip
    ** the following conflict logic if it does not. */
    VdbeNoopComment((v, "uniqueness check for ROWID"));
    sqlite3VdbeVerifyAbortable(v, onError);
    sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, addrRowidOk, regNewData);
    VdbeCoverage(v);
    sqlite3ExprCachePush(pParse);

    switch( onError ){
      default: {
        onError = OE_Abort;
        /* Fall thru into the next case */
      }
      case OE_Rollback:
1605
1606
1607
1608
1609
1610
1611

1612
1613
1614
1615
1616
1617
1618
#endif
      case OE_Ignore: {
        testcase( onError==OE_Ignore );
        sqlite3VdbeGoto(v, ignoreDest);
        break;
      }
    }

    sqlite3VdbeResolveLabel(v, addrRowidOk);
    if( sAddr.ipkTop ){
      sAddr.ipkBtm = sqlite3VdbeAddOp0(v, OP_Goto);
      sqlite3VdbeJumpHere(v, sAddr.ipkTop-1);
    }
  }








>







1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
#endif
      case OE_Ignore: {
        testcase( onError==OE_Ignore );
        sqlite3VdbeGoto(v, ignoreDest);
        break;
      }
    }
    sqlite3ExprCachePop(pParse);
    sqlite3VdbeResolveLabel(v, addrRowidOk);
    if( sAddr.ipkTop ){
      sAddr.ipkBtm = sqlite3VdbeAddOp0(v, OP_Goto);
      sqlite3VdbeJumpHere(v, sAddr.ipkTop-1);
    }
  }

Changes to test/insert.test.
431
432
433
434
435
436
437













438
439
440
441
} {11 22}
do_execsql_test insert-12.3 {
  CREATE TABLE t12c(a, b DEFAULT 'xyzzy', c);
  INSERT INTO t12c(a, rowid, c) SELECT 'one', 999, 'two';
  SELECT * FROM t12c;
} {one xyzzy two}















integrity_check insert-99.0

finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>




431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
} {11 22}
do_execsql_test insert-12.3 {
  CREATE TABLE t12c(a, b DEFAULT 'xyzzy', c);
  INSERT INTO t12c(a, rowid, c) SELECT 'one', 999, 'two';
  SELECT * FROM t12c;
} {one xyzzy two}

# 2018-06-11.  From OSSFuzz.  A column cache malfunction in
# the constraint checking on an index of expressions causes
# an assertion fault in a REPLACE.  Ticket
# https://www.sqlite.org/src/info/c2432ef9089ee73b
#
do_execsql_test insert-13.1 {
  DROP TABLE IF EXISTS t13;
  CREATE TABLE t13(a INTEGER PRIMARY KEY,b UNIQUE);
  CREATE INDEX t13x1 ON t13(-b=b);
  INSERT INTO t13 VALUES(1,5),(6,2);
  REPLACE INTO t13 SELECT b,0 FROM t13;
  SELECT * FROM t13 ORDER BY +b;
} {2 0 6 2 1 5}

integrity_check insert-99.0

finish_test