ROLLBACK TO stmt within committed transaction cause write operation to the WAL file.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ROLLBACK TO stmt within committed transaction cause write operation to the WAL file.

sanhua.zh
Here is the reproduction path.


```
sqlite3 db
PRAGMA journal_mode=WAL;
CREATE TABLE t(i INTEGER);
INSERT INTO t VALUES(1);
PRAGMA wal_checkpoint=TRUNCATE;


// check the WAL file size without checkpoint/close sqlite connection
ls -l | grep wal
// print 0 db-wal


BEGIN IMMEDIATE;
SAVEPOINT s1;
INSERT INTO t VALUES(2);
ROLLBACK TO SAVEPOINT s1;
COMMIT;


SELECT * FROM t;
// print 1


// check the WAL file size without checkpoint/close sqlite connection
ls -l | grep wal
// print 4152 db-wal
```


As you can see, the insertion inside the transaction is not effective, which is as expected.
The strange thing is that the size of WAL file is changed, which means that SOMETHING appended into the end of WAL file.
BUT why? We should have nothing to write.
Is it a bug?
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: ROLLBACK TO stmt within committed transaction cause write operation to the WAL file.

Clemens Ladisch
sanhua.zh wrote:
>BEGIN IMMEDIATE;
>SAVEPOINT s1;
>INSERT INTO t VALUES(2);
>ROLLBACK TO SAVEPOINT s1;
>COMMIT;

>SOMETHING appended into the end of WAL file.
>BUT why? We should have nothing to write.

It's information about the WAL file itself.

The WAL file must be initialized at some time, so it might as well be
done at the start of a write transaction.
(I guess a write transaction that does not actually write anything does
not happen often enough to be worth optimizing for.)


Regards,
Clemens
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users