SQLite

Check-in [d051694e02]
Login

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

Overview
Comment:Disable the truncate optimization if there is a preupdate hook.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | sessions
Files: files | file ages | folders
SHA1: d051694e024c590e4687cae1368f900799b7442d
User & Date: drh 2011-03-30 17:25:35.303
Context
2011-03-30
21:04
Add the SQLITE_ENABLE_PREUPDATE_HOOK compile-time option. (check-in: 6634521461 user: drh tags: sessions)
17:25
Disable the truncate optimization if there is a preupdate hook. (check-in: d051694e02 user: drh tags: sessions)
17:07
Add documentation to the sqlite3_preupdate_hook() interface and its relatives. (check-in: 8180f2881f user: drh tags: sessions)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/delete.c.
334
335
336
337
338
339
340
341

342




343
344
345
346
347
348
349
    sqlite3VdbeAddOp2(v, OP_Integer, 0, memCnt);
  }

#ifndef SQLITE_OMIT_TRUNCATE_OPTIMIZATION
  /* Special case: A DELETE without a WHERE clause deletes everything.
  ** It is easier just to erase the whole table. Prior to version 3.6.5,
  ** this optimization caused the row change count (the value returned by 
  ** API function sqlite3_count_changes) to be set incorrectly.  */

  if( rcauth==SQLITE_OK && pWhere==0 && !pTrigger && !IsVirtual(pTab) 




   && 0==sqlite3FkRequired(pParse, pTab, 0, 0)
  ){
    assert( !isView );
    sqlite3VdbeAddOp4(v, OP_Clear, pTab->tnum, iDb, memCnt,
                      pTab->zName, P4_STATIC);
    for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
      assert( pIdx->pSchema==pTab->pSchema );







|
>
|
>
>
>
>







334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
    sqlite3VdbeAddOp2(v, OP_Integer, 0, memCnt);
  }

#ifndef SQLITE_OMIT_TRUNCATE_OPTIMIZATION
  /* Special case: A DELETE without a WHERE clause deletes everything.
  ** It is easier just to erase the whole table. Prior to version 3.6.5,
  ** this optimization caused the row change count (the value returned by 
  ** API function sqlite3_count_changes) to be set incorrectly.
  */
  if( rcauth==SQLITE_OK
   && pWhere==0
   && !pTrigger
   && !IsVirtual(pTab) 
   && db->xPreUpdateCallback==0
   && 0==sqlite3FkRequired(pParse, pTab, 0, 0)
  ){
    assert( !isView );
    sqlite3VdbeAddOp4(v, OP_Clear, pTab->tnum, iDb, memCnt,
                      pTab->zName, P4_STATIC);
    for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
      assert( pIdx->pSchema==pTab->pSchema );
Changes to test/hook.test.
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
  DELETE FROM t1 WHERE rowid = 3
} {
  DELETE main t1 3 3  d c
}
do_preupdate_test 7.2.2 {
  DELETE FROM t1
} {
  DELETE main t3 1 1   1 1
  DELETE main t3 2 2   b a
  DELETE main t3 4 4   a b
  DELETE main t3 5 5   c d
}

do_execsql_test 7.3.0 { 
  DELETE FROM t1;
  DELETE FROM t2;
  DELETE FROM t3;








|
|
|
|







477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
  DELETE FROM t1 WHERE rowid = 3
} {
  DELETE main t1 3 3  d c
}
do_preupdate_test 7.2.2 {
  DELETE FROM t1
} {
  DELETE main t1 1 1   1 1
  DELETE main t1 2 2   b a
  DELETE main t1 4 4   a b
  DELETE main t1 5 5   c d
}

do_execsql_test 7.3.0 { 
  DELETE FROM t1;
  DELETE FROM t2;
  DELETE FROM t3;

761
762
763
764
765
766
767
768
  DELETE main t4 1 1   3      abc
  DELETE main t3 1 1   2      abc
  DELETE main t2 1 1   1      abc
  DELETE main t1 1 1   0      abc
}

finish_test








<
761
762
763
764
765
766
767

  DELETE main t4 1 1   3      abc
  DELETE main t3 1 1   2      abc
  DELETE main t2 1 1   1      abc
  DELETE main t1 1 1   0      abc
}

finish_test