Why do SQL databases use a write-ahead log over a command log?

后端 未结 6 515
无人及你
无人及你 2021-01-30 00:26

I read about Voltdb\'s command log. The command log records the transaction invocations instead of each row change as in a write-ahead log. By recording only the invocation, the

6条回答
  •  终归单人心
    2021-01-30 00:42

    Few terminologies before I start explaining:

    Logging schemes: The database uses logging schemes such as Shadow paging, Write Ahead Log (WAL), to implement concurrency, isolation, and durability (how is a different topic).

    In order to understand why WAL is better, let's see an issue with shadow paging. In shadow paging, the database uses a master version and a shadow version of the database so that if the table size is 1 billion and the buffer pool manager does not have enough memory to hold all the tuple (records) in the memory the dirty pages are not written to the master version until the transaction(s) are not committed.

    Once all the transactions are committed, the flag is switched and the shadow version becomes the master version. In the diagram above there are Page 3 and Page 5 that are old and can be garbage collected.

    1. The issue with this approach is a large number of fragmented tuples left behind which is randomly located, this is slower as compared to if the dirty pages are sequentially accessed, and this is what Write Ahead Log does.

    2. The other advantage of using WAL is the runtime performance (as you are not doing random IO to flush out the pages) but slower recovery time. Whereas, with shadow paging, the recovery performance is faster (which is required occasionally).

提交回复
热议问题