SQLite Forum

autovacuum in sqlite VS autovacuum in PG
Login
(I'm ignoring BLOBs and other weird things here to give a simple answer.)

Updating any part of a row can require that the row be rewritten to file.  Depending on whether the row takes up more or less space, and on what lengths of free spare are available, the row may or may not be re-written in place.  Because SQLite keeps pending updates in a journal file, not in the main database file, the amount of time that both the old and new versions of a row are in the main database file is very short.  Immediately after that, the space taken up by the old version of the data is marked as free, and may be reused by future updates or freed up by VACUUMing.

Updates can release space just as well as deletes.  Rows can take up less table space, freeing up filespace.  But DELETE FROM frees up space in indexes.  An UPDATE doesn't do that.

Given the questions you ask I will mention that there's a trade-off here.  You can write your database engine to keep the file size as small as possible, reclaiming the maximum of space at all times and releasing filespace as soon as possible.  But all this processing and input/output can take up time, making operations slow, and can wear out SSD storage by making numerous unnecessary changes.  For instance, in a journaling system updating a single row of data by changing values which appear in two indexes could require 12 writes !  That'a a lot of work.

In some situations it's better to just mark filespace as 'unused, available for reuse' and worry about releasing filespace only when a programmer explicitly does a VACUUM.